RedPanda-CPP/platform/windows/templates/Hello_NASM/main.asm

20 lines
588 B
NASM
Raw Normal View History

2023-02-09 21:43:49 +08:00
extern printf
extern exit
global main
section .data ; Data section, initialized variables
msg: db "Hello world", 0 ; C string needs 0
fmt: db "%s", 10, 0 ; The printf format, "\n",'0'
section .text:
main:
; the x64 calling convention requires you to allocate 32 bytes of shadow space before each call
; https://stackoverflow.com/questions/30190132/what-is-the-shadow-space-in-x64-assembly/
2023-02-12 13:24:51 +08:00
sub rsp, 32 ; allocate shadow space
mov rcx, fmt ; first parameter
mov rdx, msg ; secodng parameter
2023-02-09 21:43:49 +08:00
call printf
add rsp,32 ; remove shadow space
2023-02-09 21:43:49 +08:00
mov eax,0 ; exit code
ret