初始打印后代码未重新打印板.. 2x2 点和框游戏

code is not reprinting board after initial print.. 2x2 Dots and Boxes game

下面的代码是一个单人 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

我认为你的问题是你在板的开头写了'\0'。

您似乎读取了一个 ASCII 码,然后使用该 ASCII 码作为索引进行了查找 table。您应该为数字减去 ASCII 码“0”,并为字母 'a' 和 'b' 减去 ('a'-10)。请注意 ASCII 码 '9' 和 ASCII 码 'a'.

之间有一个间隙

您也可以将最后两个棋盘移动更改为 ':'';',因为它们在 ASCII table.[=20= 中位于 '9' 旁边]

因此,假设您将 'a' 更改为 ':',将 'b' 更改为 ';',您需要在跳转到 [=19= 之前减去 '0' ],例如:

  lb $t0, buffer
  subiu $t0, $t0, '0'   # convert to array index
  j placePiece