Question

(USING THE PROGRAM MARS) Using the MemoryAccess program we wrote in class as a starting point,...

(USING THE PROGRAM MARS) Using the MemoryAccess program we wrote in class as a starting point, write a program called LoadStore

# Title : Memory access.asm
#Desc: Practice initially memory,
#in val1 = 0x0a;
#int val2 = 0x0b;
#int result;
#string resultstring = " final answer : ";
#string returnchar = "\n";
#void main() {
#   result = val1 + val2;
#   cout<<< resultstring << returnchar;
#}
.data
val1: .word 0x0a   #store 0xa into variable val1
val2: .word 0x0b   #store 0xb into val2
result: .word 0 #destination
resultstring: .asciiz "final answer is: "
returnchar: .asciiz "\n"

.text
   .globl main
   main:
       #load our values into registers
       lw $t0, val1
       lw $t1, val2
  
       #do the math
       add $t0, $t0, $t1
       #store the total back into result
       sw $t0, result
       #series of 3 prints. string then number then string
       li $v0, 4   #syscode for printing a string
       la $a0, resultstring   #address of string to print
       syscall
       #print an integer
       li $v0, 1   #syscode for printing an int
       lw $a0, result    #we want the value in $a0
       syscall
       #print return charater
       li $v0, 4
       la $a0, returnchar
       syscall
      
       #get out of dodge
       li $v0, 10
       syscall

^^^^^^^^^^^^^^^^^^memory access program

The Algorithm for your program is as follows:

  1. Ask the user for a first number
  2. Get that number
  3. Store that number to val1 in Data Storage
  4. Ask the user for a second number
  5. Get that number
  6. Store that number to val2 in Data Storage
  7. Ask the user for a third number
  8. Get that number
  9. Store that number to val3 in Data Storage
  10. Load val1, val2 and val3 into $s0, $s1 and $s2
  11. Set $s3 to $s0 + $s1 - $s2
  12. Store $s3 into results
  13. Print the final answer. This could be tricky
  14. Exit cleanly as always.

Your output should look as follows (Example User Input is shown in bold):

Please enter the first number:  12
Please enter the second number:  13
Please enter the third number:  14
Result: 12 + 13 – 14 = 11

---------------------------------------

Hint: The operators are strings

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM:

.data
   val1: .space 4
   val2: .space 4
   val3: .space 4
   result: .space 4
   prompt1: .asciiz "Please enter first number: "
   prompt2: .asciiz "Please enter second number: "
   prompt3: .asciiz "Please enter third number: "
   output: .asciiz "Result: "
   plus: .asciiz " + "
   minus: .asciiz " - "
   equal_sign: .asciiz " = "
.text
.globl main
main:
   li $v0,4           # 4 is the print string syscall
   la $a0,prompt1           # Address of the string to be printed
   syscall               # Print the string
   li $v0,5           # 5 is the read integer syscall
   syscall               # Read the integer
   sw $v0,val1           # Store the integer in val1
  
   li $v0,4           # 4 is the print string syscall
   la $a0,prompt2           # Address of the string to be printed
   syscall               # Print the string
   li $v0,5           # 5 is the read integer syscall
   syscall               # Read the integer
   sw $v0,val2           # Store the integer in val2
  
   li $v0,4           # 4 is the print string syscall
   la $a0,prompt3           # Address of the string to be printed
   syscall               # Print the string
   li $v0,5           # 5 is the read integer syscall
   syscall               # Read the integer
   sw $v0,val3           # Store the integer in val3
  
   lw $s0,val1           # Load val1 into $s0
   lw $s1,val2           # Load val2 into $s1
   lw $s2,val3           # Load val3 into $s2
  
   add $s3,$s0,$s1           # $s3 = $s0 + $s1
   sub $s3,$s3,$s2           # $s3 = $s3 - $s2
   sw $s3,result           # Store $s3 into memory
  
   li $v0,4           # 4 is the print string syscall
   la $a0,output           # Address of the string to be printed
   syscall               # Print the string
   li $v0,1           # 1 is the print integer syscall
   lw $a0,val1           # Load integer to be printed
   syscall               # Print the integer
   li $v0,4           # 4 is the print string syscall
   la $a0,plus           # Address of the string to be printed
   syscall               # print the string
   li $v0,1           # 1 is the print integer syscall
   lw $a0,val2           # Load integer to be printed
   syscall               # Print the integer
   li $v0,4           # 4 is the print string syscall
   la $a0,minus           # Address of the string to be printed
   syscall               # Print the string
   li $v0,1           # 1 is the print integer syscall
   lw $a0,val3           # Load integer to be printed
   syscall               # Print the integer
   li $v0,4           # 4 is the print string syscall
   la $a0,equal_sign       # Address of the string to be printed
   syscall               # Print the string
   li $v0,1           # 1 is the print integer syscall
   lw $a0,result           # Load integer to be printed
   syscall               # Print the integer
  
   li $v0,10           # 10 is exit program syscall
   syscall               # Exit the program

