Assignment One - CS341 S2002

This assignment involves writing a bunch of snippets of assembly language code. These are intended to give you practice with the basic control and arithmetic instructions of the SPARC architecture, and also with bit-twiddling. (20 points each, plus extra credit for the best memcpy.)

  1. Design a way to represent, in a 16-bit word, an integer in the range -16000 to 49000. This representation should allow these numbers to be manipulated (added, subtracted, multiplied, check if a number is negative, check if a number is zero) easily. (You don't need to worry about overflow.)

  2. Write code that assumes there is a 16-bit word representing an integer between -16000 and 49000 as in problem 1, and that r1 holds the address of that word. Fetch it from memory and manipulate it so the number in question ends up in r2, represented as a standard 32-bit 2's complement integer.

  3. Assume that r1 contains the address of the start of a hunk of memory, and r2 contains the address of the hunk's end, ie the address of the last byte in the hunk. Write code that scans through 8-bit numbers in the given hunk of memory. It should leave the sum of all the 8-bit numbers, considered to be signed, in r3; their sum, considering them unsigned, in r4; the number of bytes scanned in r5; and the number of negative ones (thinking of them as signed) in r6.

  4. Write code that scans a chunk of 16-bit words starting at the address in r1, with the number of elements in r2. Look for the three-word sequence 1, 2, 3. If this sequence is found, leave the address of the start of the sequence (ie of the word containing the number 1) in r3. If it is not found, leave r3 holding zero.

  5. Implement memcpy(3), with the arguments dest, src, and n coming from r1, r2, and r3, respectively. For extra credit make your routine as fast as possible by minimizing the number of memory accesses. In particular, this means not just loading and storing each byte individually, but instead handling them in 32-bit hunks. But be careful: dest and src are not necessarily word aligned, and n might not be a multiple of 4.
You should include in what you hand in not only the raw code required, but also code that sets up inputs for testing purposes. Grading will include whether we like your tests - ie whether they cover boundary cases, etc.

Hints

When a unix person says "look at memcpy(3)" that means you can read the documentation using "man 3 memcpy".

It is a good idea to first write pseudocode in pidgin C, and then gradually translate it into assembly.

Chapter seven in MacCabe is a good source of ideas for problem 1.

Handing in

The due date for this assignment is midnight Sat Feb 9, 2002.

To hand in your code, run

  ~bap/public_html/bin/hw-handin FILES OR DIRECTORIES
The script will recursively traverse directories, so be careful with directory arguments.

If you have a special note you wish to affix, use the -a switch.

Please do not just email attachments to the instructors.