I have a MIPS code that gathers an input from a user and converts it into a different string with a key inside an array. The problem is that the keys are just numbers 2,3,4... but when mips reads this, it assumes its the Dec code for what it means in ascii. How do I make sure the actual number 4 is printed when it reads '$' (Key attached at code below)
.data
inBuf: .space 80 # input line
outBuf: .space 80 # char types for the input line
prompt: .asciiz "Enter a new input line. \n”
.data
tabChar:
.word 0x09, 6 # tab
.word 0x0a, 6 # LF
.word ' ', 6
.word '#', 5
.word '$', 4
.word '(', 4
.word ')', 4
.word '*', 3
.word '+', 3
.word ',', 4
.word '-', 3
.word '.', 4
.word '/', 3
.word '0', 1
.word '1', 1
.word '2', 1
.word '3', 1
.word '4', 1
.word '5', 1
.word '6', 1
.word '7', 1
.word '8', 1
.word '9', 1
.word ':', 4
.word 'A', 2
.word 'B', 2
.word 'C', 2
.word 'D', 2
.word 'E', 2
.word 'F', 2
.word 'G', 2
.word 'H', 2
.word 'I', 2
.word 'J', 2
.word 'K', 2
.word 'L', 2
.word 'M', 2
.word 'N', 2
.word 'O', 2
.word 'P', 2
.word 'Q', 2
.word 'R', 2
.word 'S', 2
.word 'T', 2
.word 'U', 2
.word 'V', 2
.word 'W', 2
.word 'X', 2
.word 'Y', 2
.word 'Z', 2
.word 'a', 2
.word 'b', 2
.word 'c', 2
.word 'd', 2
.word 'e', 2
.word 'f', 2
.word 'g', 2
.word 'h', 2
.word 'i', 2
.word 'j', 2
.word 'k', 2
.word 'l', 2
.word 'm', 2
.word 'n', 2
.word 'o', 2
.word 'p', 2
.word 'q', 2
.word 'r', 2
.word 's', 2
.word 't', 2
.word 'u', 2
.word 'v', 2
.word 'w', 2
.word 'x', 2
.word 'y', 2
.word 'z', 2
.word 0x5c, -1 # if you ‘\’ as the end-of-table symbol
.text
getline:
la $a0, prompt # Prompt to enter a new line
li $v0, 4
syscall
la $a0, inBuf # read a new line
li $a1, 80
li $v0, 8
syscall
linearSearch:
li $t0, 0 #load 0 into index
j linearLoop
linearLoop:
li $t4, 0 #load 0 into inner index
lb $a0, inBuf($t0) #load first byte from input
j linearLoopTab
linearLoopTab:
lb $a1, tabChar($t4) #load first byte from tabchar
beq $a1, $a0, found #compares input byte to tab byte, if similar jump to found
li $t2, '#' #makes t2 '#'
beq $a0, $t2, exit #if current input byte is '#', exit
addiu $t4, $t4, 8 #add index
j linearLoopTab #loop back
found:
addi $t4,$t4,4 #selects correct pos for encrypted message
lb $a2, tabChar($t4) #load first byte from input
subi $t4,$t4,4 #reverting pos
sb $a2, outBuf($t0) #store it into outbuff at index pos
addi $t0, $t0, 1 #add index
j linearLoop
exit:
la $a0, outBuf
li $v0, 4 #prints and leaves
syscall
la $a0,inBuf
jal clear
la $a0,outBuf
jal clear
li $v0, 10 #exit command
syscall
clear:
li $t0, 0
I already tried to change the "li $v0, 4 #prints and leaves" to system code 1 for integer. That results in a very strange number to be printed (268501072) I am unsure why that happens
I figured it out, just added 48 to my $a2 and it worked
found:
addi $t4,$t4,4 #selects correct pos for encrypted message
lb $a2, tabChar($t4) #load first byte from input
subi $t4,$t4,4 #reverting pos
addi $a2,$a2,48
sb $a2, outBuf($t0) #store it into outbuff at index pos
addi $t0, $t0, 1 #add index
j linearLoop