Assembly MIPS 2D数组作为矩阵打印

Assembly MIPS 2D数组作为矩阵打印,assembly,mips,multidimensional-array,Assembly,Mips,Multidimensional Array,我有一个关于MIPS汇编中的数组的问题。 我的2D数组由大型1D数组表示(例如,2x2数组只是一个带有4个“单元格”的1D数组) 但是,当我尝试将2D数组打印为矩阵时,会遇到问题。我的意思是,如果我有一个数组:3x3和数字1 2 3 4 5 6 7 8 9,我想把它打印在3行上,每行3个整数,而不是一行或9行上 ` add $t3,$0,$0 # t3 = counter la $s1,tableau #s1 = addresse of the begining of the array AFF

我有一个关于MIPS汇编中的数组的问题。 我的2D数组由大型1D数组表示(例如,2x2数组只是一个带有4个“单元格”的1D数组)

但是,当我尝试将2D数组打印为矩阵时,会遇到问题。我的意思是,如果我有一个数组:3x3和数字1 2 3 4 5 6 7 8 9,我想把它打印在3行上,每行3个整数,而不是一行或9行上

`
add $t3,$0,$0 # t3 = counter
la $s1,tableau #s1 = addresse of the begining of the array
AFFICHE_MAT:    
beq $t3,$t2, FIN #t3 = counter, t2 = total number of elements for the matrix
beq $t3,$t1 NEW_LINE #if we are at the end of a line, we'd like to print \n
lw $a0,($s1) #print the next number of the 2D array
addi $v0,$0,1
syscall
la $a0,intervalle #we print ' ' between all numbers
addi $v0,$0,4
syscall
addi $s1,$s1,4
addi $t3,$t3,1
j AFFICHE_MAT
新行:
洛杉矶$a0,荷兰
addi$v0$0,4
系统调用
阿菲舍尔酒店
鳍:
addi$v0$0,10
系统调用

问题是,当我进行测试时,我是否在一行的末尾

beq $t3,$t1 NEW_LINE #if we are at the end of a line, we'd like to print \n
我跳到新线,然后从新线跳到阿菲什垫
新行:
洛杉矶$a0,荷兰
addi$v0$0,4
系统调用
j粘贴垫

但在阿菲舍马,我失去了计数器的价值

如果我不测试我是否在一行的末尾,我将打印整个二维数组,但只打印一行

你有什么建议我如何解决这个问题? 先谢谢你
George

我认为您遇到的问题是,在打印新行后,您返回到测试是否应打印新行的部分,该部分将再次为真,因此您将结束打印无限多的新行

您可以通过在检查是否必须打印换行符之后跳回指令来修复它

在新的行之后添加标签

AFFICHE_MAT:    
  beq $t3,$t2, FIN #t3 = counter, t2 = total number of elements for the matrix
  beq $t3,$t1 NEW_LINE #if we are at the end of a line, we'd like to print \n
AFTER_NEW_LINE:
  lw $a0,($s1) #print the next number of the 2D array
在新的子程序中,用

  j AFTER_NEW_LINE

是的,这就是问题所在。打印符号后,我没有跳到正确的位置。现在程序可以很好地打印矩阵了

谢谢大家!