Question

In: Computer Science

Write a MIPS program that asks the user for 2 numbers. Output the sum of the...

Write a MIPS program that asks the user for 2 numbers. Output the sum of the 2 numbers. The difference between the 2 numbers (num1-num2) and (num2-num1)
The value that is 305 more than the 1st number.
The value that is 305 less than the 2nd number

Solutions

Expert Solution

MIPS Program to get two Numbers and Output the sum, the difference between two number (num1-num2) and (num2-num1) :

.data  #start of data segment
   # defining prompt message to be displayed.
   prompt1: .asciiz "Enter First Number " 
   prompt2: .asciiz "Enter Second Number "
   result_prompt1: .asciiz "\nThe sum of two number is "
   result_prompt2: .asciiz "\nThe difference (num1 - num2) is "
   result_prompt3: .asciiz "\nThe difference  (num2 - num1) is "
   
.text  # start of code segment
  main: #main
    
    li $v0,4 # this instruction is used to print string
    la $a0,prompt1 # preparing string to be displayed.
    syscall # issue system call to display string
    
    li $v0,5 #this instruction is used to get integer input.
    syscall  #issue system call to get user input.
    move $t0,$v0 #move entered value to register $t0
    
    li $v0,4 # this instruction is used to print string
    la $a0,prompt2 # preparing string to be displayed.
    syscall # issue system call to display string
    
    li $v0,5 #this instruction is used to get integer input.
    syscall #issue system call to get user input.
    move $t1,$v0 #move entered value to register $t1
    
    add $s0,$t0,$t1 # add to entered values and save result in $s0 register
    li $v0,4  # this instruction is used to print string
    la $a0,result_prompt1 # preparing string to be displayed.
    syscall # issue system call to display string
    li $v0,1 #prepare to display variable value
    move $a0,$s0 # move addition result to $a0
    syscall #issue system call
    
    sub $s1,$t0,$t1 # substract two values entered by user (num1-num2) and store in register $s1
    li $v0,4  # this instruction is used to print string
    la $a0,result_prompt2 # preparing string to be displayed.
    syscall # issue system call to display message
    li $v0,1 # prepare to display variable value
    move $a0,$s1 # move substraction result to $a0
    syscall # issue system call
    
    sub $s2,$t1,$t0 # substract two values entered by user (num2-num1) and store in register $s2
    li $v0,4  # this instruction is used to print string
    la $a0,result_prompt3 # preparing string to be displayed.
    syscall # issue system call to display message
    li $v0,1 # prepare to display variable value
    move $a0,$s2 # move substraction result to $a0
    syscall # issue system call

Sample Output :

Please refer to the screenshot of code below to understand indentation of code :


Related Solutions

Write a simple MIPS program that asks the user to input a string and then a...
Write a simple MIPS program that asks the user to input a string and then a character. The program should then count how many times that character appears in the string and print out that value. Please use comments.
Write a mips program that would function in QTSPIM that asks the user to enter a...
Write a mips program that would function in QTSPIM that asks the user to enter a list of integer values, one per line, with the last value being a negative. The program should read in these integers until a negative number is entered. Afterwards the program should print 1) sum, 2) minimum value, 3) max value, 4) mean and 5) variance value. of the numbers that were entered.
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
Write MIPs program that will read two integers from the user and compute for the sum...
Write MIPs program that will read two integers from the user and compute for the sum and difference of the two integers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Write MIPs program that will read two intergers from the user and compute for the sum...
Write MIPs program that will read two intergers from the user and compute for the sum and difference of the two intergers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
Write a program that asks the user to enter an array of random numbers, then sort...
Write a program that asks the user to enter an array of random numbers, then sort the numbers (ascending order), then print the new array, after that asks the user for a new two numbers and add them to the same array and keep the array organization. (c++ ) (using while and do while loops)
in C++, Write a program that asks the user to enter 6 numbers. Use an array...
in C++, Write a program that asks the user to enter 6 numbers. Use an array to store these numbers. Your program should then count the number of odd numbers, the number of even numbers, the negative, and positive numbers. At the end, your program should display all of these counts. Remember that 0 is neither negative or positive, so if a zero is entered it should not be counted as positive or negative. However, 0 is an even number....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT