0

I would like convey my gratitude in advance. I'd like to ask about the machine code regarding a program in emu8086 as below:

ORG 100H

MOV AX,01H      
MOV CX,03H  

loop1:  NOP

        LOOP loop1  
        DEC AX
        JZ loop2    
        ADD AX,AX   

loop2:  DEC AX      
        HLT

By referring to the program above, I can see that the equivalent machine code for JZ loop2 is 74 02 as seen in the emu8086, in which JZ is 74, loop2 is 02.

I looked up on my appendix reference which shows me the number of bytes of each different mnemonics, it seemed that ADD corresponds to 2 bytes. I've tried a few different mnemonics to replace the code "ADD AX,AX" and the machine code for loop2 changes as well. For example, if I change "ADD AX,AX" to "DEC [500H]", the machine code for loop2 changes to 04, and my reference shows DEC [memory] corresponds to 4 bytes.

What could be the explanation on how does loop2 be equivalent to 02? And what does the 02 indicates? I'm confused.

Please help me on this. I'd love any helpful explanation or information. Any effort and replies are greatly appreciated.

rkhb
  • 14,159
  • 7
  • 32
  • 60
OneBaseNotch
  • 183
  • 1
  • 2
  • 7
  • The second byte of your `JZ` instruction is a `rel8` byte, i.e. _"a relative address in the range from 128 bytes before the end of the instruction to 127 bytes after the end of the instruction"_. – Michael Dec 08 '14 at 11:28
  • @Michael what do you mean by that? – OneBaseNotch Dec 08 '14 at 14:16
  • You asked what the `02` indicates. It indicates the distance between the end up the jump instruction and the jump target. The term used [in Intel's manual](http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html) is `rel8`, and the quote I included in my previous comment is the way it's defined in the manual. – Michael Dec 08 '14 at 14:21
  • @Michael I see. So that's what it is, this helped me clear up the confusion. Thank you. – OneBaseNotch Dec 08 '14 at 17:23

0 Answers0