我刚开始学习汇编,刚开始时我被困住了 - 我试图调用一个简单的函数 - 实际上它大部分都是从一本书中复制而来,我不断收到分段错误。也许更有经验的人可能会指出什么是错,此代码:在汇编器中调用函数(AT&T,IA-32)
.code32
SYSEXIT = 1
.data
.text
.globl _start
_start:
push $28 #just some random argument
push $33
call myfunc
mov $SYSEXIT, %eax
#exit code is stored in ebx after calling function
int $0x80
.type myfunc, @function
myfunc:
push %ebp #save old base pointer on a stack
movl %esp, %ebp
movl 8(%ebp), %ebx #first argument to ebx
movl 12(%ebp), %ecx #second argument to ecx
addl %ecx, %ebx #add arguments together - store them in ebx
movl %ebp, %esp
pop %ebp
ret
您可能需要'pushl'作为您的直接参数。否则,汇编器可能会生成一个指令来推送一个字(16位)。 – Michael 2013-03-22 08:52:11
已经尝试'pushl'和其他变化 - 仍然获得seg故障 – 2013-03-22 08:56:34