什么是运codeS括号在NASM生成的列表文件的含义是什么? [英] What is the meaning of parentheses in opcodes in a NASM generated listing file?

查看:192
本文介绍了什么是运codeS括号在NASM生成的列表文件的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在那个被NASM生成一个列表文件看,我看到有三种运codeS的:


  1. 如果没有括号。

  2. 使用圆括号。

  3. 附方括号。

他们是什么意思?当每个人使用?

这是证明上述所有的列表文件的例子:

  1 .text段
 2 EXTERN的printf
 3 EXTERN与fgets
 4 00000000 313233 STR3:DB123
 5个主要的:
 6 00000003 68 [00000000]推STR1
 7 00000008 68 [09000000]推STR2
 8 0000000D 68 [00000000]推STR3
 9 00000012 E8(00000000)调用FUNC1
10 00000017 E8(04000000)调用FUNC2
11 0000001C E80B000000通话FUNC3
12 00000021 E8(00000000)调用printf
13 00000026 E8(00000000)调用与fgets
14 0000002B C3 RET
15
16 0000002C 90 FUNC3:NOP
17 0000002D C3 RET
18
19
20节.text1
21 00000000 90 FUNC1:NOP
22 00000001 90 NOP
23 00000002 90 NOP
24 00000003 C3 RET
25
26 00000004 90 FUNC2:NOP
27 00000005 90 NOP
28 00000006 90 NOP
29 00000007 C3 RET
三十
31
32段.data
33
34 00000000 313233343536373839 STR1:DB123456789
35 00000009 313233343536373839 STR2:DB123456789


解决方案

他们表示将搬迁将在链接时使用。

[NNNNNNNN] 显示了绝对的搬迁(当连接器进行搬迁,一些部分的基地址将被添加到偏移量)。例如一旦二进制完全挂钩,在推str2的这些字节指令将变成包含。数据 + ×09

(NNNNNNNN)表示PC相对重定位(用于通话及分支,其中最终值必须相对于下一个指令的地址)。例如在通话FUNC2字节指令将与地址的 FUNC2 最后地址之间的差异,并进行更新下面的指令(呼叫FUNC3 )。

有对呼叫FUNC3 指令本身,因为需要在这种情况下没有搬迁没有括号 - 在呼叫指令需要一个相对的地址,但 FUNC3 是同一节内,因此相对地址是已知的(下面的指令在的.text + 0×21 FUNC3 的.text + 0x2c ,因此相对地址是 0XB 不管最终地址的的.text )。

When looking at a listing file that was generated by NASM, I see that there are three kinds of opcodes:

  1. Without parentheses.
  2. With round parentheses.
  3. With square parentheses.

What they mean? when each of them is used?

This is an example of a listing file that demonstrate all of the above:

 1                                  section .text
 2                                      extern printf
 3                                      extern fgets
 4 00000000 313233                  str3:   db "123"
 5                                  main:
 6 00000003 68[00000000]                push    str1
 7 00000008 68[09000000]                push    str2
 8 0000000D 68[00000000]                push    str3
 9 00000012 E8(00000000)                call    func1
10 00000017 E8(04000000)                call    func2
11 0000001C E80B000000                  call    func3
12 00000021 E8(00000000)                call    printf
13 00000026 E8(00000000)                call    fgets
14 0000002B C3                          ret
15                                  
16 0000002C 90                      func3:  nop
17 0000002D C3                          ret
18                                  
19                                  
20                                  section .text1
21 00000000 90                      func1:  nop
22 00000001 90                          nop
23 00000002 90                          nop
24 00000003 C3                          ret
25                                  
26 00000004 90                      func2:  nop
27 00000005 90                          nop
28 00000006 90                          nop
29 00000007 C3                          ret
30                                  
31                                  
32                                  section .data
33                                  
34 00000000 313233343536373839      str1:   db "123456789"
35 00000009 313233343536373839      str2:   db "123456789"

解决方案

They're showing where relocations will be applied at link time.

[nnnnnnnn] shows an absolute relocation (when the linker performs the relocation, the base address of some section will be added to the offset). e.g. once the binary is fully linked, those bytes in the push str2 instruction will be changed to contain the base address of .data + 0x09.

(nnnnnnnn) shows a PC-relative relocation (used for calls and branches, where the final value must be relative to the address of the next instruction). e.g. the bytes in the call func2 instruction will be updated with the difference between the final address of func2, and the address of the following instruction (call func3).

There are no brackets for the call func3 instruction itself because no relocation is needed in that case - the call instruction needs a relative address, but func3 is within the same section, so the relative address is already known (the following instruction is at .text + 0x21, and func3 is at .text + 0x2c, so the relative address is 0xb regardless of the final address of .text).

这篇关于什么是运codeS括号在NASM生成的列表文件的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