MIPS - I'm Not getting the right answer :( Can anybody Review :)

Reply

Join Date: Apr 2005
Posts: 2
Reputation: solaris is an unknown quantity at this point 
Solved Threads: 0
solaris solaris is offline Offline
Newbie Poster

MIPS - I'm Not getting the right answer :( Can anybody Review :)

 
0
  #1
Apr 18th, 2005
Hi Guys,
So I started writing this program where i want the user to input a string
of numbers and letters and then i want to print out just the letters from
the sting ignoring all the letters and other characters such at , ; : * &...
I got it to take the string no problem and then i did the bgt and blt 's so
that it skips all the characters i don't want it to use but when it prints out
the resulting string I'm still getting the original string ;( I have no idea
where I made the mistake Please give me some ideas thx

  1. .data
  2. ask: .asciiz "Type a character string (<31 chars long): "
  3. count: .asciiz "number: "
  4. maxlen: .word 31
  5. buffer: .space 31 # allocates 31 bytes of memory in the data segment
  6. str: .space 31
  7.  
  8.  
  9. .text
  10. .globl main
  11.  
  12. main:
  13. li $v0, 4
  14. la $a0, ask # Print "Type a character string: "
  15. syscall
  16.  
  17. la $a0, buffer # $a0 holds the address of the read buffer
  18. lw $a1, maxlen # Max number of chars (including the end of string char)
  19. li $v0, 8 # Load the service number
  20. syscall # Call the operating system
  21.  
  22. # Copy the buffer into str and replace lower case letters with upper case letters
  23.  
  24. li $t2, 58 # the ASCII code of ":"
  25. li $t3, 47 # the ASCII code of "/"
  26. li $t0, 0 # $t0 is the index
  27. li $t4, 0
  28.  
  29.  
  30. loop:
  31. lb $t1, buffer($t0) # fetch a char from the buffer
  32. blt $t1, $t2, skip # the char is before ":", skip it Branch on Less Than
  33. bgt $t1, $t3, skip # the char is after "/", skip it Branch on Greater Than
  34.  
  35.  
  36. skip:
  37. addi $t4, $t4, 1
  38. sb $t1, str($t0) # and store it into str
  39. addi $t0, $t0, 1 # increment index
  40. bne $t1, $0, loop # if $t1 <> "end of string" then goto loop
  41.  
  42.  
  43.  
  44. li $v0, 4
  45. la $a0, str # Print str
  46. syscall
  47.  
  48. sub $t4, $t4, 2
  49. li $v0, 4
  50. la $a0, count
  51. syscall
  52. move $a0, $t4
  53. li $v0, 1
  54. syscall
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 2
Reputation: solaris is an unknown quantity at this point 
Solved Threads: 0
solaris solaris is offline Offline
Newbie Poster

Re: MIPS - I'm Not getting the right answer :( Can anybody Review :)

 
0
  #2
Apr 20th, 2005
AHHH i got it ;O) :p
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC