Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need some help modifying and fixing my code so that I can get Stage 3 results working on the ARMlite simulator. I ' m
I need some help modifying and fixing my code so that I can get Stage results working on the ARMlite simulator. Im encountering errors when I try to run my code. Could you please assist me in identifying and resolving these issues? this is my code :; Prompt for player's name
MOV R #promptName
STR RWriteString
MOV R #nameStorage
STR RReadString
STR RWriteString
MOV R #xA ; Load newline character
STRB RWriteChar ; Output newline
; number of matchsticks
playerInput:
MOV R #promptMatchsticks
STR RWriteString
LDR RInputNum
CMP R # ; Compare input with lower than
BLT Error ; If input is less than branch to Error
CMP R #
BGT Error
B counting
Error:
MOV R #errorMsg
STR RWriteString
B playerInput ; Repeat input process if there's an error
counting:
STR RWriteUnsignedNum ; Output valid matchstick count
MOV R #outputName ; Print player's name
STR RWriteString
STR RWriteString
MOV R #outputMatchsticks ; Print number of matchsticks
STR RWriteString
STR RWriteUnsignedNum
MOV R #Player ; to show results on screen
MOV R #ThereAre
MOV R #remaining
STR RWriteString
STR RWriteString
STR RWriteString
STR RWriteUnsignedNum
STR RWriteString
; Prompts the player to enter a number of matchsticks to remove
User:
STR RWriteString
STR RWriteString
MOV R #Promptq
STR RWriteString
; Take user's input
LDR RInputNum
CMP R # ; check if the input is between
BLT User
CMP R #
BGT User
CMP R R
BGT User
SUB R R R ; count the remaining matchsticks
STR RWriteString
STR RWriteString
STR RWriteString
STR RWriteUnsignedNum
STR RWriteString
; Check if game is over
CMP R #
BEQ endGame
B computerTurn
computerTurn:
MOV R #compTurnMsg
STR RWriteString
; Generate random number for computer's turn
BL Random ; Call random number generator
AND R R #x ; Mask to range
CMP R # ; Ensure it's at least
BNE validRand
ADD R R # ; If zero, make it
validRand:
CMP R R ; Check if random number exceeds remaining matchsticks
BLE validCompMove
MOV R R ; If so use remaining matchsticks
validCompMove:
SUB R R R ; Computer removes matchsticks
STR RWriteString
STR RWriteString
STR RWriteString
STR RWriteUnsignedNum
STR RWriteString
; Check if game is over
CMP R #
BEQ endGame
B User
endGame:
CMP R #
BEQ declareWinner
MOV R #drawMsg
STR RWriteString
B playAgain
declareWinner:
CMP R R
BNE playerWins
MOV R #loseMsg
STR RWriteString
B playAgain
playerWins:
MOV R #winMsg
STR RWriteString
B playAgain
playAgain:
MOV R #playAgainMsg
STR RWriteString
LDR RReadChar
CMP R #y
BEQ playerInput
CMP R #n
BEQ endGameForReal
B playAgain
endGameForReal:
MOV SP #gameover
STR SPWriteString
HALT
; Data
promptName: asciz Please enter your name:
nameStorage: block ; Allocate bytes for storing user's name
promptMatchsticks: asciz
How many matchsticks
errorMsg: asciz
Invalid Number Please Choose Again
outputName: asciz "Player is
outputMatchsticks: asciz Matchsticks:
Player: asciz
Player
ThereAre: asciz there are
remaining: asciz "matchsticks remaining."
Promptq: asciz how many do you want to remove
gameover: asciz
Game Over"
compTurnMsg: asciz
Computer Player's turn
drawMsg: asciz "It's a draw!
winMsg: asciz "Player, YOU WIN!
loseMsg: asciz "Player, YOU LOSE!
playAgainMsg: asciz "Play again yn
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started