Playcpu
Playcpu
As you go through the program, refer to the reference sheet at the end of this document to see where to go next when
completing each step.
MEMORY
Below is a program stored in memory, beginning at memory address 0. At each memory address, one byte (2
digits) of data is stored. Memory addresses are the numbers on the top row.
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22
30 F2 00 00 00 01 30 F1 00 00 00 05 30 F0 00 00 00 00 62 11 71 00 00 00 22 60 10 61 21 70 00 00 00 12 00
REGISTERS
Our computer has 8 registers – 8 memory slots in the CPU – to hold onto the numbers we are currently working with.
Like main memory, each register has an address, shown in the left row. The columns to the right of these addresses
represent clock cycles that the computer goes through.
address Unless a new value is written to a register, the register keeps its previous value: copy these values from the previous clock cycle.
0 0 0 0
1 0 5 5
2 1 1 1
3 0 0 0
4 0 0 0
5 0 0 0
6 0 0 0
7 0 0 0
Note: We have no register F. If you try to access register F, return a 0; if you're trying to write to register F, just move on. F
is used as a flag to indicate we don't need to read or write to a register in a given instruction.
FETCH AND DECODE
Fetch and Decode will ask for the instruction stored in memory, starting at the address PC.
The value of PC will come from Execute. Parse the instruction as follows:
• the 1st hex digit is the instruction code (iCd)
• the 2nd hex digit is the instruction function (iFn)
If iCd = 3 or iCd = 6:
● the 3rd hex digit is register A (rA) and the 4th hex digit is register B (rB)
If iCd = 3 or iCd = 7:
● the next 8 hex digits (or 4 bytes) are called valC
And then calculate the following four values (all values are in hexadecimal):
iCd valP srcA srcB dstE
0 PC 0xF 0xF 0xF
3 PC + 6 0xF 0xF equal to rB
6 PC + 2 equal to rA equal to rB equal to rB
7 PC + 5 0xF 0xF 0xF
PC 0 6 C
30F2 30F1 30F0
Instruction 0000 0000 0000
0001 0005 0000
iCd 3 3 3
iFn 0 0 0
rA F F F
rB 2 1 0
valC 1 5 0
valP 6 C 12
srcA F F F
srcB F F F
dstE 2 1 0
EXECUTE
Execute works with a lot of the rest of the computer to make sure every instruction runs properly.
1. Start off by getting the following things: iCd, iFn, valC, valP, srcA, srcB, and dstE from Fetch/Decode.
2. scrA is the register address where the value you will use for valA is stored. Get this value from the register and do the
same with
srcB to get valB.
3. Send iCd, iFn, valA, valB and valC over to ALU/DECIDE and wait for two values back: valE and bch.
4. The value of nextPC will be valP, with one exception: when iCd = 7 AND bch = 1. In this case, we will move to
somewhere else in our program, and nextPC will be valC. Pass nextPC to the PC cell in the next empty column of
Fetch/Decode.
5. Lastly, tell Memory to write the value valE to the register with address dstE.
STEP 3: Your job is also to figure out if the conditions are right for branching. Execute will then decide if we are actually going to
branch.
Different instructions: