-2
.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.
我想創建打印出字符串並打印出反向的代碼。例如「Hello SirriS olleH」。我將如何更改此行打印出反向字符串
addi $t1, $a0, 21 # initialize loop counter to array end position
因此,它將初始化爲給定字符串的長度,而不是默認設置爲21。乾杯。