CSE378
Homework #2
Due: Beginning of class, Thursday Oct. 16, 2003
A. (Textbook) 3.12
B. 3.14
C. 3.16
D. C Programming. Use gcc
on a Unix or Linux machine for this problem. Visual Studio not
allowed! The goal is to 1) see how to compile C functions
separately and execute them together 2) practice using pointers and
characters. Programming in this way should give you some insight
into programming separate procedures and parameter passing in assembly
language.
1. After reading the rest of the problem, browse the the documentation
(man page) for gcc. Would you call it long or short? As you
browse, be on the lookout for options or features that may be helpful
for solving the problem.
2. Write a function isPal which
takes a single argument, a string (null-terminated array of
characters). The method determines if the string is a
palindrome. The algorithm should ignore non-letter characters,
and ignore case differences. For example, "Madam, I'm Adam" is a
palindrome under this definition. Return 1 if the string is a
palindrome, and 0 otherwise. Ground rule: you may not use []
notation anywhere in the function, and you may not use any C library
functions (that's right, no string functions!).
3. Write a main function, in a separate .c file, which expects a single
command-line argument. That argument is passed to isPal. Then print the string,
followed by " is a palindrome" or " is not a palindrome" according to
the result of the function. For this method, you may use the
standard C library function print
(or println) printf. Use [] if
you wish (you don't really need it).
4. Compile each of your functions separately, to separate object files
(.o). Figure out how to combine the object files into a single
executable file. Figure out how to run the executable file, and
run it on enough test cases that you are sure your program work.
[Hint: it is not necessary to learn how to use make or do anything
elaborate. Keep it as simple as you like.]
5. Turn in (somehow... method to be determined):
- A printout of each function
- Write out all the commands needed to accomplish #4 above.
You can write this out by hand, as long as it is legible. (Of
course it could also be a printout of some type)
- The executable file
- A short statement as to how well the program works (e.g.
"It works perfectly" or "It works except for..."). This can be
handwritten or could be a printout of a file; it could also be comments
in the main function.
E. MIPS assembly language programming.
You will be implementing the same algorithm twice, but running it in
slightly different contexts.
The algorithm determines if a string (in the usual C sense) is a valid
integer token, and if so, what its value is. For example,
the string "3" is a valid integer with value 3; "-12" is a valid
integer with value -12; "3.0" is not a valid integer; "three" is not a
valid integer; other invalid strings include "3 3", " 3", "3D",
etc.
1. Using the information just above, come up with a slightly more
formal and/or precise definition of what "valid integer token"
means. Include this in the comments of each assembly code file
you write.
2.Write a program which takes a string and determines if it is a valid
integer token. The string comes from the .data section of the
program, where it should be the first (and maybe only) data
defined. The program uses a SPIM kernel system call to print the
string followed by " valid" or " invalid". $v0 will be 0 if the
string is valid, non-0 otherwise. If the string is valid, $v1
should have the integer value of the string. Test in SPIM.
3. [This part does not have to be completed until Homework set #3, but
is described here for reasons that you will see]. Write a procedure isValid
which takes a string and determines if it is a valid integer
token. The procedure works as described above, except the string
is passed as an argument on the stack (it will be the only argument on
the stack); the string itself is not copied to the stack -- only its
address is passed.. Then write a "main" procedure which tests isValid by calling it four times
with different arguments, two valid and two invalid (one of the valid
ones should be positive, and one should be negative). The strings
used by main may be in the .data segment. Test in SPIM.
4. Turn in the following [for Homework #2, you only nee the first
program. On Homework #3, hand them both in.]
- A copy of each of the .s files, and a printout of each one
- A short statement as to how well each program works
F. "New Boss" You and
your team (up to three people total) are computer architects at a
company that makes a MIPS look-alike chip. One day there is a
shake-up and you get a new boss. He's very knowledgeable about
semiconductor technology and manufacturing, but is not a computer
architect. At his first staff meeting with you, he makes two
proposals which he thinks will improve the product and increase sales:
1. Since is it now possible to put many more transistors on a
chip, he proposes increasing the number of general purpose registers
from 32 to 64.
2. He proposes adding new arithmetic instructions which work just
like the usual ones (ADD, SUB, AND, etc. etc.), but take their data
from memory rather than from registers. The instructions would
have names like ADDM, SUBM, ANDM, etc.
Pick one or the other of these proposals. Then in no more than
one page, state:
a. why the idea might sound on the surface like it is worthwhile
b. what your team thinks the consequences or reality might be in
implementing the idea.
c. One-line: your conclusion about whether this should be undertaken.
Your reasons should be technical and architectural in nature (rather
than matters of marketing, etc., although sometimes the two are
related).