[英]Can't understand small part of a MIPS assembly instruction
This program prints the ASCII characters from 0 to Z. The output is 该程序打印从0到Z的ASCII字符。输出为
0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ
The question is how to change the program so it prints every third ASCII character. 问题是如何更改程序,使其每三个ASCII字符打印一次。 So that the output must look like this 这样输出必须看起来像这样
0369<?BEHKNQTWZ]
When I change the constant in addi $s0,$s0,1
to addi $s0,$s0,3
the output is a lot of ASCII characters and it's like an infinite loop. 当我将addi $s0,$s0,1
的常量更改addi $s0,$s0,1
addi $s0,$s0,3
,输出是很多ASCII字符,就像一个无限循环。
.text
main:
li $s0,0x30
loop:
move $a0,$s0
li $v0,11
syscall
addi $s0,$s0,1 # what happens if the constant is changed?
li $t0,0x5b
bne $s0,$t0,loop
nop
stop: j stop
nop
I don't understand the reason behind why the program goes crazy when I change that constant. 我不了解更改常数后程序变得疯狂的原因。
I wrote my own code as shown below which works fine and do the job but I want to understand the code above because it's an assignment. 我编写了自己的代码,如下所示,该代码可以正常工作并且可以完成工作,但是我想了解上面的代码,因为这是一项任务。
.data
.text
main:
li $s0,0x30
for:
addi $a0,$s0,0
li $v0,11
syscall
li $t0,0x5a
bgt $s0,$t0, done
addi $s0,$s0,3
j for
done:
The number of characters this prints (43) is not divisible by 3, so by adding 3 each time, your loop goes past its exit condition (s0 == t0). 此打印的字符数(43)不能被3整除,因此,每次加3,循环就会超出退出条件(s0 == t0)。 Try changing the bne
to blt
. 尝试将bne
更改为blt
。
Your own code does exactly the same, except that it jumps out of the loop when it goes past the end point, rather than back to the top unless it has. 您自己的代码执行的操作完全相同,不同之处在于, 当它经过终点时会跳出循环,而不是返回到顶部( 除非有回跳)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.