Comp Architecture - LC-3

145 views Asked by At

I was wondering what the PC (Program Counter) has to do with the condition codes? I noticed that when the PC was introduced, it had ", condition codes" right after. I know what the condition codes do but not sure how they're related.

1

There are 1 answers

3
Erik Eidt On

Each register, including the general registers, the program counter, and the 3 1-bit condition codes are independent pieces of state within the processor.

What relates the various pieces of state are specific instructions in the instruction set.  The only way to access processor state is by executing instructions, so the instruction set alone literally defines what we can do with respect to processor state.

There are some instructions that set the condition codes (like ADD), and there are others that test the condition codes (like BRn/z/p).  The ones that test the condition codes are conditional branch instructions.

Conditional branch instructions can advance the program counter forwards to skip code or move the program counter backwards to repeat code already executed.

These instructions are fundamental for the assembly/machine code implementation of structured statements in languages like C, such as if-then, if-then-else, while, for-loop.

So, the fundamental relationship between condition codes and the program counter is that they are used together through the conditional branch instructions, by the program to control its execution flow.