rotexhawk 0 Newbie Poster

Hello,

I am trying to compare two characters of different strings but it quits the loop.
I know i am accessing the right chars caz i have tested it with print multiple times.

.data
mainNumPhrases:
         .word  4
mainPhrases:
         .word  mainPhrase1
         .word  mainPhrase2
         .word  mainPhrase3
         .word  mainPhrase4
         
mainPhrase1: 
         .asciiz "abcdefghijklmnopqrstuvwxyz"
mainPhrase2: 
         .asciiz "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdeabcdeABCDEXYXYXYZz"
mainPhrase3:
         .asciiz "1234567890-=`~!@#$%^&*()_+[]\{}|';:,./?><"
mainPhrase4: 
		  .ascii  "I have sworn upon the altar of God eternal hostility "
          .ascii  "against every form of tyranny over the mind of man. "
          .asciiz "--  Thomas Jefferson."
          
          # Your code goes below this line '
strings:
	   .word	lowerString
	   .word	upperString
	   
lowerString: 
         .asciiz "abcdefghijklmnopqrstuvwxyz"    
         
upperString: 
         .asciiz "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
         
i: 
	.word 0 

n: 
	.word 0
          
          
          
          
.text

main: 

  # Function prologue -- even main has one
        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, 20       # setup main's frame pointer
        
         la $s0,i
         lw $s0,0($s0)			 # $s0 has address of i for the second loop 
         
         la $s1,n
         lw $s1,0($s1)			 # $s1 has address of n for the first loop
         
         add   $t0, $zero, $s1        # want position i
         sll   $t0, $t0, 2            # multiply position by 4
         la    $t1, strings		      # address of beginning of array
         add   $t1, $t1, $t0          # add offset to address
         lw    $s4, 0($t1)            # $s4 = address of the [i]th string
         lb    $s1, 0($s4)            # $s1 = string[j]
         
         add $s1,$s1,$zero
         
         add $a0,$s1,$zero
         addi $v0,$zero,11
         syscall
        
         
         
         
mainLoop:  
         add   $t0, $zero, $s0        # want position i
         sll   $t0, $t0, 2            # multiply position by 4
         la    $t1, mainPhrases       # address of beginning of array
         add   $t1, $t1, $t0          # add offset to address
         lw    $s4, 0($t1)            # $s4 = address of the [i]th string
         lb    $s1, 0($s4)            # $s1 = string[j]
 		
 		add $s2,$s2,$zero
 
 
 # The comparison doesn't work for some reason '
 
 		slt $s3,$s2,$s1
 		beq $s3,$zero,match			# eventhough both the characters are 'a'
 									# it ends the loop. 
		j endLoop
		

match:  
add $a0,$s1,$zero
addi $v0,$zero,11
syscall       


endLoop:


        
done:    # Epilogue for main -- restore stack & frame pointers and return
         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                 # return to caller's code
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.