943,960 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 445
  • Assembly RSS
Jan 29th, 2009
0

Help with modifying strings

Expand Post »
I am taking a class in Assembly this semester and am currently at a loss. The first two projects I found easy enough but now we are working with strings. I have a basic skeleton for the program that gets input.

Assembly Syntax (Toggle Plain Text)
  1. .data
  2. strbuf: .space 80 # Buffer for string being flipped
  3. ann: .ascii "Welcome to UpLo\n"
  4. .asciiz "Type a sentence and I will swap upper/lower case\n"
  5. prompt: .asciiz "New sentence (just return to exit): "
  6. .text
  7.  
  8. # Main Program
  9. #
  10. main:
  11. li $v0,4 # Announce myself with a message
  12. la $a0,ann # on the terminal.
  13. syscall
  14. loop:
  15. li $v0,4 # Prompt for a new sentence
  16. la $a0,prompt
  17. syscall
  18. jal readstr # Read the string
  19.  
  20. jal chgcase # Flip upper/lower case
  21. jal wrtstr # Write the result
  22. b loop
  23. done: # Get here when all done.
  24. li $v0,10 # "exit" syscall
  25. syscall
  26. readstr:
  27. li $v0,8
  28. la $a0,strbuf
  29. li $a1,80
  30. syscall
  31. jr $ra
  32. wrtstr:
  33. li $v0,4
  34. la $a0,strbuf
  35. syscall
  36. jr $ra
  37. chgxit:
  38. jr $ra

This succeeds in getting the input and writing it back to the screen. I just need to do a few modifications to the string that is entered. If the user enters nothing then the program exits. Any letters entered are reversed, upper to lower case and vice versa. I know that the difference in a letter's upper and lower case is 0x20, and 0x0a is the hex for a new line(user just typed enter) but I cannot figure out how to use this and the entered string to achieve the desired result. I asked the professor for help and he just told me the differnce is 0x20 hex, make sure the only things to change case are letters, and a new line is 0x0a. I already know all this, it is just the actual conversion that is giving me problems. Any help or hints in the right direction would be appreciated. I feel like I need to navigate the string one byte(character) at a time, and pass each character to a chg subroutine, but I haven't been able to get anything to work

Thank you for your time

PS, the assembly I am coding in is MIPS but I am sure that I can use other assembly code or tips and modify it as needed for my processor.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pocnib is offline Offline
6 posts
since Sep 2008
Jan 29th, 2009
0

Re: Help with modifying strings

Instead of relying on a syscall to output a string, is there one to output a character?

If so, use that to practice using a loop to scan a string until a \0 is found.
Then you can make the loop do other things, like say compare a char with 'A' and maybe add 0x20
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 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: new to assembly
Next Thread in Assembly Forum Timeline: Teach yourself assembly??





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


Follow us on Twitter


© 2011 DaniWeb® LLC