The primary difference between the Program Counter (PC) and the Memory Address Register (MAR) is their function in the instruction cycle of a CPU. The PC holds the address of the next instruction to be executed, while the MAR holds the address of the memory location currently being accessed (either for reading or writing).
Detailed Breakdown
To better understand the difference, consider how these registers are used within the Fetch-Decode-Execute cycle:
-
Fetch:
- The MAR is loaded with the address held in the PC.
- The address in the MAR is then sent to memory.
- Memory retrieves the instruction stored at that address.
- The instruction is sent to the Memory Data Register (MDR).
- The PC is incremented to point to the next instruction in memory (unless a jump or branch instruction is encountered).
-
Decode: The instruction in the MDR is decoded by the control unit.
-
Execute: If data needs to be read from or written to memory during execution, the MAR is again used to hold the address of the memory location involved.
Table summarizing the differences
Feature | Program Counter (PC) | Memory Address Register (MAR) |
---|---|---|
Purpose | Holds the address of the next instruction to execute. | Holds the address of the memory location being accessed. |
Timing | Updated before fetching an instruction. | Updated during the fetch or execute phase. |
Usage | Primarily used to control the flow of execution. | Used to access specific memory locations. |
Incrementing | Typically incremented after each instruction fetch. | Not automatically incremented; loaded with specific addresses. |
Relation to MAR | Its value is often loaded into the MAR. | Receives its value from the PC or other sources. |
In short, the PC is like a pointer to the upcoming steps in a program, while the MAR is like a currently selected address on a map used to find a specific house (memory location).