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 MAKE SURE NOT TO USE PSUEDOCODE OR ANY VERSION OF THE MULT INSTRUCTION
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. You can assume that both arguments are values 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 the 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.
Sample Input and output:
Enter a positive number -2
Enter a positive number 2
Enter a positive number 7
Enter a positive number 1
The product is 7
Enter a positive number -3
Enter a positive number -1
Enter a positive number 3
Enter a positive number 0
Enter a positive number 6
The product is 18
code to be included:
.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 counte
j repeat # do it again
end: ori $v0, $0, 10 # set command to stop program, syscall # end program
syscall
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