Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WRITING CODE ON MARS (utils.asm for reference) # File: utils.asm # Purpose: To define utilities which will be used in MIPS programs. # Author: Charles

WRITING CODE ON MARS

(utils.asm for reference)

# File: utils.asm # Purpose: To define utilities which will be used in MIPS programs. # Author: Charles Kann # # Instructors are granted permission to make copies of this file # for use by # students in their courses. Title to and ownership # of all intellectual property rights # in this file are the exclusive property of # Charles W. Kann, Gettysburg, Pa. # # Subprograms Index: # Exit - Call syscall with a server 10 to exit the program # NewLine - Print a new line character ( ) to the console # PrintInt - Print a string with an integer to the console # PrintString - Print a string to the console # PromptInt - Prompt the user to enter an integer, and return # it to the calling program. # # Modification History # 12/27/2014 - Initial release # subprogram: PrintNewLine # author: Charles Kann # purpose: to output a new line to the user console # input: None # output: None # side effects: A new line character is printed to the # user's console .text PrintNewLine: li $v0, 4 la $a0, __PNL_newline syscall jr $ra .data __PNL_newline: .asciiz " " # subprogram: PrintInt # author: Charles W. Kann # purpose: To print a string to the console # input: $a0 - The address of the string to print. # $a1 - The value of the int to print # returns: None # side effects: The String is printed followed by the integer value. .text PrintInt: # Print string. The string address is already in $a0 li $v0, 4 syscall # Print integer. The integer value is in $a1, and must # be first moved to $a0. move $a0, $a1 li $v0, 1 syscall #return jr $ra # subprogram: PromptInt # author: Charles W. Kann # purpose: To print the user for an integer input, and # to return that input value to the caller. # input: $a0 - The address of the string to print. # returns: $v0 - The value the user entered # side effects: The String is printed followed by the integer value. .text PromptInt: # Print the prompt, which is already in $a0 li $v0, 4 syscall # Read the integer value. Note that at the end of the # syscall the value is already in $v0, so there is no # need to move it anywhere. move $a0, $a1 li $v0, 5 syscall #return jr $ra

# subprogram: PrintString # author: Charles W. Kann # purpose: To print a string to the console # input: $a0 - The address of the string to print. # returns: None # side effects: The String is printed to the console. .text PrintString: addi $v0, $zero, 4 syscall jr $ra # subprogram: Exit # author: Charles Kann # purpose: to use syscall service 10 to exit a program # input: None # output: None # side effects: The program is exited .text Exit: li $v0, 10 syscall

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

  • Write a program called SimpleCalculator.asm that uses the util methods to add two numbers.
  • Your program must include your own subroutine, written below the main subroutine, that receives two numbers and returns the sum of those two numbers.
  • Your main method should look as follows.
  • Display a welcome message to the user

Call PromptInt to get the first number Move the results to $t0 Call PromptInt to get the second number Move results to $t1 Move the values in $t0 and $t1 to the appropriate registers for a subroutine call. Call the AddTwo Subroutine Move the results to an appropriate register Call PrintInt to display the results Call PrintNewLine Call Exit

Example of how the program should look

Welcome to the Simple Calculator! Please enter number 1: 12 Please enter number 2: 13 The sum of the numbers is 25

Make sure your code is well documented. Look at Utils.asm on how to document a subroutine.

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions