【问题标题】:The binary of opcode in assembly汇编中操作码的二进制
【发布时间】:2014-08-08 09:26:00
【问题描述】:

我有以下代码(生成列表文件后,为英特尔 80x86 编写):

 1                                    global _start
 2                                  
 3                                  section .data
 4 00000000 03000000                x:  dd  3
 5                                  
 6                                  ;section .text
 7                                  
 8                                  _start:
 9 00000004 8B0D[00000000]              mov ecx, [x]
10 0000000A 000D[16000000]          r:  add byte [l+6], cl
11 00000010 C605[00000000]30        l:  mov byte [x], 48
12 00000017 51                          push    ecx
13 00000018 B804000000                  mov eax, 4      ; For "Write" system call
14 0000001D BB01000000                  mov ebx, 1      ; to standard output
15 00000022 B9[00000000]                mov ecx, x      ; "buffer"
16 00000027 BA01000000                  mov edx, 1      ; byte counter
17 0000002C CD80                        int 0x80
18 0000002E 59                          pop ecx
19 0000002F E2D9                        loop    r, ecx
20                                      
21 00000031 BB00000000                  mov ebx, 0
22 00000036 B801000000                  mov eax, 1      ; For "exit" system call
23 0000003B CD80                        int 0x80

我现在专注于第 19 行,但我并不完全理解它。 我知道操作码“循环”的二进制是 E2。

但是D9字节从哪里来?是怎么计算出来的?

【问题讨论】:

  • 不会指定寄存器吗?为什么不改变值,看看反汇编是如何变化的?
  • 将 D9 视为二进制补码表示...

标签: assembly x86 opcode


【解决方案1】:

19 0000002F E2D9 loop r, ecx

第二个操作码(D9)从何而来?

第二个操作码(在这种情况下为0xD9)是二进制补码中的相对目标地址 - 因为你是向后跳转,所以在这种情况下它是负数:

  0x00000031   (The address following the loop instruction)
+ 0xFFFFFFD9   (Signed-extended representation of 0xD9 - actually a negative number, -39 decimal)
============
  0x0000000A   (The address of the r label)

注意,目标地址是根据循环指令之后的地址计算的。

另见http://www.mathemainzel.info/files/x86asmref.html#loop

【讨论】:

  • 0xFFFFFFD9 带符号扩展。
猜你喜欢
  • 2020-11-29
  • 2017-05-18
  • 2012-06-04
  • 2015-12-09
  • 2015-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-24
相关资源
最近更新 更多