【问题标题】:code is not reprinting board after initial print.. 2x2 Dots and Boxes game初始打印后代码不会重印板.. 2x2 点和框游戏
【发布时间】: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

【问题讨论】:

    标签: printing mips


    【解决方案1】:

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

    您似乎读取了一个 ASCII 代码,然后使用该 ASCII 代码作为索引读取了一个查找表。您应该为数字减去 ASCII 代码“0”,为字母“a”和“b”减去 ('a'-10)。注意 ASCII 码 '9' 和 ASCII 码 'a' 之间有一个间隔。

    您也可以将最后两个棋盘移动更改为 ':'';',因为它们在 ASCII 表中位于 '9' 旁边。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-25
      • 1970-01-01
      相关资源
      最近更新 更多