.data
str: .asciiz "Hello Sir"
.text
la $a0, str # load the address of the string
addi $t0, $a0, 0 # starting address of array
#TODO: find length of string, it's zero terminated, so loop until a zero
strLen: #getting length of string
lb $t1, str($t2) #loading value
add $t2, $t2, 1
bne $t1, $zero, strLen
sub $t2, $t2, 1
li $v0, 11 #load imediate - print low-level byte
addi $t1, $a0, 21 # initialize loop counter to array end position
loop: lb $a0, 0($t0) # load a single character
li $v0, 11 # specify print character service 3
syscall # print
addi $t0, $t0, 1 # add 1 to the loop index
blt $t0, $t1, loop # continue if not at string length
Loop:
sub $t2, $t2, 1
la $t1, str($t2) #loading value
lb $a0, ($t1)
syscall
bnez $t2, Loop
li $v0, 10 # system call for exit
syscall # we are out of here.
我想创建将打印出字符串并打印出其反向的代码。例如“你好 SirriS olleH”。我将如何更改此行
addi $t1, $a0, 21 # initialize loop counter to array end position
以便它初始化为给定字符串的长度,而不是默认设置为 21。干杯。