Assignment 4
CISC221, Fall 2001
Queen's University
Due: Tuesday December 4th, 2000 (12:00)
Where: in drop boxGoodwin Hall
No late assignments! See below notes for furhter instructions.
When programming at the assembler level it can be difficult to keep track of one's implementation and algorithms, because Assembly language doesn't have familiar structures of control (while loops, procedures) and data. Such structures have to be made 'by hand', which is error-prone; and so, of course, we have high-level languages. But even when programming in assembly language it's helpful to design high-level algorithms. And it's instructive to translate from high-level structures to assembly level structures by hand, giving a feel for what the compiler has to do.
Translate a high-level (Java) program to Pep/6 assembly language program. All high level instructions are to be traslated. A certain amount of optimization can be included (such as: no need to load a register with a value that was already in that register as a result of a previous high level instruction translation), but do not optimize the given java program itself.
The Java program given is a program which simulates the behaviour of a simple device monitor. It obtains 'readings' from an imagined device, consisting of pairs of numbers (n,m). For each input, it provides as output the maximum and minimum of the last 25 n-values and the maximum and minimum of the last 25 m-values. (Such a monitor would probably pass it's results on to another device and therefore not include any labels or prompts). To do this, at least 25 pairs of integers must be stored. They are stored in a queue so that any amount of input can be processed efficiently (saving only the last 25 pairs, of course).
The Java program is given in full, there is no need to write it. Instead, translate it systematically into Pep/6 assembly language. In the lectures we've seen methods of representing
This program uses all those features.
Recall that arrays (allocated dynamically in Java) can be allocated statically in your translation.
Sample input for the program is available. It should produce this output. You can test it with other outputs, of course.
There is no way to detect 'end of input' with the Pep/6 input instructions, so each pair of numbers is preceded by a '*'. Execution ends as soon as the first character read on a line is not a '*'. In the Pep/6 machine (emulator) character input (CHARI) provides space characters where there is no more input.
There are modulus operations in the Java code (written with the
%). Pep/6 doesn't have a mod operation in general, but
when the divisor is a power of two, modulus can be implemented by
AND. That's why the queue size is 32.
There is no need to run the Java program itself. If you don't want to bother with that, ignore this Note.
If you want to experiment with compiling and running the Java program, you'll need the Io class it uses: here is a java file for just the Io class.
You need to hand in three things:
Note that even if your program doesn't work, you gain credit by having tests that show that it does not work.