Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

.data #declare the strings prompt1: .asciiz Enter an integer: message1: .asciiz The solution is: next_line: .asciiz .text ############################################# # Procedure main

.data

#declare the strings

prompt1: .asciiz "Enter an integer: "

message1: .asciiz "The solution is: "

next_line: .asciiz " "

.text

#############################################

# Procedure main

# Description:

# parameters:

# return value: $v0

# registers to be used:

#############################################

main:

#Print "Enter an integer: "

la $a0, prompt1

li $v0, 4

syscall

#read the integer input from the user

#$v0 = user input

li $v0, 5

syscall

#move the input value to $a0

move $a0, $v0

#Adjust sp/ store ra

addi $sp, $sp, -4

sw $ra, 0($sp)

#call the function

#jump and link function1 and $a0 is passed as parameter

jal function1

#Adjust sp/ load ra

lw $ra, 0($sp)

addi $sp, $sp, 4

#save return value from function1

move $v1, $v0

#Print "The solution is:"

la $a0, message1

li $v0, 4

syscall

#print the results

move $a0, $v1

li $v0, 1

syscall

#print new line

la $a0, next_line

li $v0, 4

syscall

#end program

li $v0, 10

syscall

################################################

# Procedure function1

# Description: The function1 is a recursive procedure

# parameters: $a0

# return value: $v0

# registers to be used:$v1,$s1,$t0,$t4,$v1,$zero

################################################

function1:

#Save $ra, $a0, $s1, and $v1 on the stack

addi $sp, $sp, -16

sw $ra, 0($sp)

sw $a0, 4($sp)

sw $v1, 8($sp)

sw $s1, 12($sp)

#check if $a0

#otherwise go to else

slti $t0, $a0, 5

beq $t0, $zero, else

mul $a0,$a0,2#find 2*n

move $v0, $a0 #return 2*n

#jump to return label

j return

else:

#store the input value(n) in $v1

move $v1, $a0

#find ($a0 - 2)

sub $a0, $a0, 2

jal function1 #int function1($a0 - 2)

mul $s1,$v1,$v0#$s1=(n) * function1 ($a0 - 2)

#find ($a0 - 3)

sub $a0, $a0, 1

#int function1 ($a0 - 3)

jal function1

#$t4 = function1 ($a0 - 3)+n

add $t4,$v0,$v1

#$v0=(n) * function1 ($a0 - 2)+function1 ($a0 - 3)+n

add $v0, $s1,$t4

return:

#load the $ra, $a0, $s1, and $v1 from the stack

lw $s1, 12 ($sp)

lw $v1, 8 ($sp)

lw $a0, 4 ($sp)

lw $ra, 0 ($sp)

addi $sp, $sp, 16

#return to main function

jr $ra

I need this mips assembly code to be edited to this code below:

image text in transcribedimage text in transcribedThe c code above is just for reference. I need this all in mips coding. I provided a template for the code i need above. I need the solution to out put -208 when 9 is entered. Please execute in qtspim

// The function1 is a recursive procedure/function defined by: // function1(n) = (3*n) - 7 if n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions