Home > other >  Assign a decimal value to a REAL8 local variable using MASM
Assign a decimal value to a REAL8 local variable using MASM

Time:07-25

I'm trying to assign a decimal value into a REAL8 local variable. However, the only quirky way I've found is to convert a decimal number to a float

Question

Is there a better way to handle decimal numbers in MASM?
Maybe other assemblers handle floats better?

CodePudding user response:

I'm trying to assign a decimal value into a REAL8 local variable. However, the only quirky way I've found is to convert a decimal number to a IEEE 754 64 bit number.

MOV             RAX,4609434218613702656
MOV             stop,RAX
FLD             QWORD PTR stop

You have hardcoded the decimal number 1.5 in the mov rax instruction. For this you had to convert the number yourself.
You can do easier and forget about conversion while using the REAL8 directive:

        ...
        db      48h, 0B8h       ; REX prefix, MOV RAX opcode
        REAL8   1.5             ; 64-bit immediate
        mov     stop, rax       ; Loading the local variable
        fld     QWORD PTR stop  ; Loading st0
        ...

Alternatively, put the (hardcoded) number anywhere you like in your program and fld it from there:

        ALIGN   8
start   REAL8   1.1
num     REAL8   1.5
        ...
        fld     QWORD PTR num
        ...

or

        ...
        fld     QWORD PTR num
        ...
        ret
        ALIGN   8
num     REAL8   1.5
main    endp
  • Related