flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
GuBar 05 Aug 2020, 22:55
I am new to assembly (only started a few months ago) and I have grasped some concepts already. Now I am trying to learn how to use the x87 instruction set. I can't move a 64 bit immediate to a 64 bit memory location.
Code: section '.data' data readable writeable float dq 1 section '.text' code readable executable _start: ; a 32 bit program that uses 64 bit floating point values push ebp mov ebp, esp mov [float], 0x4029000000000000 ;this value is 1.25 and is where i get the error "illegal instruction" fld qword [float] mov [float], 0x3FFA000000000000 ;this value is 1.625 and i suspect that i will get an "illegal instruction" error here too fld qword [float] faddp ;adds 1.25 and 1.625 together fst [float] ;stores the sum in [float] push [float] ;i also get an error here where i can't push a 64 bit value push fmt call [printf] ;i am expecting to get 0x4007000000000000 which is 2.875 add esp, 8 ret 0
|
|||||||||||
![]() |
|
GuBar 06 Aug 2020, 05:57
Thanks for your reply, the snippet of code you have shown me has solved my issue, but I have another issue. As I can't push a quad word onto the stack, I have pushed the lower and upper 32 bit values into the stack for the printf function. I remember learning that you pass arguments via the stack in reverse order(for printf you push the value you want to print then the format). so in order to print it correctly I do this,
Code: push dword [float+4] push dword [float+0] push fmt call [printf] ;this is suppose to print out 0x0x4007000000000000 but instead prints out 0x0000000000000000 but when I do this Code: push dword [float+0] push dword [float+4] ;this would print out the hex value in reverse push fmt call [printf] ;oddly it prints out as 0x0000000040070000 as it should but the other program only printed out 0's The only potential solution I could come up with is to call printf two times passing the upper bits with the format that includes "0x" at the beginning then the lower bits with a special format that excludes "0x". I am curious why it will print the correct hex number when I pass [float+0] and then [float+4] but not in the reverse order.
|
||||||||||
![]() |
|
revolution 06 Aug 2020, 06:09
Show your fmt string.
|
|||
![]() |
|
GuBar 06 Aug 2020, 07:44
this was the format string
Code: fmt: db "0x%16x", 0 ;this is the format to print in 16 hex hex digits |
|||
![]() |
|
revolution 06 Aug 2020, 07:50
You need to show two hex values because the 32-bit printf can only show 32-bit values AFAIAA.
Try this: Code: fmt: db "0x%08x%08x", 0 |
|||
![]() |
|
GuBar 06 Aug 2020, 08:11
Thanks for the assistance, I will try this in a few hours as I have to sleep.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.