(Cpre 381) Computer Organization and Assembly-Level Programming, Fall 2018 Project A Report
(Cpre 381) Computer Organization and Assembly-Level Programming, Fall 2018 Project A Report
Refer to the highlighted language in the Project A instruction for the context of the following questions.
a. [Part 1.a] Provide a description of how each of the control values in the architecture (i.e., the outputs of
the main control unit) is used.
For each output control signal, explain how it is used (i.e., what does it do?)
o o_reg_dest
This is used to decide which bits to put in the write register which is based off the type of
instruction, bits 16-20 for I type and 11-15 for R type
o o_jump
Determines whether to use a new address passed in or use the branch decision to branch or go
to the next instruction. 0 means branch is chosen, 1 means jump.
o o_branch
Determines whether to continue to the next address or branch to the specified address based on
the zero comparison(equal or not equal)
o o_mem_read
Enables reading from the data memory.
o o_mem_to_reg
Chooses whether there was a load or ALU instruction, decides which result to put back into the
register file.
o o_ALU_op
Gives operation code to the ALU control to determine what instruction to carry out.
o o_mem_write
enables the writing to the data memory.
o o_ALU_src
Chooses to compute from a register or immediate value. 0 – reg, 1 - immediate
o o_reg_write
Enables writing to registers.
1|Page
For the 6 MIPS instructions to support, ADD, ADDI, LW, SW, BEQ and J, complete the following
table.
ADD ADDI LW SW BEQ J
o_reg_dest 1 0 0 0 0 0
o_jump 0 0 0 0 0 1
o_branch 0 0 0 0 1 0
o_mem_to_reg 0 0 1 0 0 0
o_ALU_op 000000 001000 100011 101011 000100 000010
o_mem_write 0 0 0 1 0 0
o_ALU_src 0 1 1 1 0 0
o_reg_write 1 1 1 0 0 0
(continuing from the previous question) For each of the 6 MIPS instruction, explain why you set the
values as you described in the table above.
o ADD
Add is an r-type instruction that doesn’t jump/branch, and writes to the register. The opcode is
used for ALU_op. Since it computes from the register ALU_src is set to 0.
o ADDI
Addi is an i-type instruction that doesn’t jump/branch, and writes to the register. The opcode is
used for ALU_op. Since it computes from immediate ALU_src is set to 1.
o LW
Lw is an immediate type instruction that doesn’t jump/branch and writes to the register.. It loads
a value from memory to the register. Its opcode is used in ALU_op. ALU_src is 1 since it adds
an immediate value to the address passed in.
o SW
SW is n immediate type instruction that doesn’t jump/branch. It doesn’t write to the register,
rather writes to memory. ALU_src is 1 since it adds an immediate to the address. Its opcode is
used in ALU_op.
o BEQ
Beq is an I type instruction that branches and doesn’t jump. It doesn’t write anything back to
the registers.
o J
J is a j type instruction that jumps, it doesn’t do anything else. ALU_op is set to its opcode.
b. [Part 1.a] How is the zero flag from the ALU used?
The zero flag is a 1 only if the result from the ALU is 0. This is used for comparisons such as beq,
bne.
c. [Part 2] Simulate your processor in ModelSim and run the provided program in imem.mif with the data
in dmem.mif.
The [projectA > ASM Files > test_with_data_seg.asm ] file has the assembly code with data
specified which is equivalent to the given imem/dmem.mif. Before simulating the final design, just
by studying the code, please explain
o What the code does
This code sums an array from memory.
o Which values will be written on DMEM at the locations of the first 11 words staring from the
address 0.
10, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55.
o Which values will be written on the following registers: $8 (=$t0), $9 (=$t1), $10 (=$t2), and
$16 (=$s0).
$8 gets decremented to 0 in the loop. $9 gets the address of the 11th word in memory(44). $10 will
have the last element from the array(10), 10. $16 is the sum or 55.
2|Page
Provide a screenshot for each of the 6 MIPS instructions to support showing the correct
functionality and explain how the instruction is working in accordance with the screenshot
o ADDI
Attach a screenshot & explain
3|Page
o ADD
Attach a screenshot & explain
MemToReg is 0, which tells us that we’re writing to the register straight from the ALU.
RegWrite is 1, enabling writing to the register file. RegWrite[4..0] is 16, meaning that
we’re adding into register $t16. RsData and RtData are both 0, because we are adding
from register 0. ALU_src is 0 instead of 1 because we are using a register value instead
of an immediate.
4|Page
o LW
Attach a screenshot & explain
This is the first load word instruction which gets the size of the array. MemToReg is 1
meaning that the register file is receiving from the data memory. ALU_src is 1 meaning
it is taking in the immediate value to add to the memory address. ReadData is 0xA which
is correct because we are reading in n from memory which is the value 10.
5|Page
o SW
Attach a screenshot & explain
6|Page
o BEQ
Attach a screenshot & explain
Branch is set to 1 here because we are branching. ALU_src is set to 0 which means we
are adding from 2 registers which are viewed on RsData and RtData, this sum is in
ALU_out which is A(10). Because ALU_out is not 0, the zeroBit is set to 0, which when
anded with the Branch bit makes 0 meaning the new address chosen by the mux is PC+4,
not the BranchAddress.
7|Page
o J
Attach a screenshot & explain
Jump is set to 1 because we are jumping. The new instruction address chosen here is the
jump address(24) not the PC+4 address(10).
8|Page
Provide screenshots showing the final values of the dmem and registers
o DMEM (for the first 11 words starting from address 0)
9|Page
o REGISTERS
Final values for $8, $9, $10, and $16 are 0, 44, 10, and 55 respectively.
10 | P a g e