【问题标题】:Why can't I use more than 3 variables in my assembly code?为什么我不能在我的汇编代码中使用超过 3 个变量?
【发布时间】:2012-02-26 08:50:15
【问题描述】:

我从汇编开始,特别是 GNU 汇编,所以我在玩寄存器、变量和值之类的东西,但后来我注意到我不能使用超过 3 个变量。首先我写了这个:

    .section .data
    chars:  .ascii "something"
    stuff:  .long 0
    more:   .long 1

    .section .text
    .globl _start

    _start:
        movl stuff, %eax
        movl %eax, stuff

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

并在终端上尝试过并成功了,但后来我尝试了这个

.section .data
chars:  .ascii "something"
stuff:  .long 0
more:   .long 1
evenmore:   .long 3

.section .text
.globl _start

_start:
    movl stuff, %eax
    movl %eax, stuff

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

这没有用。我收到分段错误错误。 有什么问题?我该怎么办?

【问题讨论】:

  • @Dor 分段错误的完整错误消息是“分段错误”。
  • 试过通过调试器运行它吗?
  • @Necrolis 是的,先生,已经尝试使用 gdb 并没有得到太多信息:程序收到信号 SIGSEGV,分段错误。 _start () at mov.s:12 12 movl %eax, stuff
  • 这是在 Linux 或 FreeBSD 上还是其他什么东西上?
  • 你确定上面是你编译的代码吗?你是怎么编译的?能否展示一下两个版本的反汇编?

标签: assembly x86 gnu-assembler


【解决方案1】:

编译的时候出了问题,把'_start'改成'main',然后用gcc,就这么简单。

在此之前,我尝试使用 gcc,使用 -nostartfiles 选项,也尝试使用 as 和 ld,应该有一种方法可以使用它,但是使用 gcc 并将 '_start' 更改为 'main' 是最简单的并且我能做到的最快。

【讨论】:

    猜你喜欢
    • 2022-06-28
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    • 2019-09-14
    相关资源
    最近更新 更多