Click to See Complete Forum and Search --> : MIPS and String Manipulation


reddog418
February 26th, 2006, 08:33 PM
The goal of this is to skip X characters in order to unjumble to string.

So string01 would translate

Faboabuisr98-2hsxhcahoabr.ke a slaslnsldsl k sslelwv.se.snaq

into

Four score and seven

Right now the code works for the first line, but then it goes to hell after trying to do the other lines. Any suggestions?


.data
numStrings:
.word 6

jumbled: .word 2

strings: .word string01
.word string02
.word string03
.word string04
.word string05
.word string06

string01: .asciiz "Faboabuisr98-2hsxhcahoabr.ke a slaslnsldsl k sslelwv.se.snaq"
string02: .asciiz " y28e!@a(*r83s{} ][a*(g<>osl,<> !@o!@u!@r!@ !@f"
string03: .asciiz ",ma,mt,mh,me,mr,ms,m ,mb,mr,mo,mu,mg,mh,mt,m ,mf,mo,mr,mt,mh,m"
string04: .asciiz "o*(n*( *(t*(h*(i*(s*( *(c*(o*(n*(t*(i*(n*(e*(n*(t*( "
string05: .asciiz "xtagh ghngheghwgh ghnghaghtghighoghngh,gh g"
string06: .asciiz "hc[5o[5n[5c[5e[5iVmvVmeVmdVm VmisSnsS sSlsSisSbsSesSrsStsSy"

.data
newline: .asciiz "\n"
stringloc: .word 0
counter: .word 0
letter: .asciiz ""

.text

main:
# Prologue
subu $sp, $sp, 24 # allocate stack space -- default of 24 here
sw $fp, 0($sp) # save caller's frame pointer
sw $ra, 4($sp) # save return address
addiu $fp, $sp, 24 # setup main's frame pointer

# Initialize jumbled
la $t0, jumbled
lw $s7, 0($t0)

add $s7, $s7, 1 # $s7 = jumbled + 1

# Initialize numStrings and counter
la $t0, counter
lw $s0, 0($t0) # $s0 = counter

la $t0, numStrings # $s1 = numStrings
lw $s1, 0($t0)

la $t0, strings
lw $s2, 0($t0) # $s2 = strings[]


## Begin global loop ## while(counter != numStrings){
start: beq $s0, $s1, done # if our counter is equal to numStrings, end program

add $t7, $s0, $s0
add $t7, $t7, $t7
add $t7, $t7, $s2 # compute address of next string[]

lw $s3, 0($t7) # $s3 now contains the word address of the next string

##la $t0, string01 # load the memory address of the string



## Get the string to process
add $t0, $t7, $zero
add $t1, $zero, $zero

## Start filtering the string
printletters:
lb $t1,0($t0) # load the character

la $t3, letter
sb $t1, 0($t3) # store character into memory

add $a0, $t3, $zero # print the character
li $v0, 4
syscall

beq $t1, $zero, endline # linebreak for next string

add $t0, $t0, $s7 # skip the next "jumbled" chars
j printletters # we're not done so go back

endline:
la $a0, newline
li $v0, 4
syscall

addi $s0, $s0, 1 # increment counter++
j start

# return to caller's code

# Epilogue for main -- restore stack & frame pointers and return
done:
lw $ra, 4($sp) # get return address from stack
lw $fp, 0($sp) # restore the caller's frame pointer
addiu $sp, $sp, 24 # restore the caller's stack pointer
jr $ra