flat assembler
Message board for the users of flat assembler.

Index > Windows > use64 in 32-bit mode

Author
Thread Post new topic Reply to topic
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
small example

Code:
format PE console
entry start

include '%fasminc%\win32ax.inc'

section '.text' code readable executable
    start:
use64
        mov     eax, 0x12345
        mul     rax             ; rax = rax*rax
        push    rax             ; push qword rax onto stack
use32
        cinvoke printf, "%I64u"
        invoke  ExitProcess, 0
    


I thought the above push rax should push qword rax (2 dwords) onto stack and that the printf would read these correctly, but it prints an incorrect result.

Can someone show me how to do this ?

Also, with 32-bit pe, how can I get value of rax into a memory location?

I've tried

Code:

x     dq ?

use64
mov [x], rax
    

and
Code:
x     dq ?

use64
mov [dword x], rax    ;to show it's a 32-bit address
    

but nothing seems to work

Many thanks
Post 07 Aug 2012, 16:54
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
You can't use 64-bit code while running in 32-bit mode. The situation is even worse than when trying to use 16-bit code, which at least is accessible by NOT using use16 so fasm insert the appropriate override prefixes for the instructions.
Post 07 Aug 2012, 19:31
View user's profile Send private message Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
LocoDelAssembly wrote:
You can't use 64-bit code while running in 32-bit mode.


So is use64 simply to revert to 64-bit after use32 in a 64-bit app?
Post 07 Aug 2012, 19:59
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Actually, use* are meant to be used when some portion of code will be run by the CPU in a mode other than the current one. For instance, if you were writing a DOS app and you switch to 32-bit protected mode, you'd need use32 for the code that will run after the mode switch, otherwise the processor won't interpret the instructions correctly because fasm (or any other assembler for that matter), assembled it assuming the CPU works in 16-bit mode all the time.

Using use32 in a 64-bit app would also be wrong, because again, if the CPU is running in 64-bit mode then instructions like "INC EAX" assembled in a use32 context will be interpreted by the CPU as a REX prefix, among many other problems caused by using incorrect instruction encodings for the mode the processor is running in.
Post 08 Aug 2012, 03:19
View user's profile Send private message Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
Thanks for clearing that up for me loco.
Post 08 Aug 2012, 12:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.