简体   繁体   中英

Comp Architecture - LC-3

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM