Notice:
Due: Wednesday Oct. 18th by 4pm
Resources:
Please refer to all the resources on our home page.
Files Needed:
chop.s
rev.s
read.s
Your task is to write a program rtrim.s that trims the whitespace off a word entered from the keyboard. Start by copying the two example files into your directory.
chop.s shortens a string by inserting a '\0' (NULL character) into the string. This effectively chops the string off. rev.s reverses the characters in a string. The algorithm takes two pointers, one starting at the end of the string and one starting at the begining of the string. It swaps the two characters at the top and bottom location. It moves the pointers 1 character (a byte) towards each other. It swaps the two characters at that location. It moves the pointers toward each other, swaps the two characters, so on and so forth until the pointers hit each other.
Your job is to write a program rtrim.s that removes trailing whitespace. Everything you need to do this is in rev.s and chop.s.
Use chunks of these two sample programs. You can grab the code to prompt the user for a string from read.s.
To demonstrate that you trimmed the white space, display the string followed by a period (if the period does not have any whitespace before it you know your code works). The code should execute as follows:
$ spim -f rtrim.s Enter a word followed by some whitespace: foo[Tab] [Tab][Enter] foo.
Your lab program rtrim.s must be in the correct directory on Sleipnir. directory name: /home/stu/you/2240/7/ Replace you with your own Sleipnir username!