2013-08-21 91 views
0

我在下面的代码中遇到了段错误。汇编代码中的段错误

.section .data 

myarray: 
     .int 10,20,30,40,50,60 

format: 
     .ascii "%d\n" 

.section .text 

.globl _start 
_start: 

movl $2, %ebx 
movl myarray(,%ebx,4) , %ecx 

pushl %ecx 
pushl $format 
addl $8,%esp 
call printf 

movl $1,%eax 
movl $0,%ebx 
int $0x80 

而在gdb下运行,我越来越

Program received signal SIGSEGV, Segmentation fault. 
strchrnul() at ../sysdeps/i386/strchrnul.S:68 
68 ../sysdeps/i386/strchrnul.S: No such file or directory. 
    in ../sysdeps/i386/strchrnul.S 

请点我要去的地方错了。

回答

1

addl $8,%esp从堆栈中移除东西。它删除了它上面的两个参数。该指令应该在printf之后,而不是之前。

可能有其他错误;我没有彻底检查。此外,您还没有在您的问题中指定您正在使用的工具或平台。不同的平台可能使用不同的接口进行调用,中断和系统例程。

+0

完美!我正在学esp今天需要的堆栈操作,所以我错过了它的位置。感谢您的努力和时间。我正在使用linux和gnu汇编器进行实践。 –