【发布时间】:2015-05-07 17:42:07
【问题描述】:
下面的代码是一个单人 2x2 点和盒子游戏。它首先打印板并等待用户输入。之后,它根本不打印板,而是成功地提出了问题。有什么见解吗?
.data
board: .ascii "\n\n . . . . 0 . 1 ."
.ascii "\n 2 3 4"
.ascii "\n . . . . 5 . 6 ."
.ascii "\n 7 8 9"
.asciiz "\n . . . . a . b .\n"
intro: .asciiz "\n One-Player 2x2 Dots-and-Boxes Game.\n"
prompt: .asciiz "\n Please Enter Next Move. (0..b): "
contPrompt: .asciiz "\n Would you like to Continue? (y/n): "
newGame: .asciiz "\n New Game? (y/n): "
wrongMove: .asciiz "\n---------Wrong Move-----------\n"
duplMove: .asciiz "\n--------Duplicate Move--------\n"
accept: .asciiz "y"
end: .asciiz "b"
buffer: .space 2
addr: .byte 6, 8, 33, 35, 37, 62, 64, 89, 91, 93, 118, 120
mark: .byte '-', '-', '|', '|', '|', '-', '-', '|', '|', '|', '-', '-'
.text
main:
la $a0, intro
li $v0, 4
syscall
j game
game:
# Printing the Board
la $a0, board
li $v0, 4
syscall
# Printing Prompt for Value
la $a0, prompt
li $v0, 4
syscall
# Reading Input Values
li $v0, 8
la $a0, buffer
li $a1, 2
syscall
# Checking for Validity
lb $t0, end
lb $t1, buffer
bgt $t1, $t0, error
lb $t0, buffer
j placePiece
placePiece:
# Placing Values
lb $t1, addr($t0)
lb $t2, mark($t0)
sb $t2, board($t1)
j printBoard
printBoard:
la $a0, board
li $v0, 4
syscall
j con
con:
la $a0, contPrompt
li $v0, 4
syscall
li $v0, 8
la $a0, buffer
li $a1, 2
syscall
lb $t0, accept
lb $t1, buffer
beq $t0, $t1, game
j exit
error:
la $a0, wrongMove
li $v0, 4
syscall
j game
exit:
la $a0, newGame
li $v0, 4
syscall
la $a0, buffer
li $a1, 2
li $v0, 8
syscall
lb $t0, accept
lb $t1, buffer
beq $t0, $t1, main
li $v0, 10
syscall
【问题讨论】: