Question
In this assignment, you are to complete a MIPS program so it will perform the required tasks. The main function of the code is provided.
In this assignment, you are to complete a MIPS program so it will perform the required tasks. The main function of the code is provided. You are to complete the program by writing four functions. Pay particular attention to the purpose of each function and how the parameters and stack are to be used. NO pseudo code/extended formats. Turn off the option on MARS under settings that allows the use of these instructions,
1. print
$a0 integer value to print
$a1 address of string to print
This function must first print the string and then print the integer. Both outputs must be on the same line. End the output with a newline
2. multiplication $a0 first integer
$a1 second integer $v0 first integer * second integer
This function is to calculate and return the result of multiplying the first argument by the second argument. Assume that both arguments are greater than zero. You must calculate the result using a loop. Using any version of the mult instruction is NOT ACCEPTABLE.
3. getpos
$v0 positive integer input
This function must prompt the user to input a positive integer and then get input from the user. The process of printing a prompt and then reading input must be repeated until a value greater than zero is input. The input value is then returned in $v0. The prompt string will need to be added to the .data segment.
4. getinput
$a0 address to store the first value
$a1 address to store the second value
This function will call the getpos function (above) two times. The result of the first call should be stored into memory at the location given in $a0 and the result of the second call should be stored into memory at the location given in $a1. As this function calls another function, the $ra must be stored on the stack at the beginning of the function. Also, the $ra and $sp must be restored at the end of the function.
General: Comment the beginning of your programs with your name, class ID, and assignment number.
Comment every instruction.
Comment each function. Describe which registers are used in the function and how they are used.
Submit your file with the complete program.
.data num1: .word 0 num2: .word 0 answer: .asciiz The product is # add other strings at this point as needed
.text .globl main
main:
jal getpos # get a positive number for the loop
addi $s0, $v0, 0 # save input value
repeat:
beq $s0, $0, end # while there are more repeats
lui $a0, 0x1001 # get address of first word
addiu $a1, $a0, 4 # get address of second word
jal getinput # call function to get input, store into addresses
lui $t0, 0x1001 # get address of first word
lw $a0, 0($t0) # get the first value from memory
lw $a1, 4($t0) # get the second value from memory
jal multiply # multiply the values, result in $v0
addi $a0, $v0, 0 # get value to print from $v0
lui $a1, 0x1001 # get start of data section
addi $a1, $a1, 8 # get start of the product output string
jal print # print results
addi $s0, $s0, -1 # decrement counter
j repeat # do it agin
end: ori $v0, $0, 10 # set command to stop program,
syscall # end program
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started