Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

My ASM is giving me gyp

Name: Anonymous 2012-05-26 16:58

Trying to get this to work. Just a "my first" program to help me make the transition mentally to x64, but it crashes if printf is invoked - why? Commenting out printf makes it not crash, and the stack pointer is the same at the start of the program as it is before the ret.

Yes, Windows.

include 'win64a.inc'
format PE64 Console 4.0
entry main

section '.text' code data readable executable

main:
    mov rdx, rsp
    mov rcx, text
    call [printf]
    xor rax,rax
    ret

text db "It's 5 AM. Do you know where your stack pointer is? (%016x)", 10, 0

align 16
data import
    library msvc,'msvcrt.dll'
    import msvc,printf,'printf'
end data

Name: Anonymous 2012-05-27 10:04

In the Microsoft x64 calling convention, it's the caller's responsibility to allocate 32 bytes of "shadow space" on the stack right before calling the function (regardless of the actual number of parameters used), and to pop the stack after the call. The shadow space is used to spill RCX, RDX, R8, and R9.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List