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: 3561266 • 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 numl and num2 both words. Initialize numl to 89021 jq and num2 to D9E jg (use 0xD9E to initialize). Your main procedure should load the values of numl 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 SaO register, and the value 1 in the SvO register. Then perform a syscall operation. This makes a call to the PCSPIM operating system which will display the integer in SaO on the console window. Name your source code file assignment2.s. Your output format should look as follows: where XXX is the correct number for each.

Explanation / Answer

.data
prompt: .asciiz "num1 is : "
prompt1: .asciiz " num2 is : "
prompt2: .asciiz " num1 + num2 = "
prompt3: .asciiz " num1 - num2 = "
#variable declarations
num1: .word 89021
num2: .word 0xD9E
.text

main :
# print the string
li $v0,4
la $a0,prompt
syscall
# print the int
li $v0,1
la $a0,num1
lw $a0,($a0)
syscall
# print the string
li $v0,4
la $a0,prompt1
syscall
# print the int
li $v0,1
la $a0,num2
lw $a0,($a0)
syscall
#num1+num2 =
la $t0,num2
lw $t0,($t0)
la $t1,num1
lw $t1,($t1)
add $t0,$t1,$t0
# print the string
li $v0,4
la $a0,prompt2
syscall
# print the int
li $v0,1
addi $a0,$t0,0
syscall
#num1-num2 =
la $t0,num2
lw $t0,($t0)
la $t1,num1
lw $t1,($t1)
sub $t0,$t1,$t0
# print the string
li $v0,4
la $a0,prompt3
syscall
# print the int
li $v0,1
addi $a0,$t0,0
syscall
InfLoop : j InfLoop # stay here for infinite time

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