【问题标题】:What style assembly is this (intel, att...etc?) and how can I produce it?这是什么风格的程序集(intel、att...等?),我怎样才能生产它?
【发布时间】:2012-04-09 07:11:42
【问题描述】:

我正在尝试生成这样的汇编代码(以便它与 nasm 一起使用)

;hello.asm
[SECTION .text]

global _start


_start:

    jmp short ender

    starter:

    xor eax, eax    ;clean up the registers
    xor ebx, ebx
    xor edx, edx
    xor ecx, ecx

    mov al, 4       ;syscall write
    mov bl, 1       ;stdout is 1
    pop ecx         ;get the address of the string from the stack
    mov dl, 5       ;length of the string
    int 0x80

    xor eax, eax
    mov al, 1       ;exit the shellcode
    xor ebx,ebx
    int 0x80

    ender:
    call starter    ;put the address of the string on the stack
    db 'hello'

首先,这是什么汇编风格,其次,我如何使用类似于 gcc -S code.c -o code.S -masm=intel 的命令从 C 文件中生成它

【问题讨论】:

  • -masm=intel 正是产生这种风格的原因(英特尔语法,而不是默认的 AT&T 语法)。但这仅适用于实际说明。像[SECTION] 这样的东西是特定于 NASM 的,而 GCC 总是会生成特定于 GAS 的东西。
  • 那么,当我使用 (-masm=intel) 运行上述命令,然后我尝试运行命令 nasm -f elf code.S 时,怎么会出现一大堆错误?
  • 因为 nasm 不是气体。指令是错误的。
  • @HansPassant 你能解释一下你的意思吗?
  • @Nosrettap - 风格的一部分是它看起来像 手写 程序集。这可能是问题的一部分吗?

标签: c++ c gcc compiler-construction


【解决方案1】:

这是英特尔风格。

你在问题​​中写的命令行有什么问题?

【讨论】:

  • 只是如果我使用那个命令,然后我尝试使用命令nasm -f elf code.S 我得到一大堆错误
猜你喜欢
  • 2012-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-26
  • 2020-09-16
  • 1970-01-01
相关资源
最近更新 更多