Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the attached template to implement PrintForward which is to print a passed in string one character at time with spaces between each character RECURSIVELY.

Use the attached template to implement PrintForward which is to print a passed in string one character at time with spaces between each character RECURSIVELY. Assembly Language

Reference the CountDown sample code. This is quite similar; but not identical. Think and change it as appropriate.

Note that recursion is NOT the same as implementing a for loop or a dowhile loop

You will get ZERO points for implementing a loop regardless of what other code you have. The implementation MUST be a recursion.

TEMPLATE BELOW

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

.data

theString: .asciiz "Print one char at a time with SPACES"

CR: .byte '

SPACE: .byte 0x20

.code

.globl main

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

# Print2CR

# cosmetic

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

Print2CR:

lb $a0,CR

syscall $print_char

lb $a0,CR

syscall $print_char

jr $ra

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

# PrintForward

#

# Input: $a1 = address of string to print RECURSIVELY ONE CHARACTER

# AT A TIME FORWARD WITH A SPACE between each.

#

# Hint - Leverage the countdown sample code that was posted

#

# Note that recursion is NOT the same as implementing a for loop or a dowhile loop

# You will get ZERO points for implementing a loop. The implementation MUST be a recursion.

#

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

PrintForward:

addi $sp,$sp,-8 # make room on the stack for our variables

sw $ra,4($sp) # save our return address

sw $a1,0($sp) # save our original $a0

# YOUR CODE HERE

# NOTE THAT THE INPUT PARAMETER FOR THIS IMPLEMENTATION

# IS PASSED IN REGISTER $A1

donePF: lw $a1,0($sp) # restore our original $a1

lw $ra,4($sp) # restore our return address

addi $sp,$sp,8 # free the room we have taken on the stack

jr $ra

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

# Main

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

main:

jal Print2CR # cosmetic - just for improved UI

la $a1,theString # pass the string address as a parameter to the function

jal PrintForward # print it forward one char at a time without loops

jal Print2CR # cosmetic - just for improved UI

syscall $exit

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