1 year ago
#363346
szdytom
Runtime error while using %arg marco in NASM
extern printf
section .text
global add_one
add_one:
%push func_addone
%stacksize flat64
%arg a:qword
inc qword [a]
mov rax, [a]
ret
%pop
global main
main:
mov rcx, 1
sub rsp, 28h
call add_one
add rsp, 28h
mov rcx, format
mov rdx, rax
sub rsp, 28h
call printf
add rsp, 28h
xor rax, rax
ret
section .data
format:
db "number: %d", 10, 0
My Env: cpu x86_64, windows 10, NASM 2.11.02, linking with MINGW64 GCC 4.8.1.
I am a beginer to NASM. I wants to implament a program calculate 1 add 1 and output.
I tried to call add_one
function following windows's x64 calling convention by moving the first argument into rax and reserving 32 bytes of shadow storage (I actually reserved 40 bytes to align rsp to 16). This calling method works when I tried to call functions like puts
. But this program abort with segmentation fault after about 1.5 seconds without outputing anything.
I'm not a native English speaker, so sorry to my grammer mistakes.
segmentation-fault
runtime-error
nasm
0 Answers
Your Answer