Assignment 9, due Oct. 30

Part of the homework for 22C:60, Fall 2009
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday). The only exceptions to this rule will be by advance arrangement unless there is what insurance companies call "an act of God" - something outside your control. Homework must be turned in on paper and in class! Late work may be turned in to the teaching assistant's mailbox, but see the late work policy. Never push late work under someone's door!

Problems

  1. Background: Consider the problem of designing a string package. Just to make it different from existing C or Java strings, we'll consider each string object to have a fixed size (so they can be statically allocated), but different string objects could have different sizes. Therefore, string objects have the following attributes:

    Appropriate operations on strings include (this is not an exhaustive list):

    a) Present a design for a representation of the string type. This problem does not ask for code, it asks for a design, that is, human-to-human communication before you start writing code. (0.5 points)

    b) Write a macro STRINGCONST such that
        A: STRINGCONST "string"
    will assemble a constant string object into memory. The handle for that object can be loaded into a register using LEA R,A or LIL R,A. Because it's a string constant, its capacity should, of course, be equal to its size. (0.5 points)

    c) Give appropriate content for the entry in the strings.h header file for the append operation. (0.5 points)

    d) Suppose STR, a local variable, holds a string object. Write assembly code to append the letter c to the string. (0.5 points)

  2. Background: There are some things missing from the descriptions of the string package above. Consider the problem of creating a string object called STR in the activation record of subroutine. This involves two separate pieces of assembly language code:

    a) (0.5 points) Suppose I wanted to allocate STR as a local string variable with a capacity of 15 characters. What problem does this pose?

    b) (0.5 points) Suppose you have allocated STR as a local string variable large enough to store a 15 character string. How would you initialize it, given the description of the string class above, or if that description is missing something, describe the missing parts needed to solve this problem.

    Note that problem 2a) is not a problem if STR is a global string variable. In that case, you can allocate and initialize the string as follows -- but note that this sets the capacity of the string variable equal to the length of its initial value:

    	COMMON	STR,STRSIZE
    OLDLC	=	.
    .	=	STR
    	STRINGCONST "initial value of string"
    STRSIZE =	. - STR
    .	=	OLDLC