mkdir ~/cs355/hw5 cp /home/cs355001/Handouts/hw5/* ~/cs355/hw5 |
You will copy these files:
hw5.h - This file contains the machine instructions that you must write for assignment 5 Many other support files that construct a working CPU !!! DO NOT touch these files !!! |
Each machine instruction is 32 bits long
|
![]() |
Memory Location | machine instruction |
0 | Copy R8 to R0 (i.e.: mov r0, r8) |
1 | Copy MDR to R1 |
2 | Add R6 and R8 and store result in R2 |
3 | Add MDR and R9 and store result in R3 |
4 | Left shift R9 and store result in R4 |
5 | Right shift (R8+R9) and store result in R0 |
6 | Left shift (NOT(MDR)) and store the result in R1 (NOT ≡ invert the bits) |
7 | Compute R8/2 and store the result in register R2 |
8 | Compute 2*(R6 + R9) and store the result in R3 |
9 | Compute 4*R9 and store the result in R4 |
I will describe how to write the machine instruction in the next section.
|
|
Writing binary numbers in C:
|
|
Here is the initial content in the hw5.h program file that you must put the mirco-instructions:
/* ------------------------------------------------------------------
HW5 TODO:
Write the binary number pattern for the 10 machine instructions
specified in the homework assignmnet write up below.
Each machine instruction is 32 bits or 4 bytes
You can write each byte of the machine instruction in this format:
0bXXXXXXXX where X is 0 or 1
A number starting with 0b is treated as a binary number by the compiler
To help you obtain the bit pattern, I have align the bit along
with the meaning of each bit using the acronym below.
(You need to read the acronym vertically !!!)
You ONLY need to change the bits under:
AMux, ALU, Shif, EnC, CCCC, BBBB, AAAA
You DO NOT need to change the bits under:
Cond, MBR, MAR, RD, WR, branch address
Meaning of the bits: (to help you set the bits of the machine instr)
Read the acronym vertically !!!
|||||||| ||||
VVVVVVVV VVVV
ACCAASSM MRWE
MooLLhhB ADRn
unnUUiiR R C branch
xdd ff CCCC BBBBAAAA address
------------------------------------------------------------------- */
/* instr. 0: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
/* instr. 1: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
/* instr. 2: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
/* instr. 3: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
/* instr. 4: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
/* instr. 5: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
/* instr. 6: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
/* instr. 7: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
/* instr. 8: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
/* instr. 9: */ 0b00000000, 0b00000000, 0b00000000, 0b00000000,
|
Notice:
|
cd ~/cs355/hw5 // execute this command ONCE only in window bash ./run-hw5 |
You will see the following circuit:
![]() |
To check if the instructions that you have written is correct (or not):
|
|
|
/home/cs355001/demo/datapath/cs355-demo-dp2 |
You can turn off the lines by pressing the F2 key.
Press the ' (= the quote key next to the ENTER key at the right of the keyboard) once to de-activate the RESET function.
To test a machine instruction:
|
/home/cs355001/turnin hw5.h hw5 |
(A 4th extension request will be automatically denied --- personal emergencies and illiness with documentation will receive a "free" extension)
/home/cs355001/req-ext hw5 |