本文介绍了调用GAS equ'd符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是一个小的程序NASM:
[BITS 64]
[ORG 0x0000000000200000] b_print_newline EQU 0x0000000000100040开始:
电话b_print_newline RET
组装起来:
$ NASM -f斌PR-NL-a.asm -o pr-nl-a.app
拆解:
$ objdump的-D -b二进制-m i386的:X86-64 pr-nl-a.app
pr-nl-a.app:文件格式的二进制
段.data拆卸:0000000000000000<。数据计算值:
0:E8 3B 00 F0 FF callq 0xfffffffffff00040
5:C3 retq
下面是一个GAS版本:
.SET b_print_newline,0x0000000000100040 。文本 。全球_start_开始: 电话b_print_newline RET
汇编并链接:
$为-o PR-NL-B.O PR-NL-b.s
$ LD -Ttext 200000 --oformat二进制-o pr-nl-b.app PR-NL-B.O
拆解:
$ objdump的-D -b二进制-m i386的:X86-64 pr-nl-b.app
pr-nl-b.app:文件格式的二进制
段.data拆卸:0000000000000000<。数据计算值:
0:FF 14 25 40 00 10 00 callq * 0x100040
7:C3 retq
正如你所看到的,反汇编code略有不同。在code为呼叫
在NASM:
0:E8 3B 00 F0 FF callq 0xfffffffffff00040
VS气:
0:FF 14 25 40 00 10 00 callq * 0x100040
有关如何正确实施GAS版本有什么建议?
下面是该程序在FASM:
b_print_newline EQU 0x0000000000100040 use64
组织0x0000000000200000启动:来电b_print_newline
RET
它做正确的事:
$ objdump的-D -b二进制-m i386的:X86-64 pr-nl-c.apppr-nl-c.app:文件格式的二进制
段.data拆卸:0000000000000000<。数据计算值:
0:E8 3B 00 F0 FF callq 0xfffffffffff00040
5:C3 retq
解决方案
添加.ORG 0x0000000000200000到燃气文件。
Here's a small NASM program:
[BITS 64]
[ORG 0x0000000000200000]
b_print_newline equ 0x0000000000100040
start:
call b_print_newline
ret
Assemble it:
$ nasm -f bin pr-nl-a.asm -o pr-nl-a.app
Disassemble it:
$ objdump -D -b binary -m i386:x86-64 pr-nl-a.app
pr-nl-a.app: file format binary
Disassembly of section .data:
0000000000000000 <.data>:
0: e8 3b 00 f0 ff callq 0xfffffffffff00040
5: c3 retq
Here's a GAS version:
.set b_print_newline , 0x0000000000100040
.text
.global _start
_start:
call b_print_newline
ret
Assemble and link it:
$ as -o pr-nl-b.o pr-nl-b.s
$ ld -Ttext 200000 --oformat binary -o pr-nl-b.app pr-nl-b.o
Disassemble it:
$ objdump -D -b binary -m i386:x86-64 pr-nl-b.app
pr-nl-b.app: file format binary
Disassembly of section .data:
0000000000000000 <.data>:
0: ff 14 25 40 00 10 00 callq *0x100040
7: c3 retq
As you can see, the disassembled code differs slightly. The code for call
in NASM:
0: e8 3b 00 f0 ff callq 0xfffffffffff00040
vs GAS:
0: ff 14 25 40 00 10 00 callq *0x100040
Any suggestions for how to implement the GAS version properly?
Here's the program in FASM:
b_print_newline equ 0x0000000000100040
use64
org 0x0000000000200000
start: call b_print_newline
ret
It does the right thing:
$ objdump -D -b binary -m i386:x86-64 pr-nl-c.app
pr-nl-c.app: file format binary
Disassembly of section .data:
0000000000000000 <.data>:
0: e8 3b 00 f0 ff callq 0xfffffffffff00040
5: c3 retq
解决方案
Add ".org 0x0000000000200000" to the GAS file.
这篇关于调用GAS equ'd符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!