0

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.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53

1 Answers1

0

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.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
  • Thank you! This whole machine language thing is new to me. Quite interesting, but I'd stick to high-level languages :(. – pythonboi Apr 24 '21 at 17:18
  • Oh, one more question, what does PCoffset do? From what I understand, you add that value to the source register and that's your answer (LEA?). Not sure if that's correct but also, what's the difference between offsetN and PCoffsetN? – pythonboi Apr 24 '21 at 17:21
  • Sorry, I don't know what you're referring to re: offsetN. My text describes PCOffset9, and PCOffset11, both are ways to locate the storage that the program wants to refer to. This probably merits another question post here. – Erik Eidt Apr 24 '21 at 17:28