Computer Architecture - 09 - Review For Midterm
Computer Architecture - 09 - Review For Midterm
5
HW1-Assignment 3
• In the following code segment, f, g, h, i, and j are variables. If the five
variables f through j correspond to the five registers $s0 through $s4,
what is the compiled MIPS code for this C if statement?
if (i == j)
f = g + h;
else
f = g – h;
6
HW1-Assignment 3
Sol)
In general, the code will be more efficient if we test for the opposite
condition to branch over the code that performs the subsequent then part
of the if (the label Else is defined below) and so we use the branch if
registers are not equal instruction (bne):
bne $s3,$s4,Else # go to Else if i ≠ j
add $s0,$s1,$s2 # f = g + h (skipped if i ≠ j)
j Exit # go to Exit
Else: sub $s0,$s1,$s2 # f = g – h (skipped if i = j)
Exit:
7
HW1-Assignment 3 참고자료
if (i==j && i==k)
f = g + h;
else
f = g - h;
or $s0,$a3,$t6
9
HW1-Assignment 5
• Following figure shows the datapath of the MIPS processor. Please write the
following five control signals (RegWrite, ALUSrc, PCSrc, MemToReg) for R-
format, lw, sw, beq instructions, respectively.
Add 1 1 0 0 0 0
lw 0 1 1 0 1 1
sw X 0 1 1 0 X
beq X 0 0 0 0 X
10
Q&A
• case1에서 j C1_BODY로 가서
case1에 해당하는 instruction(addi
$s1, $s1, 1)을 실행하게 됩니다.
• 그 후 C2_BODY의 명령어가
실행되지 않기 위해서 jump를
넣어줘야하는게 아닌지
궁금합니다.
11
• For the following C statement, write the corresponding MIPS
assembly code. Assume that the variables i and j are assigned to
registers $s0 and $s1, respectively. Assume that the base address of the
arrays A and B are in registers $s2 and $s3, respectively.