1

This is for an easy way to write down fixed points.

Something to this effect:

%define FIXEDP_LITERAL(num) (int) (num * 65536)

That's invalid code, obviously (probably). This macro will be used in instructions as operands and in define directives. Is it possible to cast from a float to an integer in nasm expressions, such that nasm will use the expression as an integer (i.e. so dd FIXEDP_LITERAL(3.5) should place an integer constant, not a floating-point constant).

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
mid
  • 421
  • 5
  • 20
  • So you want to write an integer constant expression involving decimal fractions? Like some way to make `dd 2 * 0.5` equivalent to `dd 1`? I don't know off the top of my head, but haven't checked the NASM manual. – Peter Cordes Mar 29 '20 at 19:47
  • @PeterCordes Correct, this is just to make fixed-point easier for the coder, it's not at all a necessity. I couldn't find this in the manual, would be a shame if this isn't supported. – mid Mar 29 '20 at 21:04
  • You can probably get most of what you want via right-shift or division for fixed-point. Given that floating-point numbers can't exactly represent most decimal fractions (only ones with a power-of-2 denominator) I wouldn't be surprised if there's no support for assemble-time float->int conversion. You don't really want rounding errors to maybe give you `0` instead of `1` if you write `int ( 3 * (1.0/3.0) )` instead of limiting yourself to 0.5, 0.25, 0.125 and so on. – Peter Cordes Mar 29 '20 at 21:17

0 Answers0