Docsity

CS 061 Assignment 7: Managing a List of Words in Assembly Language - Prof. Brian Linard, Assignments of Computer Science

Toggle sidebar
bg1
CS 061 โ€“ Computer Org. & Assembly Lang. Fall - 2003
Assignment 7 โ€“ due Wednesday 11/26, 11 pm (secure server turnin)
Managing a list of words
This program will have three components:
1. An input subroutine, allowing the user to input a sequence of words, which will be stored in an array,
i.e. in a sequence of contiguous memory locations.
2. A "longest" subroutine that will locate the longest word - i.e. the one that has the most characters.
3. An output subroutine that will output the whole list of words, one per line, and then the longest word
in the list (e.g. "The longest word is: antidisestablishmentarianism")
You may assume that any input is valid - i.e. you may accept as input words such as @!!%&^#
You may also assume that the total list is not too big for the memory - i.e. you do not need to explicitly
test for size limits.
We will do this in steps:
Part 1:
1. Write a subroutine that takes a single "argument" R1 that contains an address, and asks the user to
input a single word. It stores the word to the address given, in the same form as the .STRINGZ
pseudo-op - e.g. the word "whatever" would be stored as the array:
{x0077, x0068, x0061, x0074, x0065, x0076, x0065, x0072, x0000}
starting at the address in R1.
This means that you will have to store each character as it is entered, testing each time for cr/lf (the
newline character x0A) to detect the end of the word, at which point you will store a NULL and then
return.
2. Write a subroutine that takes a single "argument" R1 that contains the location of the word, and
prints it out (at this point, that just means copying R1 to R0 and calling TRAP x22)
3. Write a main program that just calls these two subroutines. The address to which the word will be
stored can be provided by a .FILL pseudo-op.
Part 2:
Now we have to think about how we will terminate a list of words, i.e. an array of arrays that each
terminates with a NULL.
Remember that all our inputs are (necessarily!) ASCII characters, i.e. 8-bit data items which are stored
pf3

Partial preview of the text

Download CS 061 Assignment 7: Managing a List of Words in Assembly Language - Prof. Brian Linard and more Assignments Computer Science in PDF only on Docsity!

CS 061 โ€“ Computer Org. & Assembly Lang. Fall - 2003

Assignment 7 โ€“ due Wednesday 11/26, 11 pm (secure server turnin)

Managing a list of words This program will have three components:

  1. An input subroutine, allowing the user to input a sequence of words, which will be stored in an array, i.e. in a sequence of contiguous memory locations.
  2. A "longest" subroutine that will locate the longest word - i.e. the one that has the most characters.
  3. An output subroutine that will output the whole list of words, one per line, and then the longest word in the list (e.g. "The longest word is: antidisestablishmentarianism") You may assume that any input is valid - i.e. you may accept as input words such as @!!%&^# You may also assume that the total list is not too big for the memory - i.e. you do not need to explicitly test for size limits. We will do this in steps: Part 1:
  4. Write a subroutine that takes a single "argument" R1 that contains an address, and asks the user to input a single word. It stores the word to the address given, in the same form as the .STRINGZ pseudo-op - e.g. the word "whatever" would be stored as the array: {x0077, x0068, x0061, x0074, x0065, x0076, x0065, x0072, x0000} starting at the address in R1. This means that you will have to store each character as it is entered, testing each time for cr/lf (the newline character x0A) to detect the end of the word, at which point you will store a NULL and then return.
  5. Write a subroutine that takes a single "argument" R1 that contains the location of the word, and prints it out (at this point, that just means copying R1 to R0 and calling TRAP x22)
  6. Write a main program that just calls these two subroutines. The address to which the word will be stored can be provided by a .FILL pseudo-op. Part 2: Now we have to think about how we will terminate a list of words, i.e. an array of arrays that each terminates with a NULL. Remember that all our inputs are (necessarily!) ASCII characters, i.e. 8-bit data items which are stored

in a full 16-bit LC-2 word. This means that they are all positive, so we could use -1 to terminate the list. Or we could also just use another NULL, so two NULLs one after the other would indicate the end of the list. So now:

  1. Add a subroutine that takes a single "argument" R1 that contains the location (the starting address) to which the list of words will be stored, and asks the user to enter either a word, or a cr/lf to indicate no more words. If the first character is x0A it writes the list termination character to the end of the array; otherwise it calls the word entry subroutine of Part 1, passing to it (in R1) the starting address of the new word. The character just entered will still be in R0, and so available to the word entry routine.
  2. Modify the word entry subroutine to remove the prompt, and to return the next available address (in what register?).
  3. Modify the output subroutine to print the whole list of words, one per line. This means outputting a cr/lf at the end of every word, and return at the end of the list. Part 3:
  4. Add a subroutine that takes a single "argument" R1 that contains the starting address of the list, and counts the number of characters in each word. It "returns" the starting address of the longest word. (Think how you would do this in a higher level language; the principle is the same).
  5. Add a subroutine (or modify your list output subroutine) to output a message giving the longest word. Note that all of the subroutines use R1 to pass an argument: you will have to be careful to preserve arguments (and return values) as you nest subroutine calls. Make sure you have complete and consistent comments in your code. Grading policy: Possible points: 10 Program assembles without errors: 3 Program runs correctly on LC-2 simulator 5 Well commented code: 2 Assignment submitted without name and SSN:-5 points (if we can figure out who you are!)