mips - 删除前导和尾随空白 mips?
问题描述
所以我想出了这个程序,它基本上编码了一个数字模式,并且数字必须在彼此之间加上标签,例如:
1 1 1
但最后一个“1”也有一个标签,我需要删除它。这就是我的代码用于制表符的样子:我在我的 for 循环结束之前使用它,所以它可以增加多少次。我真的不知道从哪里开始创建一个不使用选项卡打印最后一个数字的条件
li $v0, 11 #this is for tabbing the numbers
li $a0, 9
syscall
解决方案
您没有提供足够的代码来给出完整的答案,但是有几种方法可以省略打印最后一个选项卡:
如果您知道您正在处理最后一项,您可以跳过打印选项卡代码,例如,假设您在一个 while 循环中,您循环的 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
推荐阅读
- java - 从错误为-1的矩阵中获取错误的子矩阵
- python - 通过 Tornado 中附加到 IOLoop 的回调写回
- typescript - 如何使用 Typescript 在 Vue 中使用 Tailwind?
- java - 转换列表
- > 到地图
爪哇 8 - plotly - 如何使用袖扣在 plotly 中制作表格和饼图的子图
- wordpress - 获取 Wordpress 中自定义分类法的子分类法列表?
- python-2.x - 我正在尝试在类中定义的 __str__() 函数中调用多个参数(self、other),但我一直收到错误消息
- python-3.x - 如何在没有numpy的python中“将n * n矩阵转换为绝对矩阵”和“计算绝对矩阵的每一行总和”
- angular - 将引导主题从主题森林使用到 Angular 的最佳方法
- javascript - 任何人都可以访问 Dockerhub 公共存储库的项目代码库吗?