COMP2300
Tutorial / Laboratory 05 -
PeANUt Experiments
Semester 1, 2007
Week 6 (26 March - 30 March)
Note that for this session, there is a submitable laboratory exercise
which is due by 10 am Monday 02 April (week 7), which will contribute
up to 1% of your assessment (in the Tute/Lab mark).
Preparation Exercises
It is expected that you have looked over your lecture notes of the
PeANUt module as well as read the relevant parts of the Specification
of the PeANUt Computer before doing this session. It is also
expected that you have completed the lab exercises of the previous
session (at least part 3, Experimenting with the PeANUt, and part
5, Your multiplication program). You should also look at the
selected answers now up on the web page.
It is also expected for you to
complete beforehand the following exercises.
Complete the following questions on a separate sheet of paper, with your
name and student number clearly written. Please ensure your writing is
legible. Hand in to your tutor at the beginning of your tutorial /
laboratory session.
-
Briefly describe the term von-Neumann architecture.
-
Suppose the five 16-bit words starting at byte 1000 of a big-endian
machine contain the integers 1, 2, 3, 4, and 5. Further suppose that these
five words are transmitted to a little-endian machine as a sequence of
bytes in address order and stored at consecutive addresses starting at
byte 30000. What are the values of the five 16-bit words now?
-
Write a sequence of PeANUt MLI instructions that would do the same
computation as the C statement x = 3 * y + 1; . Assume
x and y are at memory locations a0 and
a1 respectively.
Tutorial Exercises
- Write a sequence of PeANUt MLI instructions that would do the
same computation as the C statement if (x==0) y++;. Assume
x and y are at memory locations a0 and
a1 respectively.
- Write a PeANUt program that would read an alphabetic character
and output the same character but with its case reversed
(that is from upper to lower, or from lower to upper).
Note the program can assume the character is either upper or loewer case.
You may (or may not) find useful the following ASCII codes:
'A'=o101, 'Z'=o132,
'a'=o141, 'z'=o172:
- Is it always possible to rewrite a PeANUt program containing
instructions which use indirect mode which is equivalent to one which
does not use indirect mode instructions? If not, devise a counterexample.
If so, outline a procedure by which a PeANUt instruction using indirect
mode might be translated into a sequence of one or more instructions
which did not.
- Analyse the claim that it is always possible to replace a procedure
call with the body of a procedure, and therefore that the procedure is
necessary.
Laboratory Exercises
Preliminaries
- In your comp2300 folder, create a new directory called
lab5.
- Copy the files /dept/dcs/comp2300/public/lab5/* into
your lab5 folder.
Important:
Peanut is currently only available on the student Solaris
server - please ssh login to 'iwaki' and start Peanut
in a terminal window with:
ssh -X iwaki
Peanut &
There are a number of questions marked with an asterix '*'. In
these questions you will be asked to explain or demonstrate something
to your tutor.
Conditionals
Open your copy of lab5a.mli with your favourite text editor.
This machine language initialisation file contains a program which
is supposed to have the following effect when executed:
- The numbers stored at a10 and a11 are added.
- The sum is compared to the number stored at a12.
- If the sum is less than or equal to the number stored at
a12, the character whose ASCII code is equal to the sum
is printed to the I/O window.
- Start a PeANUt simulator, and initialise it with lab5a.mli
(convert the file into an image file using the MLI-IMG
button). Execute the instructions. Does the instruction
sequence behave as specified?
- The machine language initialisation file is partly commented.
Analyse each line of the initialisation file and complete the
comment, or add useful comments, as necessary. Save your file.
- * If you think the initialisation file needs fixing in
order to conform to the specifications, make the appropriate
correction. Explain your decision to your tutor.
Repetition and Basic Output
The conditional statement you encountered in the previous section is
the basis for repetition. Instead of branching to the end, the branch
may be back to instructions already executed. In such a case, those
instructions would continue to be executed until the condition
(expressed in the conditional statement) no longer held.
- Close your lab5a.mli file and open lab5b.mli
in your favourite text editor. This file should initialise the
PeANUt so that when executed, it reads two characters from
input, the second of which must be a digit
('0' to '9'). It prints out the first character
x times, where x is the number represented by the digits.
e.g. for the input "X8", the program outputs "XXXXXXXX".
- Complete lab5b.mli by writing in appropriate
initialisation data (PeANUt instructions and data). You will
probably need page 5 of your PeANUt Specification.
- Test your code with a range of inputs.
- When you are satisfied that you have lab5b.mli
working, test it for correctness with the command:
previewAutoMark lab5 lab5b.mli
Note that the previewAutoMark command is only available
on DCS Linux hosts, i.e. do not try to run this command from iwaki.
When satisfied, submit it using the submit command:
submit comp2300 lab5 lab5b.mli
This is due by 10am Monday April 02 (the deadline is strict)
and will contribute up to 1% of your Tute/Lab mark.
Repetition and Indirect Addressing
In this section you will do an experiment that will use the
indirect addressing mode.
- Open lab5c.mli. This file should initialise the
PeANUt so that upon execution, a series of characters will be
printed out.
- Initialise the PeANUt with lab5c.mli. Execute the
instructions. What is the message?
- This code works by holding the address of the next character to
be printed in a memory location (a14, to be specific)
and then loading each character by performing an
indirect mode load with opspec = a14 (i.e.
AC = mem[mem[a14]]).
Use the Animate and Step buttons on the PeANUt
Tool to analyse the operation of this code. You may find it
useful to display the memory area where the string lives (from
a100 on) in the lower right window area. Change the
contents to ASCII to see the characters (highlight
regions of the memory box and use control right mouse
button to change how it is viewed). If you have
any trouble understanding how the code works, be sure to ask
your tutor for help.
- Create a new file, lab5d.mli (based on lab5c.mli)
that will print a specified portion to the character sequence
(using variable z to denote the starting character and
variable l to denote the number of characters). For example,
if z = 2 and l = 3, characters two, three and
four would be printed (note character zero is the first
character).
- Extension exercise:
Create a new file, lab5d.mli (based on lab5c.mli) that
will prints the original message with all instances of one character
(value stored in a0) with another (value stored in
a1). Note: you may need to use an ACSII
table to initialize these memory locations appropriately.
Last modified:
Fri Mar 23 18:24:00 EST 2007