我有汇编语言程序,但它显示错误
“程序收到信号SIGSEGV,Segentation fault”
为什么?程序如下:
.code32
.section .data
.section .text
.globl _start
_start:
pushl $3
pushl $2
call power
addl $8, %esp
pushl %eax
pushl $2
pushl $5
call power
addl $8, %esp
popl %ebx
addl %eax, %ebx
movl $1, %eax
int $0x80
.type power,@function
power:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl 8(%ebp), %ebx
movl 12(%ebp), %ecx
movl %ebx, -4(%ebp)
power_loop_start:
cmpl $1, %ecx
je power_loop_end
movl -4(%ebp), %eax
imull %ebx, %eax
movl %eax, -4(%ebp)
decl %ecx
jmp power_loop_start
power_loop_end:
movl -4(%ebp), %eax
movl %ebp, %esp
popl %ebp
ret
编译运行程序后,它显示分段错误(核心转储),gdb说:
Program received signal SIGSEGV,Segregation fault.
为什么以及如何修复它?
答案 0 :(得分:0)
我的问题是我使用64来编译32位程序。我添加了一些编译器
解决它的选项。如下:
as -32 power.s -o power.o
ld -m elf_i386 power.o -o power
./功率