Search code examples
assemblyx86cpucpu-registerseip

What happens when the eip register reaches its maximum value?


The eip register is 32 bits, and it increments for every new instruction. So what happens when it reaches the maximum value for a 32 bit number: 4294967295.


Solution

  • Typically, you don't let it happen. %eip doesn't increment unconditionally; it's affected by flow control instructions (like jmp, call, bcc, etc).

    In practice, this behavior is unpredictable. On some CPUs, overflowing %eip causes a fault. On some others, it silently wraps around to zero.

    These discrepancies led to a famous exploit of the (original) Xbox boot ROM, as development kits used AMD CPUs (which faulted on wraparound), whereas production hardware used Intel CPUs (which did not). For details, see Hacking The Xbox: An Introduction to Reverse Engineering, around page 140.