Answered step by step
Verified Expert Solution
Link Copied!

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 3 results working on the ARMlite simulator. I'm encountering errors when I try to run my code. Could you please assist me in identifying and resolving these issues? this is my code :1|; Prompt for player's name
2| MOV R1, #promptName
3| STR R1,.WriteString
4| MOV R2, #nameStorage
5| STR R2,.ReadString
6| STR R2,.WriteString
7| MOV R6, #0x0A ; Load newline character
8| STRB R6,.WriteChar ; Output newline
9|; number of matchsticks
10|playerInput:
11| MOV R3, #promptMatchsticks
12| STR R3,.WriteString
13| LDR R4,.InputNum
14| CMP R4, #10 ; Compare input with lower than 10
15| BLT Error ; If input is less than 10, branch to Error
16| CMP R4, #100
17| BGT Error
18| B counting
19|Error:
20| MOV R8, #errorMsg
21| STR R8,.WriteString
22| B playerInput ; Repeat input process if there's an error
23|counting:
24| STR R4,.WriteUnsignedNum ; Output valid matchstick count
25| MOV R5, #outputName ; Print player's name
26| STR R5,.WriteString
27| STR R2,.WriteString
28| MOV R6, #outputMatchsticks ; Print number of matchsticks
29| STR R6,.WriteString
30| STR R4,.WriteUnsignedNum
31| MOV R8, #Player ; to show results on screen
32| MOV R9, #ThereAre
33| MOV R10, #remaining
34| STR R8,.WriteString
35| STR R2,.WriteString
36| STR R9,.WriteString
37| STR R4,.WriteUnsignedNum
38| STR R10,.WriteString
39|; Prompts the player to enter a number of matchsticks to remove
40|User:
41| STR R8,.WriteString
42| STR R2,.WriteString
43| MOV R11, #Promptq
44| STR R11,.WriteString
45|; Take user's input
46| LDR R12,.InputNum
47| CMP R12, #1 ; check if the input is between 1-7
48| BLT User
49| CMP R12, #7
50| BGT User
51| CMP R12, R4
52| BGT User
53| SUB R4, R4, R12 ; count the remaining matchsticks
54| STR R8,.WriteString
55| STR R2,.WriteString
56| STR R9,.WriteString
57| STR R4,.WriteUnsignedNum
58| STR R10,.WriteString
59|; Check if game is over
60| CMP R4, #0
61| BEQ endGame
62| B computerTurn
63|computerTurn:
64| MOV R1, #compTurnMsg
65| STR R1,.WriteString
66|; Generate random number for computer's turn
67| BL Random ; Call random number generator
68| AND R12, R0, #0x7 ; Mask to range 1-7
69| CMP R12, #0 ; Ensure it's at least 1
70| BNE validRand
71| ADD R12, R12, #1 ; If zero, make it 1
72|validRand:
73| CMP R12, R4 ; Check if random number exceeds remaining matchsticks
74| BLE validCompMove
75| MOV R12, R4 ; If so, use remaining matchsticks
76|validCompMove:
77| SUB R4, R4, R12 ; Computer removes matchsticks
78| STR R8,.WriteString
79| STR R2,.WriteString
80| STR R9,.WriteString
81| STR R4,.WriteUnsignedNum
82| STR R10,.WriteString
83|; Check if game is over
84| CMP R4, #0
85| BEQ endGame
86| B User
87|endGame:
88| CMP R4, #1
89| BEQ declareWinner
90| MOV R1, #drawMsg
91| STR R1,.WriteString
92| B playAgain
93|declareWinner:
94| CMP R12, R4
95| BNE playerWins
96| MOV R1, #loseMsg
97| STR R1,.WriteString
98| B playAgain
99|playerWins:
100| MOV R1, #winMsg
101| STR R1,.WriteString
102| B playAgain
103|playAgain:
104| MOV R1, #playAgainMsg
105| STR R1,.WriteString
106| LDR R12,.ReadChar
107| CMP R12, #'y'
108| BEQ playerInput
109| CMP R12, #'n'
110| BEQ endGameForReal
111| B playAgain
112|endGameForReal:
113| MOV SP, #gameover
114| STR SP,.WriteString
115| HALT
116|; Data
117|promptName: .asciz " Please enter your name: "
118|nameStorage: .block 128 ; Allocate 128 bytes for storing user's name
119|promptMatchsticks: .asciz "
How many matchsticks (10-100)?
"
120|errorMsg: .asciz "
Invalid Number Please Choose Again
"
121|outputName: .asciz "Player 1 is "
122|outputMatchsticks: .asciz "\Matchsticks: "
123|Player: .asciz "
Player "
124|ThereAre: .asciz ", there are "
125|remaining: .asciz "matchsticks remaining."
126|Promptq: .asciz ", how many do you want to remove (1-7)?"
127|gameover: .asciz "
Game Over"
128|compTurnMsg: .asciz "
Computer Player's turn
"
129|drawMsg: .asciz "It's a draw!
"
130|winMsg: .asciz "Player, YOU WIN!
"
131|loseMsg: .asciz "Player, YOU LOSE!
"
132|playAgainMsg: .asciz "Play again (y/n)?"
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

Appraise the concept and types of franchising.

Answered: 1 week ago

Question

At what level(s) was this OD intervention scoped?

Answered: 1 week ago