MIPS:取一个字母的地址,确定该字母的上限版本,然后将其存储回同一内存位置
因此,基本上,给定一个字符串,我们将将小写的任何事件转换为大写,并将大写的地址存储到小写地址的相同内存位置。我在这种MIPS组装语言中仍然是新手,如果我这样做的话,我仍然非常困惑。另外,为什么我们必须为字符串分配空间?我尝试将其删除,而IT输出相同?所以我很困惑分配空间与不分配任何空间有何不同?到目前为止,这是我的代码:
STR_str: .asciiz "Test String"
to_upper:
li $t0, 0 # Set t0 = 0
upper_loop:
lb $t1, STR_str($t0) # Load byte from 't0'th position into $t1
beq $t1, 0, exit # If it ends then exits the loop
blt $t1, 'a', case # If less than a, exit
bgt $t1, 'z', case # If greater than z, exit
sub $t1, $t1, 32 # If lowercase, then subtract 32
sb $t1, STR_str($t0) # Store it back to 't0'th position in the string
case:
addi $t0, $t0, 1 # if not lower, then increment $t0 and continue
j upper_loop
exit:
jr $ra # Return to caller
So basically, given a string, we will convert any occurences of lowercase to uppercase and store the address of the uppercase to the same memory location of the lowercase address. Im still new in this MIPS assembly language and very confused if im doing this right. Also why do we have to allocate space for the string? i tried removing it and the it outputs the same? so im confused how does allocating space differs from not allocating any space? Here is my code so far:
STR_str: .asciiz "Test String"
to_upper:
li $t0, 0 # Set t0 = 0
upper_loop:
lb $t1, STR_str($t0) # Load byte from 't0'th position into $t1
beq $t1, 0, exit # If it ends then exits the loop
blt $t1, 'a', case # If less than a, exit
bgt $t1, 'z', case # If greater than z, exit
sub $t1, $t1, 32 # If lowercase, then subtract 32
sb $t1, STR_str($t0) # Store it back to 't0'th position in the string
case:
addi $t0, $t0, 1 # if not lower, then increment $t0 and continue
j upper_loop
exit:
jr $ra # Return to caller
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论