Lecture 3
3.5
lw $t0, 0($s0)
sw $t0, 0($s1)
3.6
add $t0, $s0, $s1
add $t0, $t0, $s2
sub $s4, $t0, $s3
3.7
add $t0, $s0, $s1
sub $t1, $s2, $s3
mult $t0, $t1
mflo $s4
3.8
lw $t0, 0($s0)
mult $t0, $t0
mflo $t0
sw $t0, 0($s1)
addi $s0, $s0, 4
addi $s1, $s1, 4
lw $t0, 0($s0)
mult $t0, $t0
mflo $t0
sw $t0, 0($s1)
addi $s0, $s0, 4
addi $s1, $s1, 4
lw $t0, 0($s0)
mult $t0, $t0
mflo $t0
sw $t0, 0($s1)
addi $s0, $s0, 4
addi $s1, $s1, 4
lw $t0, 0($s0)
mult $t0, $t0
mflo $t0
sw $t0, 0($s1)
Lecture 4
4.7
slt $t0, $s0, $s1
bne $t0, $zero, L1 # True: $s0 < $s1
# False: $s0 >= $s1
slt $t1, $s0, $s2
bne $t1, $zero, L2 # True: $s1 <= $s0 < $s2
# False: $s0 > = $s2 and $s0 >= $s1
addi $s3, $s0, 0
j End
L1: slt $t1, $s1, $s2
bne $t1, $zero, L3 # True: $s0 < $s1 < $s2
# False: $s0 < $s1 and $s1 >= $s2
addi $s3, $s1, 0
j End
L2: addi $s3, $s2, 0
j End
L3: addi $s3, $s2, 0
j End
End:
4.8
addi $t0, $zero, 0
addi $t1, $zero, 1
sw $t0, 0($s1)
addi $s0, $s0, -1 # Count down $s0
beq $s0, $zero, End # Exit program if $s0 is 0
Loop: addi $s1, $s1, 4
sw $t1, 0($s1)
addi $t2, $t0, 0
addi $t0, $t1, 0
add $t1, $t2, $t1
addi $s0, $s0, -1
bne $s0, $zero, Loop # Repeat if $s0 is not 0
End:
4.9
addi $s0, $zero, 5000
lw $t0, 0($s0)
sll $t1, $t0, 3
srl $t2, $t0, 4
sw $t1, 4($s0)
sw $t2, 8($s0)
Lecture 5
5.4
Main:
add $a0, $zero, $s0
add $a1, $zero, $s1
jal Sum
add $s2, $zero, $v0
add $a0, $zero, $s1
add $a1, $zero, $s0
jal Dif
add $s3, $zero, $v0
j End
# Procedure Sum
Sum:
add $v0, $a0, $a1
jr $ra
# Procedure Dif
Dif:
sub $v0, $a0, $a1
jr $ra
End: