0
我想通过调用打印字符串字符char,通过调用汇编代码中的printf,但打印第一个字符后,我得到分段错误,我不明白为什么发生,请有人可以帮助请??为什么在x86中调用printf时会出现分段错误?
section .rodata
lc:
DB "%c", 10, 0
section .text
align 16
global my_func
extern printf
my_func:
push ebp
mov ebp, esp ; Entry code - set up ebp and esp
pusha ; Save registers
mov ecx, dword [ebp+8] ; Get argument (pointer to string)
incr:
cmp byte [ecx], 0
jz end
movzx eax, byte [ecx]
push eax
push lc
call printf
add esp, 8
inc ecx
jmp incr
end:
popa ; Restore registers
mov esp, ebp ; Function exit code
pop ebp
ret
'eax','ecx'和'edx'是_caller-saved_寄存器。所以你不应该依赖任何这些寄存器的值在一个函数调用中被保留。 – Michael 2015-04-04 15:55:23