|
|
COMP2300 - TuteLab 07
COMP2300 / COMP6300
Tutorial / Laboratory 07 -
Bit operations and Address Parameters in PeANUt Assembler
Semester 1, 2009
Week 8 (28 April - 01 May)
Note that for this session, there is a submittable laboratory exercise
which is due by 09 am Tuesday 05 May (week 9), which will contribute
up to 1% of your assessment (in the Tute/Lab mark).
While there is no formal Preparation Exercises, please consider
what you would like to cover in Tutorial Question 1 beforehand, and
revise your PeANUt on procedure calls and bit operations.
Objectives
There are several objectives in this session:
- To review and tutorial or laboratory exercises of the course so far,
and to review the Mid-semester Exam.
- To deepen your understanding of procedures and address parameters,
as well as bit operations in PeANUt.
Tutorial Exercises
- Revise a selection of questions from previous tutorials or
laboratory exercises, or the
Mid-semester Exam
(the class to collectively decide which - come prepared if you want
your questions to be nominated!).
- How could you use the array short int powers2[16], where
powers2[i] = 2i, to shift 16-bit bit patterns left
or right by n bits (where 0 <= n < 16)? In other
words, how could you use it to translate the following C code into assembler:
short int a, b, x, n;
...
a = x << n;
b = x >> n;
What if n > 15? What are other ways this shifting can be achieved
in PeANUt?
-
Translate the following C code into PeANUt assembler.
short int a, b, x, n;
...
a = x & (0xf << 4);
b = x | n;
Laboratory Exercises
Preliminaries
- In your comp2300 directory, create a new sub-directory
called lab7.
- Copy the files /dept/dcs/comp2300/public/lab7/* into
your lab7 directory.
- Start up a terminal window and cd to your lab7
directory. Then start up the PeANUt simulator.
Bit Operations and Address Parameters
In this part we are working with the files swapbits.ass and
bitswap.ass. Assembled into swapbits.img (as shown below),
this program inputs a character, prints it out in character and hexadecimal
form, and prints out the character with bits 0..3 and bits 4..7 swapped.
- Assemble and link the (initial version of the)
swapbits.img program using the shell commands:
assemble bitswap.ass
assemble swapbits.ass
join swapbits.rel bitswap.rel
InOut.rel
- Start the PeANUt simulator and load swapbits.img.
Execute the program, entering a line with a single character
(e.g. 2, B or %).
- Start your favourite text editor and load the file
bitswap.ass. Add the code for the call to
SwapBits() in bitswap.ass, and re-assemble, link
and load swapbits.img as done in step 1 above.
Note that the instruction loada ch can be used to put the
address of ch into the PeANUt accumulator
AC.
- Single step through the execution of swapbits.img, and
ensure that the address of ch appears on the expected
place on the stack when the call instruction is executed.
- Now load the file swapbits.ass into your editor.
Assume that the local variables xH and xL are
implemented by the stack, and the local variable xtmp
is implemented via a block directive (so that it is
accessed via direct mode rather than stack mode, and hence can
be used as an operand to a PeANUt logical instruction).
By how much should the stack pointer be incremented upon entry
into the SwapBits() procedure (and similarly decremented
upon exit)?
- What stack displacements should then be given to the parameter
x and local variables xL and xH in
SwapBits()? Check your answers with your tutor.
- Add the (concise) macros to define the stack displacements for
these local variables. Add the code in the body of SwapBits()
corresponding to the manipulation of the stack pointer for the
local variables, and for the statement xtmp = *x;.
- Now re-assemble, re-link and re-load swapbits.img, run
it in single step mode (or with break points set at the entry
and exit points of the procedure). Verify that xtmp has
indeed received the correct value of the char * parameter.
Note: It may be useful to set the format of the memory
location corresponding to ch and xtmp to hex.
Check that xtmp has received the correct value, and that
the proper return from the procedure has been achieved.
- Translate the next 3 assignment statements from SwapBits()
into assembler. Be careful that you have used the appropriate
addressing modes at each point. Re-assemble and re-link the
program.
It may again be useful to set the format of the memory locations
corresponding to xL and xH to hex.
Again execute in single step mode to check that the bit operations
have been correctly implemented.
- Now translate the final assignment statement into assembler, and
re-assemble, re-link and re-run the program. The program output
should make it obvious whether your additions have been correct.
- When you are satisfied, check your work with your tutor.
- When you are satisfied that you have your program
working, test it for correctness with the command:
previewAutoMark lab7 swapbits.ass
When satisfied, submit it using the submit command:
submit comp2300 lab7 swapbits.ass
submit comp6300 lab7 swapbits.ass
This is due by 09 am Tuesday May 05 (the deadline is strict)
and will contribute up to 1% of your Tute/Lab mark.
Last modified: 23/04/2009, 17:04
|