【发布时间】:2013-03-22 08:47:43
【问题描述】:
我刚开始学习 Assembler,但我一开始就卡住了 - 我试图调用一个简单的函数 - 实际上它主要是从书中复制的,而且我一直遇到分段错误。也许更有经验的人可以指出这段代码有什么问题:
.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 位)。 -
已经尝试过
pushl和其他变体 - 仍然出现段错误
标签: function assembly x86 call