Question

So i found out that when the program executes the EIP pointer is set to the first instruction in the code segment, the processor does an execution loop:

  1. Points the EIP to the first instruction
  2. Adds the byte length of the instruction to EIP
  3. Executes the instruction that was read in step 1
  4. Back to 1

My question is, what happens in the step 2?

Please reply thank you

Était-ce utile?

La solution

If you have instructions like this:

0x1000 INSTR_1
0x1004 INSTR_2
0x1007 INSTR_3 /* instructions can have different size */

and the EIP contains 0x1000, you need to update the EIP to make it point to the second instruction (0x1004), so it can execute it in the next iteration. If you don't do this, you will always execute the first instruction.

Because instructions can have different size, you can't just add the constant to it (you can do that if all instructions have the same size, like in RISCs), but you need to add lenght of the instruction you've just read. So, after the first, you will add 4, to make it point to the second one, and after the second instruction, you will add 3 to EIP and it will point to the third instruction.

Autres conseils

EIP gets the address of next instruction.

"2. Adds the byte length of the instruction to EIP"

Increments the EIP to point to next instruction, it is incremented by the no. of bytes taken up by the current instruction

EIP move to the next instruction.

Points the EIP to the first instruction  

EIP-->     1.instruction 1 with 2 bytes 
           2.instruction 1 with 5 bytes
           3.instruction 1 with 3 bytes 



Adds the byte length of the instruction to EIP(move 2 bytes ahead)  

           1.instruction 1 with 2 bytes        
EIP-->     2.instruction 1 with 5 bytes
           3.instruction 1 with 3 bytes 

Adds the byte length of the instruction to EIP(move 5 bytes ahead)

           1.instruction 1 with 2 bytes        
           2.instruction 1 with 5 bytes
EIP-->     3.instruction 1 with 3 bytes   
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top