Assembly: printf not printing new line -
i have following code prints number of parameters passed ./main. notice fmt in rodata section. i've included new line \n, in c, instead of printing new line, prints:
number of parameters: 1 \n
my code is:
;main.asm global main extern printf  section .rodata: fmt db "number of parameters: %d \n", 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 including 10 before 0 , after "number..." in fmt print it, want printf it. assemble code nasm , link via gcc create executable. 
when use quotes or double quotes around string in nasm, doesn't accept c style escape sequences. on linux can encode \n ascii 10 this:
fmt db "number of parameters: %d", 10, 0  there alternative. nasm supports backquotes (backticks) allow nasm process characters between them c style escape sequences. should work well:
fmt db `number of parameters: %d \n`, 0 please note: not single quotes, backticks. described in nasm documentation:
3.4.2 character strings
a character string consists of 8 characters enclosed in either single quotes ('...'), double quotes ("...") or backquotes (
...). single or double quotes equivalent nasm (except of course surrounding constant single quotes allows double quotes appear within , vice versa); contents of represented verbatim. strings enclosed in backquotes support c-style -escapes special characters.
Comments
Post a Comment