## This is the modulized wheelfortune program ## I provide you the main function
ID: 3536100 • Letter: #
Question
## This is the modulized wheelfortune program
## I provide you the main function and data section
## you need write the following functions
## the 5 functions below right under .data need to be made
## If you need to modify the main function for them to call correctly
## please do so but i think it is all set, Mars/QtSpim compatability
## Keep the indentation clean and readable, no bogus answeres
## if you have questions use comments not answers to ask goodluck'
## when the program runs successfully 5/5 stars will be given
.data
## initialize the puzzle display as something liks * **** **********
generate_stars:
## is match function. Return 1 if two given strings are match, return 0 otherwise
is_match:
## return the argument itself if it is NOT a lower case letter
## otherwise, return its upper case
toupper:
## check if the given char is in the phrase and count how many
## there are three arguments: the given char ($a0), the given phrase (address in $a1),
## and the cover of the phrase (address in $a2)
## the cover of the phrase will be change accordingly, i.e. reveal the correctly guessed char
check_char:
## alltoupper
## convert a sentence to all upper case
## assume that the sentence address is stored in $a0
alltoupper:
menu_data: .ascii " ********************* "
.ascii " Menu "
.ascii " 1. Guess a letter "
.ascii " 2. Guess the phrase "
.ascii " 3. View answer "
.ascii "********************* "
.byte 0
prompt1: .asciiz "Enter your choice: "
prompt2: .asciiz "Enter your guess: "
message1: .asciiz " Congratulations! Your guess was correct!"
message2: .asciiz " Sorry, your guess was wrong."
message3: .asciiz "There is(are) "
message4: .asciiz " match(es)"
message5: .asciiz " Game Over!"
phrase: .asciiz "I LOVE PROGRAMMING "
string_space: .space 64 # set aside 1024 bytes for the string.
cover: .space 64
.text
main:
la $a0, phrase
la $a1, cover
jal generate_stars #inlitialize the puzzle to something like * **** ********
loop: la $a0, menu_data #print menu
li $v0, 4
syscall
la $a0, cover
li $v0, 4
syscall
la $a0, prompt1 #ask user enter choice
li $v0, 4
syscall #print a string whose address is in $a0
li $v0, 5 #read an int
syscall
add $s0, $v0, $zero #$s0 hold the input
li $t0, 1
beq $s0, $t0, case1
li $t0, 2
beq $s0, $t0, case2
li $t0, 3
beq $s0, $t0, case3
j loop
case1:
la $a0, prompt2 #prompt user to input a char
li $v0, 4
syscall
li $v0, 12 #get user's input
syscall
move $a0, $v0
la $a1, phrase
la $a2, cover
jal check_char # check the char answer
move $t0, $v0 #$t0 hold the result
beq $t0, $zero, no_match_message
la $a0, message1
li $v0, 4
syscall
j end_case1
no_match_message:
la $a0, message2
li $v0, 4
syscall
end_case1:
la $a0, message3
li $v0, 4
syscall
move $a0, $t0
li $v0, 1
syscall
la $a0, message4
li $v0, 4
syscall
j loop
case2: la $a0, prompt2
li $v0, 4
syscall #print a string whose address is in $a0
la $a0, string_space #string address
li $a1, 64 #string length
li $v0, 8 #read a string
syscall
jal alltoupper #convert input to all uppercase, string_space is already in $a0
la $a0, string_space
la $a1, phrase
jal is_match
beq $v0, $zero, not_match
la $a0, message1
li $v0, 4
syscall
j exit #match whole sentence, display message and game over
not_match:
la $a0, message2
li $v0, 4
syscall
j exit #not match whole sentence, display message and game over
case3:
la $a0, phrase
li $v0, 4
syscall
exit: li $v0, 10
syscall
Explanation / Answer
ANSWER
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.