andrex's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 3 (0.01 per day)
- Joined:
- 08-October 12
- Profile Views:
- 76
- Last Active:
Oct 08 2012 10:18 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: MIPS Program to find palidrome
Posted 8 Oct 2012
*ANOTHER UPDATE*
For anyone who cares, I've worked more and tweaked it, but I still need some help. Now my program says the longest palindrome is interpret nine memos, and that is wrong in multiple ways. If someone could give some feedback, that'd be great.
.data pali0: .asciiz "Go deliver a dare, vile dog" pali1: .asciiz "Some men interpret nine memos" pali2: .asciiz "Gateman sees name, garageman sees name tag" pali3: .asciiz "Ein Neger mit Gazelle zagtim Regen nie" pali4: .asciiz "stressed desserts" pali5: .asciiz "palindromes" pali6: .asciiz "Drab as a fool, aloof as a bard" pali7: .asciiz "Tattarrattat" pali8: .asciiz "Socorram me subi no on ibus em Marrocos" pali9: .asciiz "May a moody baby doom a yam" test_str: .word pali0, pali1, pali2, pali3, pali4, pali5, pali6, pali7, pali8, pali9 is_pali_msg: .asciiz "The string is a palindrome." not_pali_msg: .asciiz "The string is not a palindrome." newline: .asciiz "\n" res_msg: .asciiz "The longest palindrome is " forward_msg: .space 400 backward_msg: .space 400 .text .globl main main: la $a0, test_str # Load the starting address of the array li $a1, 10 # the number of elements jal get_longest ori $t0, $v0, 0 la $a0, res_msg li $v0, 4 # print $a0 syscall ori $a0, $t0, 0 li $v0, 4 # print $a0 syscall la $a0, newline li $v0, 4 # print $a0 syscall done: li $v0, 10 # exit syscall get_longest: addi $sp, $sp, -8 sw $ra, 4($sp) sw $a0, 0($sp) li $s1, 0 # loop counter\ lw $s0, 0($a0) li $t1, 0 li $t0, 0 li $t4, 0 PALLOOP: la $a0, 0($s0) la $t2, 0($s0) # stores the address of the next palindrome into a0 addi $s1, $s1, 1 beq $s1, $a1, ENDPAL # checks if loop is done jal is_palindrome # call is_palindrome beq $v0, $0, NOTLOOP # if string is not palindrome ori $t3, $a0, 0 # store the length and index of the next palindrome bge $t0, $t2, NOTLOOP # if first length > second, continue add $t0, $t2, $0 # else copy second length and address to t0 and t1 add $t1, $t3, $0 NOTLOOP: addi $s0, $s0, 4 j PALLOOP ENDPAL: # end of pal loop lw $a0, 0($sp) lw $ra, 4($sp) addi $sp, $sp, 8 ori $v0, $t2, 0 jr $ra is_palindrome: addi $sp, $sp, -16 sw $ra, 0($sp) sw $a0, 4($sp) sw $s0, 8($sp) sw $s1, 12($sp) jal get_to_end # call get_to_end ori $t0, $a0, 0 la $t1, forward_msg la $t2, backward_msg li $t4, 65 # ascii value for A li $t5, 90 # ascii value for Z addi $sp, $sp, -1 sb $0, 0($sp) COPY: # copies char lb $t3, 0($t0) beq $t3, $0, COPYDONE blt $t3, $t5, MAYBE LOWER: sb $t3, 0($t1) addi $sp, $sp, -1 sb $t3, 0($sp) addi $t1, $t1, 1 addi $t0, $t0, 1 j COPY MAYBE: # char is above upper, but not known blt $t3, $t4, LOWER addi $t3, $t3, 32 j LOWER COPYDONE: REVCOPY: # copies char string in reverse lb $t0, 0($sp) addi $sp, $sp, 1 sb $t0, 0($t2) beq $t0, $0, REVDONE addi $t2, $t2, 1 j REVCOPY REVDONE: li $t0, 1 la $t1, forward_msg la $t2, backward_msg CHECK: lb $t3, 0($t1) lb $t4, 0($t2) bne $t3, $t4, FALSE # if string is same forward and back, then equal beq $t4, $0, TRUE addi $t1, $t1, 1 addi $t2, $t2, 1 j CHECK TRUE: li $v0, 1 j PALDONE FALSE: li $v0, 0 PALDONE: add $v1, $v1, $0 lw $s0, 8($sp) lw $s1, 12($sp) lw $a0, 4($sp) lw $ra, 0($sp) addi $sp, $sp, 16 jr $ra get_to_end: addi $sp, $sp, -4 sw $ra, 0($sp) la $t1, 0($a0) li $t3, 0 li $t0, 0 #counts how many chars CHARCHECK: # goes through and counts the number of chars lb $t3, 0($t1) beq $t3, $0, RUNDONE la $t2, 0($t1) addi $t0, $t0, 1 addi $t1, $t1, 1 j CHARCHECK RUNDONE: add $v0, $t2, $0 add $v1, $t0, $0 lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra
-
In Topic: MIPS Program to find palidrome
Posted 8 Oct 2012
#EDIT#
I have made some leeway with this, the program now runs all the way through. It just isn't giving me the right answer. But that's better than it was before. My code is still a mess, but I'm getting there.
.data pali0: .asciiz "Go deliver a dare, vile dog" pali1: .asciiz "Some men interpret nine memos" pali2: .asciiz "Gateman sees name, garageman sees name tag" pali3: .asciiz "Ein Neger mit Gazelle zagtim Regen nie" pali4: .asciiz "stressed desserts" pali5: .asciiz "palindromes" pali6: .asciiz "Drab as a fool, aloof as a bard" pali7: .asciiz "Tattarrattat" pali8: .asciiz "Socorram me subi no on ibus em Marrocos" pali9: .asciiz "May a moody baby doom a yam" test_str: .word pali0, pali1, pali2, pali3, pali4, pali5, pali6, pali7, pali8, pali9 is_pali_msg: .asciiz "The string is a palindrome." not_pali_msg: .asciiz "The string is not a palindrome." newline: .asciiz "\n" res_msg: .asciiz "The longest palindrome is " forward_msg: .space 400 backward_msg: .space 400 .text .globl main main: la $a0, test_str # Load the starting address of the array li $a1, 10 # the number of elements jal get_longest ori $t0, $v0, 0 la $a0, res_msg li $v0, 4 # print $a0 syscall ori $a0, $t0, 0 li $v0, 4 # print $a0 syscall la $a0, newline li $v0, 4 # print $a0 syscall done: li $v0, 10 # exit syscall get_longest: addi $sp, $sp, -8 sw $ra, 4($sp) sw $a0, 0($sp) li $s1, 0 # loop counter\ la $s0, 0($a0) PAL: # determines which are palindromes lw $a0, 0($s0) # stores the address of the palindrome into a0 addi $s1, $s1, 1 jal is_palindrome # call is_palindrome beq $v0, $0, NOT # jump to NOT if string is not a palindrome ori $t1, $a0, 0 # store the length and address of the first palindrome ori $t0, $v1, 0 addi $s0, $s0, 4 PALLOOP: la $a0, 0($s0) # stores the address of the next palindrome into a0 addi $s1, $s1, 1 beq $s1, $a1, ENDPAL # checks if loop is done jal is_palindrome # call is_palindrome beq $v0, $0, NOTLOOP # if string is not palindrome ori $t3, $a0, 0 # store the length and address of the next palindrome ori $t2, $v1, 0 bge $t0, $t2, NOTLOOP # if first length > second, continue add $t0, $t2, $0 # else copy second length and address to t0 and t1 add $t1, $t3, $0 NOTLOOP: addi $s0, $s0, 4 j PALLOOP NOT: # if the string is not a palindrome addi $s0, $s0, 4 j PAL ENDPAL: # end of pal loop lw $a0, 0($sp) lw $ra, 4($sp) addi $sp, $sp, 8 addi $v0, $t1, 0 jr $ra is_palindrome: addi $sp, $sp, -4 sw $ra, 0($sp) jal get_to_end # call get_to_end ori $t0, $a0, 0 la $t1, forward_msg la $t2, backward_msg li $t4, 65 # ascii value for A li $t5, 90 # ascii value for Z li $t6, 97 # ascii value for a li $t7, 122 # ascii value for z addi $sp, $sp, -1 sb $0, 0($sp) COPY: # copies char if letter lb $t3, 0($t0) beq $t3, $0, COPYDONE blt $t3, $t4, NO bgt $t3, $t5, MAYBE UPPER: # if char is uppercase, changes to lower addi $t3, $t3, 32 LOWER: sb $t3, 0($t1) addi $sp, $sp, -1 sb $t3, 0($sp) addi $t1, $t1, 1 addi $t0, $t0, 1 j COPY MAYBE: # char is above upper, but not known blt $t3, $t6, NO bgt $t3, $t7, NO j LOWER NO: # char is not letter addi $t0, $t0, 1 j COPY COPYDONE: li $t0, 0 # loop counter REVCOPY: # copies char string in reverse lb $t0, 0($sp) addi $sp, $sp, 1 sb $t0, 0($t2) beq $t0, $0, REVDONE addi $t2, $t2, 1 j REVCOPY REVDONE: li $t0, 1 la $t1, forward_msg la $t2, backward_msg CHECK: lb $t3, 0($t1) lb $t4, 0($t2) bne $t3, $t4, FALSE # if string is same forward and back, then equal beq $t4, $0, TRUE addi $t1, $t1, 1 addi $t2, $t2, 1 j CHECK TRUE: li $v0, 1 j PALDONE FALSE: li $v0, 0 PALDONE: lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra get_to_end: addi $sp, $sp, -4 sw $ra, 0($sp) la $t1, 0($a0) li $t3, 0 li $t0, 0 #counts how many chars li $t4, 65 # ascii value for A li $t5, 90 # ascii value for Z li $t6, 97 # ascii value for a li $t7, 122 # ascii value for z CHARCHECK: # goes through and counts the number of letter chars lb $t3, 0($t1) beq $t3, $0, RUNDONE la $t2, 0($t3) blt $t3, $t4, NOCHAR bgt $t3, $t5, MAYBECHAR j CHAR MAYBECHAR: # if the character is above upper case and might be lower case blt $t3, $t6, NOCHAR bgt $t3, $t7, NOCHAR j CHAR NOCHAR: # if the char is not a letter addi $t1, $t1, 1 j CHARCHECK CHAR: # if the char is a letter addi $t0, $t0, 1 addi $t1, $t1, 1 j CHARCHECK RUNDONE: add $v0, $t2, $0 add $v1, $t0, $0 lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
andrex hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
andrex has no profile comments yet. Why not say hello?