所以我想出了这个程序,该程序基本上对数字模式进行编码,并且数字之间必须在制表符之间进行制表,例如:
1 1 1
但最后一个“ 1”也有一个选项卡,我需要删除它。这就是我的代码看起来像是制表符:我在for循环结束之前使用它,因此它可以增加多少次。我真的不知道从哪里开始创建一个不显示带有选项卡的最后一个数字的条件
li $v0, 11 #this is for tabbing the numbers
li $a0, 9
syscall
您提供的代码不足以提供完整的答案,但是有几种方法可以省略最后一个标签的打印:
如果知道您正在处理最后一个项目,则可以跳过打印标签代码,例如假设您处于while循环中,当$t0
与$t1
不同时,您可以这样写:
while_loop:
# .... do something
beq $t0, $t1, skip
# your code to print tab
li $v0, 11 #this is for tabbing the numbers
li $a0, 9
syscall
skip:
# ... something else
bne $t0, $t1 while_loop % this is the condition to keep in the loop
如果打印标签是您在循环中所做的最后一件事,则可以简化一下:
while_loop:
# .... do something
beq $t0, $t1, while_loop
# your code to print tab
li $v0, 11 #this is for tabbing the numbers
li $a0, 9
syscall
b while_loop
另一种方法是在循环开始时打印选项卡,保存第一次迭代。如果您要遍历寄存器上的某些值并且知道某些初始值不会重复,则很有用。在此示例中,我将仅使用假定的备用寄存器:
li $t7, 0 # $t7 will only have 0 on the first iteration of the loop
while_loop:
beq $t7, $zero, skip
# your code to print tab
li $v0, 11 #this is for tabbing the numbers
li $a0, 9
syscall
skip:
li $t7, 1
% your remaining code here, which at some point goes to the while_loop