【问题标题】:How do i start to learn asm (gas)?我如何开始学习 asm(gas)?
【发布时间】:2013-02-15 19:11:20
【问题描述】:

我找到了“hello world”并写了它。 纳米你好.s

这段代码

.data
msg:
.string  "Hello, world!\n"
len = . - msg
.text
global _start
_start:
    movl    $len,%edx
    movl    $msg,%ecx
    movl    $1,%ebx
    movl    $4,%eax
    int     $0x80
    movl    $0,%ebx
    movl    $1,%eax
    int     $0x80

我已经完成了as -o hello.o hello.s 我报错了

hello.s:6: Error: no such instruction: global _start

delete global _start.

我已经完成了

ld -s -o hello.o hello*

error 

ld: hello: No such file: No such file or directory

我错在哪里了?

p/s debian, amd64.

【问题讨论】:

  • 很难说出你在问什么。当您收到有关“global _start”的错误时,您确实运行了汇编程序。您应该查看汇编程序的手册,看看该行有什么问题。也许它不应该有空格或者全局需要一个 "。"在前面。
  • 也使用gcc 编译器,并查看其生成的汇编代码,例如gcc -Wall -fverbose-asm -O -S file.c 然后看看file.s

标签: linux assembly x86-64 gnu-assembler


【解决方案1】:

试试.globl _start.global _start

您可以尝试不带下划线的start,以防您在入口点遇到问题。

最后,如果您要制作 64 位可执行文件,您可能需要使用不同的系统调用接口,不是int 0x80,而是syscall。更多关于 here.

【讨论】:

  • Furthermore... ld -o hello hello.o -o 开关指定输出文件名,hello.o 是 ld 正在处理的文件。要从 64 位 ld 获取 32 位代码,-m elf_i386。旧的int 0x80 系统调用将在 64 位代码中工作,但它是不正确的。 push reg32 在 64 位代码中不起作用!
猜你喜欢
  • 1970-01-01
  • 2015-01-07
  • 1970-01-01
  • 2022-07-29
  • 2010-09-20
  • 2018-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多