如何生成纯二进制文件就像NASM -f与GNU GAS汇编斌? [英] How to generate plain binaries like nasm -f bin with the GNU GAS assembler?
问题描述
我有一般有一些结构NASM文件:
[BITS 64]
[ORG 0x0000000000200000]开始:
... RET
我将它们组装,像这样:
NASM -f斌abc.asm
我想写一些使用燃气代替。两个问题:
-
我应该在天然气使用什么指示?我已经找到了.ORG指令,但GAS似乎并不有一个'.bits'指令。
-
我要传递给
GCC什么
或为
来生成一个简单的二进制文件?即什么-f斌
选项确实与NASM。
我应该在天然气使用什么指示?我已经找到了.ORG指令,但GAS似乎并不有一个'.bits'指令。
块引用>汇编器默认为64 - 位对我来说,你可以使用
- 32
或- 64
要选择在命令行上。看看手册中的作为以了解如何改变$ C里面的结构如果$ C需要(如code16
可用于生成实模式code的Boot Loader)。您最有可能不想使用
.ORG
指令来指定code的位置,但可能希望使用链接脚本或指定的文本和数据段在命令行上加载。 (组织0x0000000000200000
的结果2+ MB二进制文件)。
我要传递给GCC或生成纯二进制文件?即什么-f bin选项确实与NASM。
块引用>$猫test.S
.section伪的.text
.globl _start
_开始:
XOR%RAX,RAX%
MOV测试,RAX%
RET测试:.quad 0x1234567812345678
作为$ -o --64 test.o test.S
$ LD -Ttext 200000 --oformat二进制-o TEST.bin,烧写test.o
$ objdump的-D -b二进制-m i386的:X86-64 TEST.bin,烧写
TEST.bin,烧写:文件格式的二进制
段.data的拆卸:&0000000000000000 LT;。资料>:
0:48 31 C0 XOR%RAX,RAX%
3:48 8B 04 25 0C 00 20 MOV 0x20000c,RAX%
答:00
乙:C3 retq结果
C:78 56 JS 0x64
E:34 12 XOR $ 0×12,%人
10:78 56 JS为0x68
12:34 12 XOR $ 0×12,%人
I have some NASM files that generally have the structure:
[BITS 64] [ORG 0x0000000000200000] start: ... ret
I'm assembling them like so:
nasm -f bin abc.asm
I'd like to write some of these using GAS instead. Two questions:
What directives should I use in GAS? I've found the '.org' directive but GAS doesn't seem to have a '.bits' directive.
What should I pass to
gcc
oras
to generate a plain binary file? I.e. what the-f bin
option does with NASM.解决方案What directives should I use in GAS? I've found the '.org' directive but GAS doesn't seem to have a '.bits' directive.
The assembler defaults to 64--bit for me, you can use
--32
or--64
to chose on the command line. Have a look at the manual for as to see how you can change the architecture inside the code if needed (e.g..code16
can be used to generate real mode code for a boot loader).You most likely don't want to use the
.org
directive to specify where the code is located, but will probably want to use a link script or specify where the text and data segments are loaded on the command line. (org 0x0000000000200000
results in a 2+ MB binary file).What should I pass to gcc or as to generate a plain binary file? I.e. what the -f bin option does with NASM.
$ cat test.S .section .text .globl _start _start: xor %rax, %rax mov test, %rax ret test: .quad 0x1234567812345678 $ as --64 -o test.o test.S $ ld -Ttext 200000 --oformat binary -o test.bin test.o
$ objdump -D -b binary -m i386:x86-64 test.bin test.bin: file format binary Disassembly of section .data:0000000000000000 <.data>: 0: 48 31 c0 xor %rax,%rax 3: 48 8b 04 25 0c 00 20 mov 0x20000c,%rax a: 00 b: c3 retq
c: 78 56 js 0x64 e: 34 12 xor $0x12,%al 10: 78 56 js 0x68 12: 34 12 xor $0x12,%al这篇关于如何生成纯二进制文件就像NASM -f与GNU GAS汇编斌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!