Help with modifying strings

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 6
Reputation: pocnib is an unknown quantity at this point 
Solved Threads: 0
pocnib pocnib is offline Offline
Newbie Poster

Help with modifying strings

 
0
  #1
Jan 29th, 2009
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.

  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help with modifying strings

 
0
  #2
Jan 29th, 2009
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
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC