我正在阅读这本书《从头开始编程》,乔纳森·巴特利特。在这个第一次显示函数调用约定的程序上,我在像书中那样输入后运行它时遇到了分段错误。该函数只从堆栈中取出 2 个数字,并在 %eax 中返回第一个数字的第二个数字幂。
这是有问题的程序:
.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:
cmpl $1, %ecx
je end_power
movl -4(%ebp), %eax
imull %ebx, %eax
movl …Run Code Online (Sandbox Code Playgroud)