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:
|
2023-02-10 19:28:18 +08:00
|
|
|
; 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
|
2023-02-14 23:42:11 +08:00
|
|
|
lea rcx, [rel fmt] ; first parameter
|
|
|
|
lea rdx, [rel msg] ; secodng parameter
|
2023-02-09 21:43:49 +08:00
|
|
|
call printf
|
|
|
|
|
2023-02-10 19:28:18 +08:00
|
|
|
add rsp,32 ; remove shadow space
|
2023-02-09 21:43:49 +08:00
|
|
|
mov eax,0 ; exit code
|
2023-02-10 19:28:18 +08:00
|
|
|
ret
|