News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Problem with arguments to PROC in UASM64 for target Win64

Started by DebugBSD, October 04, 2020, 05:34:11 AM

Previous topic - Next topic

DebugBSD

Hi, good afternoon!

I've a weird problem which I can't understand. It's possible that I'm wrong and some of you can undertake some light on this. The thing is, I have this code:

; ML64 template file
; Compile: uasm64.exe -nologo -win64 -Zd -Zi -c testUasm.asm
; Link: link /nologo /debug /subsystem:console /entry:main testUasm.obj user32.lib kernel32.lib

EXIT_SUCCESS = 0
EXIT_FAILURE = -1

TestFunction PROTO dwArg1:DWORD,dwArg2:DWORD,dwArg3:DWORD,dwArg4:DWORD
ExitProcess PROTO dwExitCode:DWORD

_const SEGMENT

_const ENDS

_data SEGMENT

_data ENDS

_data? SEGMENT

_data? ENDS

_text SEGMENT

main proc
sub rsp, 8 ; for stack alignment to 16 bytes.
sub rsp, 32 ; for shadow space
sub rsp, 32 ; for local variables

mov rcx, 10
mov rdx, 11
mov r8, 12
mov r9, 13
invoke TestFunction, 1, 2, 3, 4

mov rcx, EXIT_SUCCESS
call ExitProcess
ret
main endp

TestFunction PROC USES rax rbx rcx rdx rsi rdi, dwArg1:DWORD,dwArg2:DWORD,dwArg3:DWORD,dwArg4:DWORD

lea rcx, dwArg1
lea rdx, dwArg2
lea r8, dwArg3
lea r9, dwArg4

ret
TestFunction ENDP

_text ENDS

END

; vim options: ts=2


And my problem is the next:

When I try to see the values passed as arguments to the TestFunction (I mean, dwArg1, dwArg2, ...), their values are always 0. I know that for Win64, all values are passed in rcx, rdx, r8 and r9 registers for the first four arguments and the rest on the stack, but I thought that UASM64 was aware of this and the developers did something to pass those arguments into the variables instead of registers. So my question is? I'm wrong about using arguments to procedures instead of using registers ? or maybe is a bug in UASM64? I don't know. I've read the documentation but I cannot find any place related to this so, that's why I ask here, because I don't know if it's an issue or I'm wrong and should pass values into the registers and the stack instead of using arguments to procedures.

I'm using UASM64 v2.50

Thanks in advance!
Guille
Happy Hacking!

rsala

Hi,

Add the following line at the begining of your source code:

OPTION WIN64:1

If you also want the variables to be 16-byte aligned, then:

OPTION WIN64:5

Regards.
EC coder

DebugBSD

Quote from: rsala on October 04, 2020, 07:46:16 PM
Hi,

Add the following line at the begining of your source code:

OPTION WIN64:1

If you also want the variables to be 16-byte aligned, then:

OPTION WIN64:5

Regards.

Thank you so much!

I've seen the documentation and have found those options in the document. At first I didn't pay much attention  because I was looking for some proc options instead of Win64 extensions so I'm sorry for that. I'll pay more attention next time.

Have a nice day!
Guille
Happy Hacking!


johnsa

Hi,

Thanks RSala for helping out!

Feel free to message me directly if you have any other questions, I've been very quiet this year on UASM due to other commitments but will soon be putting some more time into it.

John