删除前导和尾部空白mips

  • 本文关键字:空白 mips 尾部 删除 mips
  • 更新时间 :
  • 英文 :


所以我想出了这个程序,它基本上编码一个数字模式,并且数字必须在彼此之间进行制表,例如:

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

最新更新