# MIPS Assembly Language Program in SPIM To Perform Some Math Operations Assignment Solution.

## Instructions

Objective
Write a MIPS assembly language program in SPIM to perform some math operations.

## Requirements and Specifications

Write a SPIM program to calculate 2 * ( 111 + 333) - 12345.
Use R8, R9, and R10 to store the values 10, 20, and 15 respectively. Store the result in R12. Run the program and submit the screenshot (showing program code and register values).
Write a SPIM program to "prompt the user to enter" a radius of a circle (integer only), and to display the diameter (use add - do not use MUL). The radius and the diameter can be stored in the registers.
Write a SPIM program to prompt the user to enter two numbers x and y (integers only), and to display their sum z, z = x + y. All x, y, and z can be stored in the registers. Register Mapping: x: \$t0 , y: \$t1, z: \$t2 (Use RAM to store those value).
Screenshots of output

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

li \$v0, 4 # load syscall to print a string

syscall # print the prompt

syscall # read integer in \$v0

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

li \$v0, 4 # load syscall to print a string

syscall # print the prompt

syscall # read integer in \$v0

move \$t0, \$v0 # save x in \$t0

li \$v0, 4 # load syscall to print a string

syscall # print the prompt

syscall # read integer in \$v0

move \$t1, \$v0 # save y in \$t1

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

li \$v0, 4 # load syscall to print a string

syscall # print the prompt

syscall # read integer in \$v0

sw \$v0, 0(\$t0) # save read number in num1

li \$v0, 4 # load syscall to print a string

syscall # print the prompt

syscall # read integer in \$v0

sw \$v0, 0(\$t0) # save read number in 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

li \$v0, 4 # load syscall to print a string

syscall # print the result message

li \$v0, 1 # load syscall to print an integer

lw \$a0, 0(\$t0) # load num1 value to be printed

syscall # print integer

li \$v0, 4 # load syscall to print a string

syscall # print the result message

li \$v0, 1 # load syscall to print an integer