为什么寄存器 $a1 在 Mips 架构中总是打印 0
Why does register $a1 always prints a 0 in Mips architecture
我在做作业之前测试了一些 mips 程序集,我试图检查字符串中的字符是否在字母表中。我想出了一个让它工作的 hacky 方法,但我更希望有人能向我解释为什么我的代码每次都打印出 0。
.data
str1: .asciiz "allo"
str2: .asciiz "a1b2"
true: .word 1
false: .word 0
.文本
main:
la $a0, str1
move $t0, $a0
loop:
lb $a0, 0($t0) # pointer on array
beqz $a0, end # Checks for end of array
blt $a0, 97, non_alpha # Is character in the alphabet
bgt $a0, 122, non_alpha
addi $t0, $t0, 1 # Increment pointer
j loop
end:
li $v0, 1
lw $a1, true # !!! This line is the issue, why $a1 print a 0
syscall # When I change it to $a0 it prints out 1 as it
# should
# end program
li $v0, 10
syscall
non_alpha: "Did not touch this yet, ignore this"
您正在系统调用的服务($v0 = 1 = print_integer)仅打印出 $a0 中的值。对 $a1 的任何更改都不会影响结果,因为它与服务完全无关。
有关每个服务的功能及其使用的参数的更多信息,请参阅:https://courses.missouristate.edu/KenVollmar/mars/Help/SyscallHelp.html
我在做作业之前测试了一些 mips 程序集,我试图检查字符串中的字符是否在字母表中。我想出了一个让它工作的 hacky 方法,但我更希望有人能向我解释为什么我的代码每次都打印出 0。
.data
str1: .asciiz "allo"
str2: .asciiz "a1b2"
true: .word 1
false: .word 0
.文本
main:
la $a0, str1
move $t0, $a0
loop:
lb $a0, 0($t0) # pointer on array
beqz $a0, end # Checks for end of array
blt $a0, 97, non_alpha # Is character in the alphabet
bgt $a0, 122, non_alpha
addi $t0, $t0, 1 # Increment pointer
j loop
end:
li $v0, 1
lw $a1, true # !!! This line is the issue, why $a1 print a 0
syscall # When I change it to $a0 it prints out 1 as it
# should
# end program
li $v0, 10
syscall
non_alpha: "Did not touch this yet, ignore this"
您正在系统调用的服务($v0 = 1 = print_integer)仅打印出 $a0 中的值。对 $a1 的任何更改都不会影响结果,因为它与服务完全无关。
有关每个服务的功能及其使用的参数的更多信息,请参阅:https://courses.missouristate.edu/KenVollmar/mars/Help/SyscallHelp.html