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: 667445 • 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 50274 10and num2 to CB7 16 (use 0xCB7 to initialize). 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.

__________________________________________________

This is what I have so far. It runs without errors, but I am not getting anything on the console window/nothing is printing out.

.data

num1: .word 50274
num2: .word 0xCB7

.text
main:
lw $t0, num1
lw $t1, num2
add $s0, $t0, $t1
sub $s1, $t0, $t1
li $v0, 1
la $a0, num1
syscall
li $v0, 1
la $a0, num2
syscall
li $v0, 1
move $a0, $s0
syscall
li $v0, 1
move $a0, $s1
syscall

Explanation / Answer

working mips code.

You can enter any value from user:

.data
prompt1: .asciiz " Enter the first integer please:"
prompt2: .asciiz "Enter the second integer please:"
result: .asciiz "The result is:"

              .text
main:
    #t0-to hold first integer
    #t1-to hold second integer
    #t2- used to hold the sum of t$1 and t$2
        #first number
        li $v0, 4 #syscall to print string
        la $a0, prompt1 #address of string to print
        syscall
#
        li $v0, 5 #syscall to read an integer
        syscall
        move $t0, $v0 #move the number to read into $t0
    #second number
    li $v0, 4
    la $a0, prompt2
    syscall
#
    li $v0,5      
    syscall
    move $t1,$v0
#
    #print out sum of $t2
    li $v0, 4
    la $a0, result
    syscall
#
    add $a0, $t1, $t0 #compute the sum
    li $v0, 1
    syscall
#
    li $v0, 10
    syscall

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