【发布时间】: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