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

MIPS assembly language code Write an assembly language program to: -load address

ID: 2247300 • Letter: M

Question

MIPS assembly language code

Write an assembly language program to: -load addresses of variables or values of variables into registers. -perform arithmetic and logical operations on variables -use syscall operations to display integers and strings on the console window 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 OxD5A 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 theriat 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

Hi..

Author: Evan Bechtol
# Description: This program prompts the user to enter 2 integers and computes their sum.
#---------------------------------------------------------------------------------------#
.data
A: .word # Store the number 4 as an integer in var1 # $t0 is used
B: .word # Store the number 2 as an integer in var2 # $t1 is used
S: .word # Store the sum of A and B # $t2 is used
Prompt1: .asciiz "Please enter first number: "
Prompt2: .asciiz "Please enter second number: "
Result: .asciiz "The sum of A and B is: "
.text
main:
#--------------------------------------------------------#
#Display first prompt
li $v0, 4 # Load instruction "print string"
la $a0, Prompt1 # Load prompt into $a0
syscall

#Read first integer
li $v0, 5 # Read 1st integer
la $t0, A # $t0 = A
syscall

#Store first integer into memory
move $t0, $v0 # Move contents in $v0 to $t0
sw $t0, A # A = value at $t0
#--------------------------------------------------------#

#Display second prompt
li $v0, 4 # Load instruction "print string"
la $a0, Prompt2 # Load prompt into $a0
syscall

#Read second integer
li $v0, 5 # Read 1st integer
la $t1, B # $t0 = A
syscall

#Store second integer into memory
move $t1, $v0 # Move contents in $v0 to $t0
sw $t1, B # A = value at $t0
#--------------------------------------------------------#

#Add the two variables
la $t2, S # $t2 = S   
add $t2, $t0, $t1 # $t2 = $t0 + $t1
sw $t2, S # S = value at $t2

#Display the Result prompt
la $a0, Result # Loads Output label to be printed
li $v0, 4 # Sysycall to print string
syscall

#Display the sum
lw $a0, S # $a0 = value at S
li $v0, 1 # Syscall to print integer
syscall

#Exit the program
li $v0, 10 # Load exit code to $v0
syscall

Thanks

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