该程序的目的是对用户提供的字符串进行base64编码,然后输出新的编码字符串。
编码是通过从原始字符串中收集3个字符(每个字符为8位)然后将它们分成4个字符,每个字符串为6位来完成的。
如何正确访问和操作用户输入的字符串?
目前第一次迭代带来了正确的输出,但是第二次迭代总是给t2值#34; 0",无论输入如何,都会使输出A停止程序;这两个都是错的。
.data
sentence: .space 64
prompt: .asciiz "Enter the string: "
ASC: .byte 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
.text
.globl main
main:
la $s0, ASC
la $a0, prompt #ask for string
li $v0, 4
syscall
li $v0, 8 #take string
la $a0, sentence #load byte space into address
li $a1, 64 #max number of bytes
syscall
la $t0, sentence
lb $t2, 0($t0) #to load the first 8 bits
j read_ASC
read_ASC: beq $t2, $0, exit
lb $t2, 0($t0) #to load the first 8 bits
andi $a0, $t2, 63 #takes first 6 bits of string
#srl $t0, $t0, 6 #removes the 6 bits we just took
sub $t0, $t0, $t2 #removes the char we just took
addu $t1, $a0, $s0 #s0 being the base of the table, $a0 being the offset
#lbu $a0, ASC($a0)
lbu $a0, 0($t1) #sees value of the 6 bits from string to retrieve encoded value from table
li $v0, 11 #prints the new encoded char
syscall
j read_ASC
exit: li $v0, 10 #end
syscall