A program counter turns control into data.
A pc register identifies the next instruction, so a controller can advance by transforming the complete machine state.
How can one transition procedure represent several machine instructions?
- Use a pc value to select one instruction
- Advance control and data registers together
- Recognize a halt state in the controller
The state holds pc, a, b, temp, and cycles. Each cond branch implements exactly one instruction and writes the pc of the instruction that should follow.
Instruction 0 tests b and either enters the remainder cycle or jumps to halt at pc 5. The other instructions move values through temp before returning control to the test.
- Output
- —
- Value
- —
- Diagnostic
- —
The first program halts with (5 2 0 0 2). pc 5 marks halt, a holds 2, and two remainder cycles completed.
Read the recurring pc sequence 0, 1, 2, 3, 4. The final test changes pc directly from 0 to the halt value 5.
Change the program and compare the result.
Add a register that counts every instruction rather than only completed remainder cycles.
Show hint
Every cond branch must increase the instruction count exactly once.