Empty Mips field at address

So I have a string of characters. I need to check if a character is a space "" / ascii 32. How can I assign the ascii address to a space so that I can use it in if / else?

.data 
userInput: .space 40
.text
main:
li $v0, 8
la $a0, userInput
li $a1, 40
syscall

li $t1,0
    la $t0,userInput

loop:

li $a3, 32 #can i give this address 32 ascii value?
lb   $a0,0($t0)
beqz $a0,done
addi $t0,$t0,1 #going true the characters
bne  $t0, $a3, L1    # branch if ! ( char == ' ' ) 
addi $t1,$t1,1 #add blank space
L1: addi $t2,$t2,1 #add characters  
j     loop
done:

li   $v0,1
addi $t1, $t1, -1
add  $a0, $0,$t1
syscall

li $a0, 32
li $v0, 11  
syscall

li   $v0,1
addi $t2, $t2, -1
add  $a0, $0,$t2
syscall


li   $v0,10
syscall

      

+3


source to share


1 answer


.data   

         blankSpace: .ascii  " "

.text
 main:

         la $a3, blankspace
         lb $t3,0($a3)

      

Alternatively you can directly load the ASCII value for space

which is 0x20

in the ASCII table.



 li $a3, 0x20 

      

+2


source







All Articles