In: Computer Science
Create a SPIM program that asks the user for a character string and a number. Repeatedly display the string on the console for the number of times specified by the user.
Format your assembly program to make it easier to read by including appropriate comments and formatting using appropriate white space. When ending your program call system call code 10.
Example Output:
Please enter a string: I will not repeat myself
Please enter the integer number of times to repeat: 5
I will not repeat myself I will not repeat myself I will not repeat myself I will not repeat myself
***Please upvote or thumbsup if you liked the answer***
Screenshot of the SPIM code:-
Screenshot of Output:-
SPIM code to copy:-
.data
buffer: .space 50
str: .asciiz "Please enter a string:"
prompt: .asciiz "Please enter the integer number of
times to repeat: "
.text
main:
la $a0, str # Prompt for inputting string
li $v0, 4
syscall
li $v0, 8 # load the string input
la $a0, buffer # load byte space into address
li $a1, 50 # allot the byte space for string
move $t0, $a0
syscall
# initialize
li $s0, 10
# prompt for integer input
li $v0, 4
la $a0, prompt
syscall
# read in the integer value
li $v0, 5
syscall
move $s0, $v0
loop:
# print str
la $a0, buffer
move $a0, $t0
li $v0, 4 # print string
syscall
# decrement loop counter and branch if positive and
non-zero
sub $s0, $s0, 1
bne $zero,$s0, loop
li $v0, 10 # end program with system code 10
syscall