HW2 solutions
3.10
Pseuodinstructions
What is accomplished
Minimum sequence of Mips
Move $t5, $t3
$t5=$t3
Add $t5, $t3, $0
Clear $t5
$t5=0
Xor $t5, $t5, $t5
Li $t5, small
$t5=small
Addi $t5, $0, small
Li $t5, big
$t5=big
lui $t5, big[31:16]
Ori $t5, $t5, big[15:0]
Lw $t5, big($t3)
$t5=mem[$t3+big]
Lui $t5, big[31:26]
Ori $t5, $t0, big[15:0]
Add $t3, $t3, $t5
Lw $t5, 0($t3)
Addi $t5, $t3, big
$t5=$t3+big
Lui $t5, big[31:16]
Ori $t5, big[15:0]
Addi $t5, $t5, $t3
Beq $t5, small, L
If $t5=small, branch to L
Addi $at, $0, small
Beq $t5, $at, L
Beq $t5, big, L
If $t5=big, branch to L
Lui $at, big[31:16]
Ori $at, big[15:0]
Beq $at, $t5, L
Ble $t5, $t3, L
If $t5<=$t3, branch to L
Slt $at, $t3, $t5
Beq $at, $0, L
Bge $t5, $t3, L
If $t5>=$t3, branch to L
Slt $at, $t5, $3
Beq $at, $0, L
Bgt $t5, $t3, L
If $t5>$t3, branch to L
Slt $at, $t3, $t5
Bne $at, $0 L
3.25
You did this for Lab 1.
3.29
sbn temp, temp, .+1 # temp = 0;
sbn temp, b, .+1 # temp = -b;
sbn a, temp, .+1 # a = a – (-b) = a + b;
3.30
sbn neg_a, neg_a, .+1 # neg_a = 0;
sbn neg_a, a, .+1 # neg_a = -a;
sbn c, c, .+1 # c = 0;
loop: sbn b, one, .+1 # do { b = b – 1;
sbn c, neg_a, .+1 # c = c + a;
sbn temp, temp, .+1 # temp = 0;
sbn temp, b, loop # } while (b > 0);