Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MIPS assembly language program that adds two integers and displays the s

ID: 2247259 • Letter: W

Question

Write a MIPS assembly language program that adds two integers and displays the sum and the difference. In the .data section, define two variables num1 and num2 both words. Initialize num1 to 75301 10 and num2 to D5A 16 (use 0xD5A to initialize, Note that D5A is a hexadecimal number). Your main procedure should load the values of num1 and num2 into two temporary registers, and display them on the console window. Then add the values together, and use the print_int system call function to display the sum on the console window. Also compute the difference of two numbers and display it on the console window. (Reference: see Assignment 1) To print an integer on the console window, you must put the integer to be printed in the $a0 register, and the value 1 in the $v0 register. Then perform a syscall operation. This makes a call to the PCSPIM operating system which will display the integer in $a0 on the console window. Name your source code file assignment2.s.

Your output format should look as follows:

num1 is: XXX

num2 is: XXX

num1+num2 = XXX

num1-num2 = XXX

where XXX is the correct number for each.

Explanation / Answer

Given below is the MIPS program to add and subtract the specified numbers. Please don't forget to rate the answer if it helped. Thank you very much.

.data
num1: .word 75301
num2: .word 0xD5A
num1_msg: .asciiz " num1 = "
num2_msg: .asciiz " num2 = "
sum_msg: .asciiz " num1 + num2 = "
sub_msg: .asciiz " num1 - num2 = "


.text

#load num1 and num2 into t1 and t2 respectively
lw $t1, num1
lw $t2, num2


#assign t3 = num1 + num2 and t4 = num1 - num2
add $t3, $t1, $t2
sub $t4, $t1, $t2

#display num1
li $v0, 4
la $a0, num1_msg
syscall

li $v0, 1
move $a0, $t1
syscall

#display num2

li $v0, 4
la $a0, num2_msg
syscall

li $v0, 1
move $a0, $t2
syscall


#display num1 + num2 i.e. t3
li $v0, 4
la $a0, sum_msg
syscall

li $v0, 1
move $a0, $t3
syscall
#display num1 - num2 i.e t4

li $v0, 4
la $a0, sub_msg
syscall

li $v0, 1
move $a0, $t4
syscall

#exit
li $v0, 10
syscall

output


num1 = 75301
num2 = 3418
num1 + num2 = 78719
num1 - num2 = 71883

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote