Electronic – MAR vs Stack Pointer, Whats the difference

computer-architecture

So I was watching some videos on a guy "Building his own 8-bit computer", and the Memory Address Register (MAR) was attached to the SRAM. The MAR took the next Program Counter value and then looked in the SRAM for the next instruction and put it on the Instruction register. (Sidenote: Why doesn't the Program Counter just go straight into a decoder instead of the MAR which is basically another register?)

Anyways, I was looking at the ATTiny85's datasheet and noticed that the "Stack Pointer" was linked to the SRAM in the block diagram (I only understand some of the basics here so apologies if this is a really stupid question). The Program counter in this case was linked directly to the SRAM and the stack pointer pointed at the SRAM as well.

Im curious exactly how this works? Im just learning Computer Architecture so some of this stuff is out of bounds in what i've learned…but Im very interested in understand how a CPU works at the base level.

Maybe im confusing SRAM and program flash in this case though. In that case then where is the MAR?

Block Diagram

Best Answer

The Mememory Address Register and the Memory Data Register are thing that can be found in most CPU implementations. But they are (generally) not part of the programmers view of the CPU: they are not needed to decribe what the CPU does at the (external) instruction level. (But they are often visible on the micro-instruction level).

Hence you might find a MAR in a picture that describes the CPU implementation, but you will generally not see a MAR on a picture that is intended to describe the CPU for a programmer. Unfortunately, it is not always clear what the intended purpose of such a picture is.

In most (simple) cases there are multiple sources (PC, SP, other registers, immediate address from the instruction, result of a caculation) for a memory address that must be read, and there is only one address bus from the CPU to the memory. Hence there must be some way to select one of these sources. In most cases this is done by the source putting the address on an internal bus, and the MAR latching (remembering) this address. Next the memory is accessed, which takes considereable time compared to CPU-internal operations. Because the address is latched, the internal bus is free to do other usefull things (like maybe incrementing the PC).