1

我在试图弄清楚如何在 Mips/Mars 架构中实现这一点时遇到了很多麻烦。

我正在制作一个战舰游戏并将棋盘存储为一个可以容纳 100 个整数的数组。

我需要遍历玩家的数组并将存储在每个“单元格”中的信息转换为图形数据,以便向用户显示棋盘。

我的麻烦源于这样一个事实,即向用户显示的字符是基于数组的每个单元格中的值。

如果值为 0(空) - 打印 '[ ]',如果 1(猜测和空)打印 - '[O]',如果 2(猜测和命中)打印 - '[X]'。

因此,当我遍历数组中的每个单元格时,我需要检查值并分支到适当的打印函数。

我的问题是,如果我分支到 print 语句,我如何跳回到分支语句所在的位置?

伪代码:

Looping through array, 'ArrayCell' = value at current array location
branch if equal ArrayCell, 0, print empty
branch if equal ArrayCell, 1, print miss
branch if equal ArrayCell, 2, print hit
increment array

print empty:
print then jump back to loop
print miss:
print then jump back to loop
print hit:
print then jump back to loop

打印后如何跳回分支语句以保留您在数组中的位置?

非常感谢!

4

2 回答 2

2

在运算符上方和标签的,和,increment array末尾放置一个标签。print emptyprint missprint hitj

例子:

   Looping through array, 'ArrayCell' = value at current array location
    branch if equal ArrayCell, 0, print empty
    branch if equal ArrayCell, 1, print miss
    branch if equal ArrayCell, 2, print hit

   LBL_Increment:
    increment array

   loop


    print empty:
    print
    j LBL_Increment
    print miss:
    print
    j LBL_Increment
    print hit:
    print
    j LBL_Increment
于 2011-12-05T02:46:07.943 回答
2

你真的应该为此使用函数调用

   Looping through array, 'ArrayCell' = value at current array location
    if equal ArrayCell, 0, JAL empty
    if equal ArrayCell, 1, JAL miss
    if equal ArrayCell, 2, JAL hit

   LBL_Increment:
    increment array

   loop


   empty:
    print " "
    JR $RA    // return to the instruction after the "JAL empty" instruction.
   miss:
    print "miss"
    JR $RA
   hit:
    print "hit"
    JR $RA
于 2011-12-06T20:24:58.030 回答