Please refer to the following screenshot of the program for indentation of the code:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
(USING THE PROGRAM MARS) Using the MemoryAccess program we wrote in class as a starting point,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data...

    WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4    la...

  • .data prompt: .asciiz "Input an integer x:\n" result: .asciiz "Fact(x) = " .text main: # show prompt li $v0, 4 la $a0, prompt syscall # read x li $v0, 5 syscall # function call move $a...

    .data prompt: .asciiz "Input an integer x:\n" result: .asciiz "Fact(x) = " .text main: # show prompt li $v0, 4 la $a0, prompt syscall # read x li $v0, 5 syscall # function call move $a0, $v0 jal factorial # jump factorial and save position to $ra move $t0, $v0 # $t0 = $v0 # show prompt li $v0, 4 la $a0, result syscall # print the result li $v0, 1 # system call #1 - print int move $a0,...

  • MIPS - Takes two inputs from the user, which are the lengths of two sides of...

    MIPS - Takes two inputs from the user, which are the lengths of two sides of a polygon. It adds those two lengths and prints the sum. Your task is modify the program to make it specific to a triangle, and to print the perimeter of that triangle. See blue highlighted. preamble: prompt1: prompt2: answer: endline: .data ascii .asciiz asciiz .asciiz asciiz .asciiz "\nThis program, written by <YOUR NAME>," " can be used to add the length of two sides...

  • QT Spim question. Program and answer already given please explaine it. Please explain the reason why...

    QT Spim question. Program and answer already given please explaine it. Please explain the reason why each instruction was used throughout the program step by step given the prompt, what is its purpose to achive the goal asked in the prompt, why is written in that order. Please not just write to the side what each instruction means in words like load $t0 to $t1. I want to understand the program thoroughly. Thanks in advance Previous information needed to solve...

  • 1. Modify larger.s to let the user to enter three numbers and output the largest value...

    1. Modify larger.s to let the user to enter three numbers and output the largest value # larger.s-- prints the larger of two numbers specified # at runtime by the user. # Registers used: # $t0 - used to hold the first number. # $t1 - used to hold the second number. # $t2 - used to store the larger of $t1 and $t2. # $v0 - syscall parameter and return value. # $a0 - syscall parameter. .text main: ##...

  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • Write a MIPS program that prints(displays) "Hello World" using MMIO (NOT syscall!) Here is a scre...

    Write a MIPS program that prints(displays) "Hello World" using MMIO (NOT syscall!) Here is a screenshot of a MIPS program that prints user input to the screen. And I need something that displays "Hello World" without taking any input. Please help! Thanks. The output should be something like this but without the input .data 7 strl:.asciiz "\nStart entering characters in the MMIO Simulator" .text 10 .globl echo 12 13 14 15 16 17 echo: al Read # single print statement...

  • ASSEMBLY LANGUAGE (Mars MIPS) Starting code: Factorial: #Factorial Recursive function subu $sp, $sp, 4 sw $ra,...

    ASSEMBLY LANGUAGE (Mars MIPS) Starting code: Factorial: #Factorial Recursive function subu $sp, $sp, 4 sw $ra, 4($sp) # save the return address on stack beqz $a0, terminate # test for termination subu $sp, $sp, 4 # do not terminate yet sw $a0, 4($sp) # save the parameter sub $a0, $a0, 1 # will call with a smaller argument jal Factorial # after the termination condition is reached these lines # will be executed lw $t0, 4($sp) # the argument I...

  • Hello, I'm having trouble completing this program in less than four lines using MIPS programming language,...

    Hello, I'm having trouble completing this program in less than four lines using MIPS programming language, we are required to fill in the missing code as indicated (via comments). IMPORTANT: As indicated in the program's comments: ⇒ Write no more than certain number of lines of code as indicated. (One instruction per line, and there will be penalty if your code consumes more lines.) ⇒ Code MUST use only instructions that are allowed i.e., only bit manipulating instructions: (ANDing, ORing,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT