Stage 3 avatar
7 months ago
3.8 kB
  1|//--Before Game Start--
  2|//Get player name
  3|      MOV R2, #msg1
  4|      STR R2, .WriteString
  5|      MOV R10, #name
  6|      STR R10, .ReadString
  7|//Get the total matchsticks of the game
  9|      MOV R2, #msg2
 10|      STR R2, .WriteString
 11|      MOV R11, #num
 12|      LDR R11, .InputNum
 13|      CMP R11, #5
 14|      BLT TotalStick
 15|      CMP R11, #100
 16|      BGT TotalStick
 17|      MOV R9, R11
 18|//--Game Start--
 20|      MOV R2, #msg0
 21|      STR R2, .WriteString
 22|      MOV R11, R9       //Reset the number of matchsticks everytime you play
 23|//How many matchsticks are left
 25|      MOV R2, #msg3
 26|      STR R2, .WriteString
 27|      STR R10, .WriteString
 28|      MOV R2, #msg4
 29|      STR R2, .WriteString
 30|      STR R11, .WriteUnsignedNum
 31|      MOV R2, #msg5
 32|      STR R2, .WriteString
 33|//--Human Player's Turn--
 35|      MOV R2, #msg3
 36|      STR R2, .WriteString
 37|      STR R10, .WriteString
 38|      MOV R3, #msg6
 39|      STR R3, .WriteString
 40|      LDR R4, .InputNum
 41|      CMP R4, #1
 42|      BLT PlayerRemove
 43|      CMP R4, #3
 44|      BGT PlayerRemove
 45|      CMP R4, R11
 46|      BEQ Draw          //Check for draw
 47|      BGT PlayerRemove
 48|      SUB R11, R11, R4
 49|//Check for Human Player win
 50|      CMP R11, #1
 51|      BEQ HumanWin
 52|//--Computer Player's Turn--
 54|      LDR R5, .Random
 55|      AND R5, R5, #3
 56|      CMP R5, #0
 57|      BEQ CompRemove
 58|      CMP R5, R11
 59|      BGT CompRemove
 60|      BEQ Draw          //Check for draw
 62|      STR R5, .WriteUnsignedNum
 63|      MOV R2, #msg8
 64|      STR R2, .WriteString
 65|      SUB R11, R11, R5
 66|//Check for Computer Player win
 67|      CMP R11, #1
 68|      BEQ ComputerWin
 69|//--Loop back until the game end--
 70|      B Loop
 71|//--Game result--
 72|//Human victory
 74|      MOV R2, #msg3
 75|      STR R2, .WriteString
 76|      STR R10, .WriteString
 77|      MOV R2, #msg10
 78|      STR R2, .WriteString
 79|      B Replay
 80|//Computer victory
 82|      MOV R2, #msg3
 83|      STR R2, .WriteString
 84|      STR R10, .WriteString
 85|      MOV R2, #msg11
 86|      STR R2, .WriteString
 87|      B Replay
 90|      MOV R2, #msg12
 91|      STR R2, .WriteString
 92|      B Replay
 93|//--Replay the game or end it--
 95|      MOV R2, #msg13
 96|      STR R2, .WriteString
 97|      MOV R6, #des
 98|      STR R6, .ReadString
 99|      LDRB R6, [R6+#0]
100|      CMP R6, #121
101|      BEQ GameStart
102|      CMP R6, #110
103|      BNE Replay
104|      HALT
105|//R10 is for Player name
106|//R11 is for the current matchsticks
107|//R2 is for printing messages
108|//R4 is for the matchsticks removed of the Human Player
109|//R5 is for the matchsticks removed of the Computer Player
110|//R6 is for the Player's decision to replay or not
111|//R9 is for the initial matchsticks
112|name: .BLOCK 128
113|num:  .Word
114|des:  .Word
115|msg0: .ASCIZ "Game Start! \n"
116|msg1: .ASCIZ "Enter your name: \n"
117|msg2: .ASCIZ "How many matchsticks (5-100)? \n"
118|msg3: .ASCIZ "Player "
119|msg4: .ASCIZ ", there are "
120|msg5: .ASCIZ "matchsticks left. \n"
121|msg6: .ASCIZ ", how many do you want to remove (1-3)? \n"
122|msg7: .ASCIZ "Game Over! \n"
123|msg8: .ASCIZ " was taken by Computer Player. \n"
124|msg9: .ASCIZ " remaining \n"
125|msg10: .ASCIZ ", YOU WIN! :> \n"
126|msg11: .ASCIZ ", YOU LOSE! :< \n"
127|msg12: .ASCIZ "\nIt's a draw!"
128|msg13: .ASCIZ "\nPlay again (y/n)? \n"