Assembly binary operation code

I have the following code (after creating a listing file written for Intel 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 

I am now focusing on line 19, and I do not quite understand this. I understand that the binary code of the Code loop is E2.

But where does the D9 byte come from? how was it calculated?

+6
source share
1 answer

19 0000002F E2D9 loop r, ecx

Where does the second operation code come from (D9)?

The second operation code ( 0xD9 in this case) is the relative destination address in the two additions - since you are jumping backwards, in this case it is negative:

  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) 

Note that the destination address is calculated based on the address after the loop statement.

See also http://www.mathemainzel.info/files/x86asmref.html#loop

+9
source

Source: https://habr.com/ru/post/970988/


All Articles