Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I did some work already but there are some errors I cant fix. al so I have no idea how to finish the multiple part,

I did some work already but there are some errors I cant fix. al so I have no idea how to finish the multiple part, so please help me to fix the errors(something like address), and do the multiple part. Thank you.

image text in transcribed

CODE BELOW:

.data

num1: .word 0

num2: .word 0

answer: .asciiz "The product is "

prompt: .asciiz "Please enter an integer: "

.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 again

end: ori $v0, $0, 10 # set command to stop program,

syscall # end program

print:

#allocate memory

addi $sp, $sp, -4

sw $ra, 0($sp)

#setup

addi $t7, $zero, 1

#print

addi $v0, $zero, 4

syscall

#new line

lui $a0, 0x1001

addi $a0, $a0, 36

syscall

#check condition

beq $t7, $a2, both

#deallocate

lw $ra 0($sp)

addi $sp, $sp, 4

#return to $ra

jr $ra

both: addi $v0, $zero, 1

addi $a0, $a1, 0

syscall

#deallocate

lw $ra 0($sp)

addi $sp, $sp, 4

#return to $ra

jr $ra

multiply:

#setup for integer multiple

getpos:

addi $sp, $sp, -12

sw $ra, 0($sp)

sw $a0, 4($sp)

sw $a1, 8($sp)

#loop until input is not 0

loopPos:

lui $a0, 0x1001

addi $a0, $a0, 38

addi $a2, $zero, 0

jal print

addi $v0, $zero, 5

syscall

bne $v0, $zero, endPos

j loopPos

endPos:

#restore registers and deallocate stack

lw $ra, 0($sp)

lw $a0, 4($sp)

lw $a1, 8($sp)

addi $sp, $sp, 12

jr $ra

getinput:

addi $sp, $sp, -4

sw $ra, 0($sp)

#call getpos

jal getpos

sw $v0, 0($a0)

jal getpos

sw $v0, 0($a1)

#restore and deallocate

lw $ra, 0($sp)

addi $sp, $sp, 4

jr $ra

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 $vO - 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 Sra must be stored on the stack at the beginning of the function Also, the Sra and Ssp must be restored at the end of the function

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions