COMP2300

Semester 1, 2007: Assignment 2

Deadline: 12:00 (noon) on Friday 04 May 2007

Hints added 11/04: these will appear within (*** ...... ***) below.

(Please report any errors, mistakes and ambiguities to the course lecturer)


This assignment is worth 10% of your total course mark. It will be marked out of 40 as indicated below.

The estimated time we expect you to spend on this assignment is around 10 hours in total (1 hour per 4 assignment marks).

Submission

This assignment must be submitted electronically. This can be done using the submit comp2300 ass2 ... command.

You should submit a separate file for each part of the assignment you are required to complete. The file names which you should use (and the only ones that will be accepted by the submit command) are:

    filter.mli
    transpose.ass
As an example of what you should do

    submit comp2300 ass2 filter.mli transpose.ass
All files submitted must include, at the beginning, a completed preamble. The proforma for this can be found in the file:

      /dept/dcs/comp2300/public/standard_preamble.txt

You have to copy the preamble from this file into the top of each file you intend to submit, and then complete your details. By submitting a file containing a completed preamble, you are making a declaration about the work you have submitted (see the text of the declaration in the preamble files. If you need to modify the text, e.g. you did in fact receive substantial assistance from another student, you should modify the text to say so).

Any file submitted without a completed preamble will be rejected without being marked.

Note you can submit any file multiple times, including after the deadline has expired. Note that if you submit any file after the deadline your entire submission will be considered as late and will attract a late penalty.

Extensions

See http://cs.anu.edu.au/student/comp2300/assessment.html.

Late Penalties

Late penalties are as follows
How LatePenalty from 60 Marks
less than 1 hour-1
between 1 and 6 hour-2
between 6 and 24 hours (1 day)-4
between 24 and 48 hours (2 days)-8
between 48 and 72 hours (3 days)-16
between 72 and 96 hours (4 days)-32
more than 96 hours (4 days)-64 (forget it!)

Note: late penalties apply even if you submit just one file after the deadline.

Plagiarism

See http://cs.anu.edu.au/student/comp2300/assessment.html.

Part 1 - Machine Language Programming [8 marks]

Write a PeANUt machine language program filter.mli that reads in a line of text and prints out the line with uppercase letters transformed to lowercase letters, and a sequence of one or more spaces replaced by a single space. The input is terminated by ONE end-of-line character (ASCII code o012) as is your program's output. For example, given the input:
This is a ***SHORT*** linE WITH a   few    multiple spaces    .
Your program should produce the output:
this is a ***short*** line with a few multiple spaces .

Style:

Hints:

Marking:


Part 2 - PeANUt Assembly Programming [32 marks]

Translate your C program transpose.c from Assignment 1, Part 2 (as specified in there) into an equivalent PeANUt assembly program transpose.ass.

For full marks, your program should contain a function to print the matrix (***any local variables should also be implemented n the stack***). Your program should use the InOut function WriteInt() to print number, and WriteString() to print strings. It should also use the InOut function ReadCard() to read n.

Style:

In this part of the assignment you have to write a PeANUt assembly language program. This program should be set out with only one instruction (or macro call) per line and using your C code plus additional comments as necessary (similar to the comments given in the examples in lectures and labs). All functions should be commented; non-trivial variable declarations should also be accompanied by a short comment.

You have to follow the procedure call convention as discussed in lectures and labs. Make sure you have the correct offsets (defined as concise macros) for input parameters and local variables. Quantities used to define data structure limits should be defined as a constant (concise macro) for both C and assembler programs.

Hints:

You may modify transpose.c (as submitted for Assignment 1); in particular, it should be debugged and simplified if necessary. The latter might involve removal of any of the C library functions that do not have a PeANUt equivalent in InOut, and possibly removal of excessive internal functions. You might also want to consider shortening long identifiers (see below). (*** Move all variable declarations to the top of main(). You may also want to explicitly translate for loops to while loops beforehand (see lecture C2, p7) - although rather verbose, this will make translation clearer. A two-space indentation is recommended for the C code, as otherwise you will run out of room! Note that a call like printf("text ... %d more text\n", i) will need to be effectively converted to printf("text ... "); printf("%d", i); printf(" more text\n"); for direct translation to PeANUt. It is advised to put the print matrix function at the bottom of the program, as otherwise concise macro definitions might clash with address labels, e.g. n. ***) In this case, the C program should be tested again before you translate it into assembler. The final C code should then be used to document the assembler.

The InOut.ass module is available from the lecture P8 example programs web page at: http://cs.anu.edu.au/student/comp2300/lectures/P8progs/. Assemble and link your program using
assemble transpose.ass ; join transpose.rel InOut.rel.

In your assembler code, don't omit the # when using immediate mode constants (e.g. use cmp #'\n', not cmp '\n'). Keep your identifiers (including branch targets) reasonably short (only the first 7 characters are significant, and underscores are not allowed). When evaluating conditions, check that the correct branch instruction is used. If you suspect you have an infinite loop, commenting out backward branches/jumps may help in identifying which loop.

(*** Strings need to be defined using the data directive (lecture P5, p10). The sensible use of macros is encouraged. In particular, defining a macro to call WriteStr, and one to set up XR to index your matrix will be helpful, as these operations need to be done a number of times. When debugging other parts of your code, commenting out all calls to WriteStr may be helpful - and if this is done by a macro, you will only need to do this in one place! Note lectures P6, P7 and P8 cover most aspects of arrays and functions that you will need. ***)

I suggest that you start implementing, testing and debugging transpose.ass one step at a time. When you get to step 5, it may be easier at first not to implement the code in a separate procedure; if later making this into a procedure proves too problematic, it is better to leave it in the main program and repeat the section of code for printing the transposed matrix.

When completed, transpose.ass should give exactly the same output as transpose.c.

Marking:

Your program will be marked for correctness / completeness. Marks will be deducted for poor style.



Last modified: Wed Apr 11 13:26:54 EST 2007