Instructions
Requirements and Specifications




Source Code
Program 1
.text
main:
li $8, 10 # R8 = 10
li $9, 20 # R9 = 20
li $10, 15 # R10 = 15
li $12, 111 # R12 = 111
addi $12, $12, 333 # R12 = 111 + 333
sll $12, $12, 1 # R12 = 2* (111 + 333)
li $11, 12345 # R11 = 12345
sub $12, $12, $11 # R12 = 2* (111 + 333) - 12345
li $2, 10 # syscall to exit
syscall # exit program
Program 2
.data
prompt: .asciiz "Circle radius? = "
result: .asciiz "Diameter = "
.text
la $a0, prompt # load address of prompt string
li $v0, 4 # load syscall to print a string
syscall # print the prompt
li $v0, 5 # load syscall to read an integer
syscall # read integer in $v0
add $t0, $v0, $v0 # diameter = 2*radius = radius + radius
la $a0, result # load address of result string
li $v0, 4 # load syscall to print a string
syscall # print the result message
li $v0, 1 # load syscall to print an integer
move $a0, $t0 # copy result value to be printed
syscall # print integer
li $v0, 10 # syscall to exit
syscall # exit program
Program 3
.data
promptx: .asciiz "x value? = "
prompty: .asciiz "y value? = "
result: .asciiz "x + y = "
.text
la $a0, promptx # load address of prompt string
li $v0, 4 # load syscall to print a string
syscall # print the prompt
li $v0, 5 # load syscall to read an integer
syscall # read integer in $v0
move $t0, $v0 # save x in $t0
la $a0, prompty # load address of prompt string
li $v0, 4 # load syscall to print a string
syscall # print the prompt
li $v0, 5 # load syscall to read an integer
syscall # read integer in $v0
move $t1, $v0 # save y in $t1
add $t2, $t0, $t1 # add z = x + y
la $a0, result # load address of result string
li $v0, 4 # load syscall to print a string
syscall # print the result message
li $v0, 1 # load syscall to print an integer
move $a0, $t2 # copy result value to be printed
syscall # print integer
li $v0, 10 # syscall to exit
syscall # exit program
Program 4
.data
prompt1: .asciiz "num1 value? = "
prompt2: .asciiz "num2 value? = "
result1: .asciiz "swapped num1 = "
result2: .asciiz "\nswapped num2 = "
num1: .word 0
num2: .word 0
.text
la $a0, prompt1 # load address of prompt string
li $v0, 4 # load syscall to print a string
syscall # print the prompt
li $v0, 5 # load syscall to read an integer
syscall # read integer in $v0
la $t0, num1 # load address of variable num1
sw $v0, 0($t0) # save read number in num1
la $a0, prompt2 # load address of prompt string
li $v0, 4 # load syscall to print a string
syscall # print the prompt
li $v0, 5 # load syscall to read an integer
syscall # read integer in $v0
la $t0, num2 # load address of variable num2
sw $v0, 0($t0) # save read number in num2
la $t0, num1 # load address of variable num1
la $t1, num2 # load address of variable num2
lw $t2, 0($t0) # load num1
lw $t3, 0($t1) # load num2
sw $t2, 0($t1) # swap num1 to num2
sw $t3, 0($t0) # swap num2 to num1
la $a0, result1 # load address of result string
li $v0, 4 # load syscall to print a string
syscall # print the result message
li $v0, 1 # load syscall to print an integer
la $t0, num1 # load address of variable num1
lw $a0, 0($t0) # load num1 value to be printed
syscall # print integer
la $a0, result2 # load address of result string
li $v0, 4 # load syscall to print a string
syscall # print the result message
li $v0, 1 # load syscall to print an integer
la $t0, num2 # load address of variable num2
lw $a0, 0($t0) # load num2 value to be printed
syscall # print integer
li $v0, 10 # syscall to exit
syscall # exit program