My first x64 assembly code cooked by hand

This is my first hand made x64 assembly code.

extrn MessageBoxA:proc

    msg DB "Hello World!", 0

main PROC
    sub rsp, 28h
    xor rcx, rcx
    lea rdx, msg
    lea r8, msg
    xor r9, r9
    call MessageBoxA
main ENDP

To compile this code, in command prompt run

ml64 helloworld.asm /link /subsystem:windows /defaultlib:user32.lib /entry:main

The major different between x86 and x64 calling conventions. The first six integer or pointer arguments are passed in registers RDI, RSI, RDX, RCX, R8, and R9, while XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6 and XMM7 are used for floating point arguments. additional arguments are passed on the stack and the return value is stored in RAX.

Leave a Reply
