Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

My first prog (find if a string is palindromic)

Hi this is my first post in this forum! I learned a bit of mips assembly and did my first exercise, I have some questions though. Where can I find the list of all the assembly commands? Some websites do not include bge (branch if greater or equal) in their list. I'm going to learn computer architecture from this book soon in my university:Computer Organization and Design: The Hardware/Software Interface (J.Hennessy), what kind of assembly I'm going to see there? Currently I'm studying from here: http://www.eecs.harvard.edu/~ellard/Courses/cs50-asm.pdf
and I have downloaded PcSpim 8.0 does anyone now how to run a programme on this thing?
Ok here's the programme (if you have any suggestions/corrections or a different approach please tell me):

[code]
.text
main:
li $v0
la $a0,usrstr
li $a1,1024
syscall
la $t1,usrstr #$t1 used to hold the left index
la $t2,usrstr #$t2 used to hold the right index

findend:
lb $t3,($st2)
beq $t3,10,sseek #go to the search of a char or an int which is starting from the left
addu $t2,$t2,1
b findend

ssekk:
lb $t3,($t1) #$t3 to hold the byte
addu $t1,$t1,1
bge $t1,$t2,ypal # the way out if the string is palindromic or null

li $t4,0 # $t4=0 to indicate integer
blt $t3,48,sseek
blt $t3,58,endsseek
li $t4,1 # $t4=1 to indicate char
blt $t3,65,sseek
blt $t3,91,endsseek
blt $t3,97,sseek
blt $t3,123,endsseek
b sseek

endsseek:
lb $t6,($t2) # $t6 to hold the byte
subu $t2,$t2,1

li $t5,0 #$t5=0 to indicate int
blt $t6,48,endsseek
blt $t6,58,checkeq #checkeq to check equality of ints or chars inside $t3,$t6
li $t5,1 #$t5=1 to indicate char
blt $t6,65,endsseek
blt $t6,91,checkeq
blt $t6,97,endsseek
blt $t6,123,checkeq
b endsseek

checkeq:
beq $t3,$t6,sseek
bne $t4,$t5,npal
beq $t4,0,npal #$t5 used as scratch place from now on
addu $t5,$t3,32
beq $t5,$t6,sseek
addu $t5,$t6,32
beq $t5,$t3,sseek

npal:
li $v0,4
la $a0,npalmsg
syscall
li $v0,10
syscall

ypal:
li $v0,4
la $a0,ypalmsg
syscall
li $v0,10
syscall
.data
usrstr: .space 1024
npalmsg: .asciiz "The input string is not a palindromic one."
ypalmsg: .asciiz "The input string is a palindromic one."
[/code]

Comments

  • Bat0u89Bat0u89 Posts: 2Member
    Something I didn't mention :P :
    The programme must ignore punctuation, white space and capitalization. It must recognize these as palindromic:
    1. "1 2 321"
    2. "Madam, I'm Adam."
    3. "Able was I, ere I saw Elba."
    4. "A man, a plan, a canal{ Panama!"
    5. "Go hang a salami; I'm a lasagna hog."
    2
Sign In or Register to comment.