【发布时间】:2014-04-25 13:23:58
【问题描述】:
在使用 malloc(也是 C 库的)分配内存后,我试图调用 C 库的“gets”函数,但我不断收到分段错误,我不知道为什么!! 我知道堆栈有问题,但我不知道是什么! 这是代码:
section .rodata
LC0:
DB "The number is: %i", 10, 0 ; string
LC1:
DB "Allocation failed!!!", 10, 0 ; string
section .data
section .bss
stack_size:
RESB 20
section .text
align 16
global main
extern printf
extern malloc
extern gets
link_size EQU 5
_start:
jmp main
main:
mov dword edi, link_size
push edi
call malloc
mov dword [stack_size], eax
test eax,eax
jz fail_exit
add esp,4
push ecx
call gets
pop ecx
ret
fail_exit:
push LC1
call printf
add esp,4
【问题讨论】: