In: Computer Science
Assignment Description:
Write a MIPS assembly language program that adds the following two integers and displays the sum and the difference. In the .data section, define two variables num1 and num2 both words. Initialize num1 to 92413 10 and num2 to D4B 16 (use 0xD4B to initialize, Note that D4B is a hexadecimal number). Your main procedure/function 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 syscall for 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 SPIM 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 and they should be printed in decimal.
Please find the code below::
.data
num1 : .word 92413
num2 : .word 0xD4B
str1: .asciiz "num1 is : "
str2: .asciiz "num2 is : "
str3: .asciiz "num1+num2 = "
str4: .asciiz "num1-num2 = "
.text
lw $s0,num1 #loading s0 to num1
lw $s1,num2 #loading s0 to num2
add $s2,$s0,$s1 #s2 will store addition
sub $s3,$s0,$s1 #s3 will store subtraction
li $v0,4
la $a0,str1
syscall
li $v0,1
move $a0,$s0 #print value of s0
syscall
li $v0,11
li $a0,'\n' #print new line
syscall
li $v0,4
la $a0,str2
syscall
li $v0,1
move $a0,$s1 #print value of s1
syscall
li $v0,11
li $a0,'\n' #print new line
syscall
li $v0,4
la $a0,str3
syscall
li $v0,1
move $a0,$s2 #print value of s2
syscall
li $v0,11
li $a0,'\n' #print new line
syscall
li $v0,4
la $a0,str4
syscall
li $v0,1
move $a0,$s3 #print value of s3
syscall
li $v0,11
li $a0,'\n' #print new line
syscall
output: