Datapath Simulator - MARIE-js/MARIE.js GitHub Wiki

Datapath Simulator

Datapath diagram

The datapath simulator is incorporated into MARIE.js, and can be accessed via the menu:

View -> Datapath

The purpose of this visualisation is to give an understanding of how instructions and micro-instructions relate to sequence of signals.

Register bank

The MARIE simulator register bank is a set of 7 registers used for different purposes. For example, the PC register holds the memory address that points to the next instruction.

Here is a list of the registers used in the MARIE simulator.

Name Number Abbreviation # of bits stored
Memory Address Register 1 MAR 12
Program Counter 2 PC 12
Memory Buffer Register 3 MBR 16
Accumulator 4 AC 16
Input 5 IN 16
Output 6 OUT 16
Instruction Register 7 IR 16

Memory

The memory stores data in a sequence of locations. At this point of time, nothing much is shown in the memory, apart from whether data is being read from or written to memory.

It is important to know that the data in each memory cell has no meaning in itself. For example, a memory cell may represent as data 0000 (which is very common as usually most of memory cells are empty), but can also be seen as a JnS instruction with memory address 000, as the highest hexadecimal value is the same as the opcode for the JnS instruction.

Read control bus

The read control bus tells which register (or memory) to output data into the data bus.

In the table below, observe the link between the number of the register, and which wires have been activated.

Abbreviation Register Number (binary) Activated Wires
M[MAR] N/A* Mr
MAR 001 P0
PC 010 P1
MBR 011 P1 P0
AC 100 P2
IN 101 P2 P0
OUT 110 P2 P1
IR 111 P2 P1 P0

* The register number can be seen as 000, which means that we do not want to access any register. This is the reason why we have a separate memory read wire so that we can tell the memory exactly when we want to fetch the contents of one memory cell.

Write control bus

The write control bus tells which register (or memory) to read from the data bus and override its value.

Abbreviation Register Number (binary) Activated Wires
M[MAR] N/A* Mw
MAR 001 P3
PC 010 P4
MBR 011 P4 P3
AC 100 P5
IN 101 P5 P3
OUT 110 P5 P4
IR 111 P5 P4 P3

* Like what is said previously in the read control bus section, we do not want to write to any register, so the register number can be seen as 000. A separate memory write wire is activated instead when we need to write to memory.

ALU opcode signals

There are three wires to tell the ALU what kind of operation it needs to perform. Here are the following operations with their opcodes.

Operation Opcode Active Wires RTL
Subtraction 001 A0 AC ← AC - MBR
Addition 010 A1 AC ← AC + MBR
Clear 011 A1 A0 AC ← 0
Increment PC 100 A2 PC ← PC + 1
Increment PC if AC is negative 101 A2 A0 AC < 0? If so then PC ← PC + 1
Increment PC if AC is zero 110 A2 A1 AC = 0? If so then PC ← PC + 1
Increment PC if AC is positive 111 A2 A1 A0 AC > 0? If so then PC ← PC + 1

Data bus

The data bus is 16 bits long, and is used for transferring data (which may hold memory addresses) between registers and/or the memory. It is connected to all registers as well as the memory.

Address bus

The address bus is 12-bits long, and is connected to both the MAR register and the memory. Whenever memory is being accessed (whether it is being read from or written to memory), the memory uses this address to reference the memory cell and performs its intended task (either the contents of the memory cell is outputted to the data bus, or the memory cell is overwritten by the value specified on the data bus).

Decode bus

The "decode bus" is 4-bits long, and is connected to both the IR register and the control unit. Only the highest 4 bits of the IR register is connected to the decode bus. This is used as input into the control unit for decoding which instruction it is so that it can execute the right sequence of micro-operations.

The control unit, and putting it all together

The control unit handles both the register bank, the memory, and the ALU. It does this by generating a sequence of signals, depending on what instruction it has decoded. All instructions begin with the fetch cycle, which the control unit fetches the next instruction from memory, and increments the program counter. Once the instruction is decoded, it executes the instruction by performing the corresponding sequence of RTL operations. Each RTL operation has its own set of signals that needs to be generated.

The active 'LED' in the time sequence signal labelled Tn where n is an unsigned integer, shows how many RTL operations have been performed before the current one within the current instruction. These sequential signals are reset once the control unit has finished executing the current instruction and is ready to execute the next instruction.

The first three (T2 T1 T0) time sequence signals are dedicated to the fetch part of the fetch-decode-execute cycle. The rest of the time sequence depends on what instruction the control unit has decoded from the IR.

Limitations

Although the MARIE datapath gives us a representation of what a CPU looks like, it has some limitations.

ALU and PC

The program counter is not attached to the ALU, which it should be. However, this requires the use of a multiplexer if we want to use the same ALU, which only has two inputs. Trying to add a multiplexer would make the datapath needlessly complicated.

An alternative is to have a separate adder to increment the PC (that is hidden behind the PC). However, the way the datapath is illustrated implies that we are using the same ALU to increment the PC. So in this case, just pretend that there is another wire attached between the ALU and the separate adder, and the ALU outputs a high voltage to that wire whenever it needs to increment the PC.

Another alternative is to transfer the memory address in the PC register to MBR register, increment the MBR using the ALU, then move it back to the PC register. This increases the number of micro-operations from 1 to 3, which is more computationally expensive considering that the PC register only needs to be incremented once.

Input wires into the ALU

Although the wires appear as control signals, they are in fact data buses with 16-bits in each input. However, representing them as 16-bit data buses would be too wide to fit in the datapath visualisation.