.data
//* The welcome message. */
welcome_message: .asciz "Welcome to the guessing game! This has been created by Ahmed Imran naeem (6779560)"
/* The prompt for the user to enter their guess. */
guess_prompt: .asciz "Enter your guess: "
/* The message for when the user guesses correctly. */
correct_guess_message: .asciz "Congratulations! You guessed the correct number!"
/* The message for when the user's guess is too low. */
low_guess_message: .asciz "Your guess is too low. Try again."
/* The message for when the user's guess is too high. */
high_guess_message: .asciz "Your guess is too high. Try again."
/* The message for when the user runs out of guesses. */
no_more_guesses_message: .asciz "You have no more guesses. The secret number was %d."
/* The message for when the user enters ‘q’. */
quit_message: .asciz "Thanks for playing! Would you like to play again (y/n)? "
buffer: .space 10
secret_number: .word 42
noofguesses: .word 6
.text
.global main
/* The main function. */
main:
/* Display a welcome message. */
ldr r0, =welcome_message
bl puts
/* Load the secret number and number of guesses. */
ldr r1, =secret_number
ldr r2, =noofguesses
/* Start the guessing game loop. */
guess_loop:
/* Prompt the user to enter a guess. */
ldr r0, =guess_prompt
bl puts
/* Read the user's guess. */
bl read_int
/* Check if the user's guess is correct. */
cmp r0, r1
beq correct_guess
/* Check if the user's guess is too low. */
blt low_guess
/* Check if the user's guess is too high. */
bgt high_guess
/* The user entered an invalid number. */
invalid_guess:
/* Display an error message. */
ldr r0, =invalid_guess_message
bl puts
/* Go back to the top of the loop. */
b guess_loop
/* The user guessed the correct number! */
correct_guess:
/* Display a victory message. */
ldr r0, =correct_guess_message
bl puts
/* Exit the program. */
mov r7, #1
svc #0
/* The user's guess was too low. */
low_guess:
/* Display a message telling the user that their guess was too low. */
ldr r0, =low_guess_message
bl puts
/* Decrement the number of guesses. */
sub r2, r2, #1
/* Check if the user has no more guesses. */
cmp r2, #0
beq no_more_guesses
/* Go back to the top of the loop. */
b guess_loop
/* The user's guess was too high. */
high_guess:
/* Display a message telling the user that their guess was too high. */
ldr r0, =high_guess_message
bl puts
/* Decrement the number of guesses. */
sub r2, r2, #1
/* Check if the user has no more guesses. */
cmp r2, #0
beq no_more_guesses
/* Go back to the top of the loop. */
b guess_loop
/* The user ran out of guesses. */
no_more_guesses:
/* Display a message telling the user that they have no more guesses. */
ldr r0, =no_more_guesses_message
bl puts
/* Exit the program. */
mov r7, #1
svc #0
/* The function to read an integer from the terminal. */
read_int:
/* Save the registers that we will be using. */
push {r0, r1, r2}
/* Read an integer from the terminal. */
mov r0, #0
ldr r1, =buffer
mov r2, #10
svc #0
/* Check if the integer was read successfully. */
cmp r0, #0
beq error
/* Convert the integer to a number. */
mov r0, r1
bl atoi
/* Return the number. */
pop {r0, r1, r2}
bx lr
error:
/* Display an error message. */
ldr r0, =invalid_guess_message
bl puts
/* Go back to the top of the loop. */
b guess_loop
the code should do the following : Displays a welcome message with my name Tracks the number of guesses and displays it Prompts to the player if the guessed number is lower or greater than the secret number
Examines whether the input is a valid number. If an invalid number is entered (e.g., entering an alphabet letter, except ‘q’, or the input number is out of the range), ask the player to input again. The player does not lose a chance
Informs player when he or she guesses a number that has already been guessed; player does not lose a chance.
The game ends with player victory if the correct number is guessed. The game ends with player defeat if the player runs out of chances. The game ends if the player enters ‘q’ (quit) without completing the game. When the game ends, the secret number is revealed, and the player can choose to have another round.
I have tried debugging the code but it keeps on giving segmentation errors.Can anyone help me fix it
//* The welcome message. */
comment describingwelcome_message: .asciz "Welcome to the guessing ....