How to store character immediate in .space type MIPS

0

I'm currently trying to convert an ascii character to its equivalent in binary as part of a larger program that I have running. I have an input buffer that I can successfully parse through character by character, and I am using branch statements to run specific commands like so:

.data
...
    binaryBuff: .space 32
...
.text
...
la $s1, binaryBuff              #Store buffer for binary string in $s1
...
beq $t1, '0', zero              #If current character is ascii zero
...
zero:
    jal loadZero
    jal loadZero
    jal loadZero
    jal loadZero
    j afterCBChecks
...
loadZero: #Load zero into current space in binary buffer, then move to next char
    
    addi $t2, $zero, 48 
    sb $s1, ($t2)                   #Load 0 into current $s1 byte
    addi $s1, $s1, 1                #Move to next char
    jr $ra

My issue is with the loadZero section of the code. I need to be able to store a single character (0 or 1) into a byte in a buffer that is referenced by $s1, and then move to the next byte in the space to repeat. I must do this to further analyze the binary string as a whole, so other options of storing the information are (to my knowledge) nonexistent.

Currently the sb $s1, ($t2) command is returning the error Runtime exception at 0x004002d4: address out of range 0x00000030, and I know that is because the command I am using is attempting to store an address into $s1 rather than the plain character value. I'm just not sure what command will actually do what I want.

Long story short, I need a way to store an immediate character value into a .space data type.

A more efficient way to actually do the comparisons for the ascii values wouldn't hurt either, because with 16 branch conditions, and each branch laid out the same way, it uses 122 lines in my code (which bothers me a lot). I had a previous method that used more comparisons, with less overall lines, but even that bothered me. I may be asking too much of assembly when I ask for that though.

assembly
char
mips
asked on Stack Overflow Apr 24, 2021 by Lord R

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0