Question

In: Computer Science

Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...

Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S. The program then prints out the result (i.e. integer S) after printing the string "The sum of X and Y (X + Y) is ".

Then assemble and run the program with MARS to show and capture the input/output.

Instruction:

1. A copy of the final working assembly language source code with comments and documentation. The file should be "text-only" and the extension must be ".s" or ".asm".

2. A screenshot showing keyboard input and displayed output from the console.

Solutions

Expert Solution

Given below is the code and output for the question. Please do rate the answer if it helped. Thank you.

.data
   xMsg: .asciiz "Enter the values for X: "
   yMsg: .asciiz "Enter the values for Y: "
   outMsg: .asciiz "The sum of X and Y (X + Y) is "
   X: .word 0
   Y: .word 0
   S: .word 0
  
.text
   #print string
   la $a0, xMsg
   li $v0, 4
   syscall
  
   #read int and store in X
   li $v0, 5
   syscall
   sw $v0, X

   #print string
   la $a0, yMsg
   li $v0, 4
   syscall
  
   #read int and store in Y
   li $v0, 5
   syscall
   sw $v0, Y

   #load X into $t0, and Y into $t1, calculate sum into $t0 and save to S
   lw $t0, X
   lw $t1, Y
   add $t0, $t0, $t1
   sw $t0, S
  
   #display the result - msg and then number from S
   la $a0, outMsg
   li $v0, 4
   syscall
  
   #print number from S
   lw $a0, S
   li $v0, 1
   syscall

   #exit
   li $v0, 10
   syscall


output
----
Enter the values for X: 2
Enter the values for Y: 3
The sum of X and Y (X + Y) is 5
-- program is finished running --


Related Solutions

Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a MIPS assembly language program that inputs a floating-point number and shows its internal 32-bit...
Write a MIPS assembly language program that inputs a floating-point number and shows its internal 32-bit representation as a 8-digit hexadecimal representation. For example: 2.5 decimal is 10.1 binary, which normalized is 1.01x21 and would be stored in the IEEE format as 0100 0000 0010 0000 0000 0000 0000 0000 which is 0x40200000
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle....
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle. (NAME = John Doe) 2)Write a Program that intializes X to 10, Y to 20 and Z to -50, adds X and Y and Z and prints the following the value of each variable, for example value of x is 10 as well as the result of the addition.
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...
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
using Windows 32 bit framework , Write an assembly language program to find the second minimum...
using Windows 32 bit framework , Write an assembly language program to find the second minimum element (formally, second minimum is larger than the minimum but smaller than all the other elements in the array) of an array of size 100. Note: You can define the array as nbrArray DWORD 23 45 21 67 78 95 dup(?) and show that your program works for the first five elements. Display the second minimum in a message box using Input output macro
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 assembly language program. Ask the user whether he wants to repeat the program:...
Write a mips assembly language program. Ask the user whether he wants to repeat the program: "\nRepeat [y/n]? ". Use service code 12 to read a character and the branch instruction to repeat the main function if the user input is character 'y'.
Write a MIPS Assembly language program to request a file name from the user, open the...
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write out the contents to the console. This is what I have so far: .data    fileName:   .space 100    prompt1:   .asciiz "Enter the file name: "    prompt2:    .asciiz ""    prompt3:   .asciiz "\n"    buffer:    .space 4096 .text    main:        #        li $v0, 4        la $a0, prompt1       ...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT