Marie
- Marie Architecture.
- 4K 16-bit words of main memory.
- Word-addressable, not byte-addressable.
- 12-bit memory addresses.
- Each instruction is 16 bits.
- Data registers are 16 bits: AC, MBR, IR
- Registers which hold addresses are 12: MAR, PC.
- I/O registers are 8, except in the simulator where they are 16.
- The ALU is 16 bits wide.
- Registers and purposes.
- AC: The accumulator holds computation results and data in use.
- MAR: Holds the address when accessing memory.
- MBR: Holds a value being read from or entered into memory.
- PC: Holds the address of the next instruction.
- IR: Holds a copy of the currently-executing instruction.
- InREG, OutREG: Holds data to be read by, or data written out
by, the CPU.
- Instruction Set Architecture.
Instruction Format:
Opcode 15-12
Address 11-0
The first four bits is the operation code, which tells what the
instruction does.
0000 |
JnS X |
Store the PC in memory at address X, then jump to X+1. |
0001 |
Load X |
Copy the value in memory at location X into AC. |
0010 |
Store X |
Copy the value in the AC to memory at location X. |
0011 |
Add X |
Add the value in memory at address X to the AC. |
0100 |
Subt X |
Subtract the value in memory at address X from the AC. |
0101 |
Input |
Copy the value from the input register to AC. |
0110 |
Output |
Copy the value from AC to the output register. |
0111 |
Halt |
Stop the machine. |
1000 |
Skipcond cond |
Skip the next instruction if the condition is true.
Conditions are 00 for the AC is negative, 01 for zero
or 10 for positive. |
1001 |
Jump X |
The next instruction to execute is the one at
address X in memory |
1010 |
Clear |
Set the AC to zero. |
1011 |
AddI X |
Treat the low 12 bits of the value at address X in memory
as
another address, fetch the value from that address and
add it to AC. |
1100 |
JumpI X |
Treat the low 12 bits of the value at address X in memory
as
another address, which is the location of the next
instruction to execute. |
1101 |
LoadI X |
Treat the low 12 bits of the value at location X in
memory as
another address, fetch the value from that address and
copy it to AC. |
1110 |
StoreI X |
Treat the low 12 bits of the value at address X
in memory as
another address, and copy the contents of the AC there. |
- Seems to me a load immediate would be a better use of op code A:
Copy X to AC.
- The I in the last four instructions stands for indirect.
- They
all specify some address indirectly, by specifying where to find the
address, rather than giving the address itself.
Better: Think of them as using X as a pointer, and
following it.
- The JnS and JumpI can be used for call and return (Example 4.4).
- LoadI, StoreI and JumpI are useful with arrays. The X value is
effectively a pointer (Example 4.1, 4.3.)
- JumpI can also be used with some control constructs,
or to implement function pointers or virtual function calls.
- Marie Data Path.
- Major components are connected via a 16-bit-wide bus.
- During each clock cycle, the bus can transfer one 16-bit quantity from
one specified device to another.
- Some additional connections also exist. These can make additional
transfers during the same cycle as a value is transferred on the bus.
- Each instruction is implemented by a series of computations and
transfers.
- RTL Definitions.
- Describe how the datapath is used to implement
the instructions.
- The X refers to the instruction parm. Really IR[11-0]
- Instructions which can be executed simultaneously are listed on a
a single line.
JnS X
MBR ← PC
MAR ← X
M[MAR] ← MBR
MBR ← X
AC ← 1
AC ← AC + MBR
PC ← AC
Load X
MAR ← X
MBR ← M[MAR]
AC ← MBR
Store X
MAR ← X, MBR ← AC
M[MAR] ← MBR
Add X
MAR ← X
MBR ← M[MAR]
AC ← AC + MBR
Subt X
MAR ← X
MBR ← M[MAR]
AC ← AC - MBR
|
Skipcond
If IR[11-10] = 00 then
If AC < 0 then PC ← PC + 1
else if IR[11-10] = 01 then
If AC = 0 then PC ← PC + 1
else if IR[11-10] = 10 then
If AC > 0 then PC ← PC + 1
AddI X
MAR ← X
MBR ← M[MAR]
MAR ← MBR
MBR ← M[MAR]
AC ← AC + MBR
JumpI X
MAR ← X
MBR ← M[MAR]
PC ← MBR
LoadI X
MAR ← X
MBR ← M[MAR]
MAR ← MBR
MBR ← M[MAR]
AC ← MBR
StoreI X
MAR ← X
MBR ← M[MAR]
MAR ← MBR
MBR ← AC
M[MAR] ← MBR
|
- Marie Logisim Data Path
- Signal Definitions
- The above circuit implements the Marie processor using Logisim.
The datapath is on the first page.
- Make sure the input marked “Controller Select” near the top right
is set to zero. This allows manual control of the datapath through
the various inputs shown on the right side of the circuit.
- I have included a dedicated increment unit for the PC. There is no
indication of it on any of the diagrams, but p. 258 mentions the
assumption that the PC can increment itself. This is also needed to
make sense of much of the RTL and other discussion of the control
unit.
- Note that Fig. 4.15
gives a detail of the connection of the MBR to the bus.
Some difference and problems:
- Ignore the version in the 3rd edition. It's broken.
Use the 4th edition version.
- Fig. 4.15 uses AND gates
to generate select signals from the control signal groups
P5P4P3 and P2P1P0.
The left AND gate generates a store enable that causes the register
to save the bus value on the next clock, and the one on the right
generates a bus enable which places the registers value onto the
bus for some other device to receive.
My implementation uses two decoders, each of which generates eight
selects at once, rather than using two
sets of AND gates for each register.
- The logisim program provides a built-in register object, which I have
used rather than entering 16 individual D flip-flops. These
simulated devices have a pin for store enable to which I connect
the select line.
- Fig. 4.9 shows three inputs to the
AC (Bus, ALU and MBR). Since I'm using a multiplexer to choose which
input to send the register, I have to round up to a power of two. So
I added a source of constant one, thinking it might be useful. So far,
it hasn't been.
- The list in Sec. 4.8.1 on p. 231 says that the input and output
registers are 8 bits. The input and output registers in the Marie
simulator have 16 bits, though they only display the lower byte
when set to ASCII mode. My circuit has 16 bit input and output
registers.
- I've attached a 4x4 LED matrix to the output register.
Each LED corresponds on one bit in the 16-bit output value, and lights
if the bit is a one. It's not
particularly useful, but it can be amusing.
- Fetch-execute cycle.
- Generally.
- Fetch the instruction as indicated by the PC.
- Decode the instruction (figure out what to do next).
- Fetch any required operands from memory.
- Perform the instruction, perhaps saving results to memory.
- Marie specific.
- Copy the PC to the MAR.
- Fetch the instruction at the address given in MAR, and place it
in the IR, while also incrementing the PC.
- Decode the high four bits of the IR to adapt to the particular
instruction, while copying the lower 12 bits into MAR.
- If the particular instruction needs the value located a M[MAR],
fetch it.
- Perform the instruction, including any other required memory
operations.
- The control unit.
- Takes certain input from the datapath.
- Op code and skip code from the IR.
- AC negative and zero signals.
- Generates control signals to move data.
- Marie Control State Diagram
- Approaches.
- Implement the state state diagram using a ROM.
- High-Level Design
- The State register holds the current state.
- The Signal ROM is indexed by the state. That entry
contains all the
the datapath signals for that state, and specifies the next state.
- If there can be only one next state, its number is part of
the entry.
- If there can be multiple next states, look up the correct one
in the Jump ROM.
- See the “Simple ROM Controller.”
- Contents of state ROM
- Contents of jump ROM
- Build from gates.
- Simple approach: Replace ROMs with gate circuits that produce similar signals.
- Text Approach.
- Instead of current state, keep a counter of the instruction
cycle step.
- The decoder.
- Mainly decode the op code to one line for each code.
- Might decode other fields.
- Might just be combined with main control matrix.
- Microcode controller
- Another form of ROM controller.
- Instead of putting signals in the ROM, it contains codes which
which decode to the signals.
- The ROM entries are viewed as instructions forming a
microprogram.
- Instead of a state register, there is a microinstruction counter.
- Each instruction either branches, or the counter is incremented.
- Microinstruction Format
- Microperation Codes
- Partial Microprogram
Note: The two above figures have been modified to have
MBR ← PC for code 01000. This is
needed for the JnS RTL.
- Traps and Interrupts.
- Marie does not implement these, but any serious CPU does.
- Interrupts.
- Interrupts are initiated by an I/O device, which sends a signal to
the CPU. The signal indicates that the device has completed some
operation, is available for use, or has data to be
collected.
- At the top of the instruction cycle, before fetching from M[PC]
check if an interrupt has been raised. If so, fetch the next
instruction from a pre-defined address instead of PC.
This is an asynchronous jump.
- The address may be a single fixed address, one of a list depending
on the device, or stored in a table located at a standard place.
- The code located at this location is the service routine or
interrupt vector. This is part of the operating system.
- The service routine must save the CPU state, service the device, then
restore the state so that the interrupted program sees no change.
- The interrupt is blocked until the service routine acknowledges it.
- Most interrupts may also be temporarily blocked by software (generally
the OS). They should not be blocked for a
long time, as data from the device may be lost.
- Traps
- Also called software interrupts or exceptions.
- Generated by an instruction, not an external device.
- Errors, such as division by zero.
- Deliberate traps to invoke the operating system.
Questions
Chapter questions:
4th, 5th ed: 2, 4, 6, 10, 15, 20, 21, 22, 26, 29,
37, 43, 44, 47, 54
3rd ed:
2, 4, 6, 9, 13, 17, 18, 19, 23, 26,
33, 41, 47
(For 22/19, perhaps do only do some of the instructions.)