I have the following code that prints the number of parameters passed to ./main
. Notice the fmt
in the rodata
section. I've included the new line
, just like in C, but instead of printing the new line, it prints:
Number of parameters: 1
My code is:
;main.asm
GLOBAL main
EXTERN printf
section .rodata:
fmt db "Number of parameters: %d
", 0
section .text:
main:
push ebp
mov ebp, esp ;stackframe
push dword[ebp+8] ;prepara los parametros para printf
push fmt
call printf
add esp, 2*4
mov eax, 0 ;return value
leave ;desarmado del stack frame
ret
I know that including a 10 before the 0 and after the "Number..." in fmt
will print it, but I want printf
to do it. I assemble the code with NASM and then link it via GCC to create my executable.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…