hnefatl
hnefatl

Reputation: 6037

Program Counter Overflow?

Is it possible for the Program Counter (PC) in a processor to overflow, and if so, what happens? That is, if it can hold 1 byte, what happens when it is increased beyond 255?

Upvotes: 3

Views: 1609

Answers (1)

Brendan
Brendan

Reputation: 37214

For some (most?) CPUs it is possible; and if the program counter overflows it wraps around.

For example, if PC is 16-bit and there's a 1 byte instruction at 0xFFFF, then the CPU may happily continue executing the next instruction at 0x0000.

Of course it depends on a lot of different things (e.g. which CPU, which operating mode, how it's configured by software/OS, etc). There's also corner-cases; like whether you can have a (2 bytes or larger) instruction that's split such that the first part is at the highest address (accessed before PC wraps) and the remainder is at the lowest address (accessed after PC wraps).

Upvotes: 5

Related Questions