简体   繁体   中英

Reading intel assembly 8086 listing file

Here is my listing file for a program. However, the question I'm asked is the significance of F0 on line 20. I know the first column represents the address offset and the third column represents the instruction, but how do we figure out what the data means here?

 1 ; 
 2 ; 
 3 ;
 4                                 section .data
 5
 6 00000000 0102030405             number: db 1,2,3,4,5
 7 00000005 00                     sum: db 0
 8
 9
 10                                section .text
 11                                        global _start
 12
 13                                 _start:
 14 00000000 B905000000            keith: mov ecx, 5
 15 00000005 B800000000            ron:   mov eax, 0
 16 0000000A BB[00000000]                 mov ebx, number
 17 0000000F 0203                  again: add al, [ebx]
 18 00000011 81C301000000                 add ebx,1
 19 00000017 81E901000000                 sub ecx,1
 20 0000001D 75F0                         jnz again
 21 0000001F A2[05000000]                 mov [sum], al
 22
 23 00000024 B801000000                   mov eax,1
 24 00000029 BB00000000                   mov ebx,0
 25 0000002E CD80                         int 80h

Opcode 75 is a short jump . A short jump is a relative jump that is less than 128 bytes away forward or backward from the instruction pointer (IP) of the instruction that follows the jump instruction. (NOTE: in the standard CPU fetch-execute cycle, an instruction is fetched, and then the IP is incremented to the next instruction before the fetched instruction is executed.)

 16 0000000A BB[00000000]                 mov ebx, number
 17 0000000F 0203                  again: add al, [ebx]
 18 00000011 81C301000000                 add ebx,1
 19 00000017 81E901000000                 sub ecx,1
 20 0000001D 75F0                         jnz again
 21 0000001F A2[05000000]                 mov [sum], al

In this case, your full opcode is: 75F0 . That's a short jump (if Z flag is 0) a distance from the next IP represented by the signed byte value, F0 . The signed value of F0h , taken as a 2's complement signed byte, is minus 10h and is computed as:

  0000000F ; address of "again:" label
- 0000001F ; address of instruction after "jnz"
----------
        F0 ; difference in addresses

This tells the CPU to jump back -10h byte locations from the following IP in order to get to the again: label.

The fact that the distance to jump was so short, the assembler was able to use the short jump . Otherwise, if it were greater than 128 bytes away, a different jump opcode would be needed ( eg , near jump if it's within the 64kB segment - otherwise a far jump is needed).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM