943,972 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 5580
  • Assembly RSS
Apr 18th, 2005
0

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

Expand Post »
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

Assembly Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
solaris is offline Offline
2 posts
since Apr 2005
Apr 20th, 2005
0

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

AHHH i got it ;O) :p
Reputation Points: 10
Solved Threads: 0
Newbie Poster
solaris is offline Offline
2 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: FPU + external C file - how to return double
Next Thread in Assembly Forum Timeline: Assembly newbie question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC