【问题标题】:Cannot access memory at address 0x ffffdfc4无法访问地址 0x ffffdfc4 处的内存
【发布时间】:2015-07-16 11:57:25
【问题描述】:

我有汇编语言程序,但是显示错误

“程序收到信号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.

为什么以及如何解决它?

【问题讨论】:

  • Power eax 不用于其他任何用途,因此您可以将“movl %ebx, -4(%ebp)”替换为“movl %ebx, %eax”并删除所有其他包含 - 4(%ebp)。
  • 您的问题可能是,您编译为 64 而不是 32 位。如果是这种情况,您需要提供正确的编译器选项。
  • @MikkelChristiansen 如何提供正确的编译器选项
  • @shengfu zou --32 为 GNU 做这件事。

标签: linux assembly


【解决方案1】:

我的问题是我使用64编译32位程序。我添加了一些编译器

解决它的选项。如下所示:

as -32 power.s -o power.o

ld -m elf_i386 power.o -o power

./电源

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 2013-02-18
    • 2013-10-30
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多