Null yang berada di akhir null-terminated string tidak perlu di hapus, karena dia berguna untuk membentuk null-terminated yang merupakan hasil dari pop.
. . . . .
# push each character onto the stack
pushl:
lbu $t0,str($t1) # get current char into
# a full word
beqz $t0,stend # null byte: end of string
subu $sp,$sp,4 # push the full word
sw $t0,($sp) # holding the char
addu $t1,1 # inc the index
j pushl # loop
# pop chars from stack back into the buffer
stend: li $t1,0 # index of first byte of str buffer
popl:
$t0,($sp) # pop a char off the stack
$sp,$sp,4
beqz $t0,done # null means empty stack
$t0,str($t1) # store at string[$t1]
addu $t1,1 # inc the index
j popl # loop
# print the reversed string
. . . . .
.data
str: .space 128 # character buffer
Quest 14: Fill in the blank
Tidak ada komentar:
Posting Komentar