notes

Personal notes
git clone git://git.laack.co/notes.git
Log | Files | Refs

InstructionPointer.md (929B)


      1 # Instruction Pointer (IP)
      2 
      3 **Source:** Performance Aware Programming
      4 
      5 **Definition:** The instruction pointer is a register that points to the next instruction byte to decode.
      6 
      7 ## 8086
      8 
      9 In 8086, IP would work like this:
     10 
     11 1. IP == 0
     12 2. read 3 bytes (mov, reg r/m, dist)
     13     - The number of bytes can vary on 8086
     14 3. IP += 3
     15     - Or however many bytes the instruction is
     16 4. Execute mov instruction
     17     - Or whatever instruction was decoded
     18 5. go to step 2, repeat until instructions cease
     19 
     20 ## Jumps
     21 
     22 Step 4 above may be a jumping instruction, like JNZ, which can set the IP directly. In such cases, we set the IP relative to our current position. Additionally, since the jump instruction has been decoded by the time it is being executed, and IP has been incremented by then, our relative reference must account for that too.
     23 
     24 ```asm
     25 cmp bx, ax
     26 jne -4
     27 ```
     28 
     29 This will either loop forever if bx != ax or it will just pass through.