Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use 'MARS' to Solve the problem (Mars is a tool which you can find it with key word mars mips simulator): Copy your updated macro.asm

Use 'MARS' to Solve the problem (Mars is a tool which you can find it with key word "mars mips simulator"):

Copy your updated macro.asm from last homework in a directory. And download second.asm in the same directory.

Add the following two macros in this macro.asm

1. swap_hi_lo ($temp1, $temp2) : This macro swap content of HI and LO register using specified temporary registers. For example 'swap_hi_lo($t0, $t1)' will swap content of HI and LO using $t0 and $t1 register. 2. print_hi_lo ($strHi, $strEqual, $strComma, $strLo) : This macro prints content of HI and LO register. It expects string address for string 'Hi', string '=', string ',' and string 'Lo'. You can use any temporary register inside macro definition to bring data out from HI and LO registers.

Assemble and execute second.asm. This should create following sample output

Enter number for Hi ? 32 Enter number for Lo ? 49 Before swapping Hi = 32 , Lo = 49 After swapping Hi = 49 , Lo = 32

============================================================

The given .asm document is as follow: macro.asm:

image text in transcribed

second.asm:

image text in transcribed

=================================================================

All the information are already shown above, just need help with two macros in macro.asm.

Please help, thank you!

# Macro : print_str # Usage: print_str(
) .macro print_str($arg) li $v0, 4 # System call code for print_str la Sal, $arg # Address of the string to print syscall # Print the string .end_macro # Macro : print_reg_int # Usage: print_reg_int () .macro print_reg_int($reg) li $v0, 1 # System call code for print_int move Sal, $reg # Integer to print syscall # Print the integer .end_macro # Macro : read int # Usage : read int () .macro read_int($reg) li $v0, 5 syscall move $reg, $v0 .end_macro # Macro : exit # Usage: exit .macro exit li $v0, 10 syscall .end_macro 1 include "./macro.asm" 3 .data 4 msgi: asciiz "Enter number for " 5 stri: .asciiz "Hi" 6 stro: asciiz "Lo" 7 strQuery: asciiz " ?" 8 strEqual: .asciiz " 9 strComma: .asciiz"," 10 strNewline: asciiz "n" 11 msg2: asciiz "Before swapping" 12 msg3: .asciiz "After swapping" 13 14 .text 15 globl main 16 main: # Get and store Hi value print_str(msgl) # Prints: Enter a number for print_str(strHi) # Prints: Hi print_str(strQuery) # Prints: ? read_int($t0) # Read integer into sto mthi $t0 # Move $t0 value to Hi # Get and store Lo value print_str(msgl) # Prints: Enter a number for print_str(strlo) # Prints: Hi print_str(strQuery) # Prints: ? read_int($t0) # Read integer into sto mtlo $t0 # Move sto value to Lo #print content of Hi and to print_str(msg2) # Prints: Before swaping print_hi_lo(strHi, strEqual, str Comma, strlo) # Prints: Hi = , Lo = print_str(strNewline) # Prints: newline # Swap the content svap_hi_lo($t0,$tl) #print content of Hi and Lo print_str(msg3) # Prints: After swaping print_hi_lo (strHi, strEqual, strComma, stro) # Prints: Hi = , Lo print_str(strNewline) # Prints: newline exit # Macro : print_str # Usage: print_str(
) .macro print_str($arg) li $v0, 4 # System call code for print_str la Sal, $arg # Address of the string to print syscall # Print the string .end_macro # Macro : print_reg_int # Usage: print_reg_int () .macro print_reg_int($reg) li $v0, 1 # System call code for print_int move Sal, $reg # Integer to print syscall # Print the integer .end_macro # Macro : read int # Usage : read int () .macro read_int($reg) li $v0, 5 syscall move $reg, $v0 .end_macro # Macro : exit # Usage: exit .macro exit li $v0, 10 syscall .end_macro 1 include "./macro.asm" 3 .data 4 msgi: asciiz "Enter number for " 5 stri: .asciiz "Hi" 6 stro: asciiz "Lo" 7 strQuery: asciiz " ?" 8 strEqual: .asciiz " 9 strComma: .asciiz"," 10 strNewline: asciiz "n" 11 msg2: asciiz "Before swapping" 12 msg3: .asciiz "After swapping" 13 14 .text 15 globl main 16 main: # Get and store Hi value print_str(msgl) # Prints: Enter a number for print_str(strHi) # Prints: Hi print_str(strQuery) # Prints: ? read_int($t0) # Read integer into sto mthi $t0 # Move $t0 value to Hi # Get and store Lo value print_str(msgl) # Prints: Enter a number for print_str(strlo) # Prints: Hi print_str(strQuery) # Prints: ? read_int($t0) # Read integer into sto mtlo $t0 # Move sto value to Lo #print content of Hi and to print_str(msg2) # Prints: Before swaping print_hi_lo(strHi, strEqual, str Comma, strlo) # Prints: Hi = , Lo = print_str(strNewline) # Prints: newline # Swap the content svap_hi_lo($t0,$tl) #print content of Hi and Lo print_str(msg3) # Prints: After swaping print_hi_lo (strHi, strEqual, strComma, stro) # Prints: Hi = , Lo print_str(strNewline) # Prints: newline exit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

Create a Fishbone diagram with the problem being coal "mine safety

Answered: 1 week ago