RAX, RBX, RCX, RDX: The primary data registers. RAX is typically used for return values.
Stack Alignment: The stack must be aligned to a 16-byte boundary before any call instruction. A Basic "Hello World" Example Introduction to 64 Bit Windows Assembly Program...
Register Usage: The first four integer or pointer arguments are passed in RCX, RDX, R8, and R9 (in that order). RAX, RBX, RCX, RDX: The primary data registers
In this snippet, we observe the application of the calling convention: RCX , RDX , R8 , and R9 are loaded with arguments before the WriteFile call, and the stack is adjusted to accommodate the shadow space. Conclusion A Basic "Hello World" Example Register Usage: The
; External Windows functions extern GetStdHandle extern WriteFile extern ExitProcess section .data msg db "Hello, 64-bit World!", 0 msg_len equ $ - msg section .bss bytes_written resq 1 section .text global main main: sub rsp, 40 ; Reserve shadow space + align stack ; Get handle to standard output mov rcx, -11 ; STD_OUTPUT_HANDLE call GetStdHandle mov r12, rax ; Save handle in r12 ; Write to the console mov rcx, r12 ; Arg 1: Handle lea rdx, [rel msg] ; Arg 2: Buffer address mov r8, msg_len ; Arg 3: Length lea r9, [rel bytes_written] ; Arg 4: Pointer to written count mov qword [rsp + 32], 0 ; Arg 5: Overlapped (on stack) call WriteFile ; Exit the program xor rcx, rcx ; Return code 0 call ExitProcess Use code with caution. Copied to clipboard
64-bit Windows Assembly is a powerful tool that offers unparalleled control over a system. While the syntax and rules—such as stack alignment and register-based argument passing—can be rigid, they provide a structured environment for writing highly efficient code. By mastering these fundamentals, you gain a deeper appreciation for how the Windows operating system executes every instruction under the hood.
Windows follows a specific set of rules for passing data to functions, known as the Microsoft x64 calling convention. Understanding this is critical for interacting with the Windows API (like printing to a console or creating a window).