LAB 4

advertisement
EEM489 MICROPROCESSSORS II
M68K LAB 2 – FALL 2007-08
MATHEMATICAL INSTRUCTIONS
This second lab will be about the extension of the mathematical capabilities of M68K.
As a 16-bit (!) microprocessor, 68K is capable of performing complicated
mathematical operations with ease and speed. And with the combination of these
mathematical instructions we can operate on larger numbers.
2.1
Extension of multiplication
In the first part of the lab, You are going to perform a multiple-precision
multiplication by extending capabilities of MULU and MULS instructions from 16-bits
to 32-bits. Since the multiplicand and the multiplier will be 32-bit long the result will
be 64-bit long, and to store this result a 64-bit register will be needed. And since no
64-bit registers is available in 68K architecture you can synthesize it by
concatenating two 32-bit data registers and use of the X-bit (remember the use of Xbit in previous lab).
You can test your implementation by performing this operation (the calculation of the
length of a light year in kilometers):
299,792 x 31,558,464 = 9460975039488 or in hex;
$49310 x $1E18B40 = $89ACE0E7400
2.2
Calculating the mean (average) of a vector (number array)
You are required to implement a function, i.e. a subroutine, to calculate the mean.
The function will calculate the mean of a vector and it will execute according to the
input parameters which will be passed to it. You will possibly need to use a data
register to pass the vector size, or you can use stack. Another input parameter of the
function will be only one address value which points to the start address of the data
set. And it is important to state that each number in the data set must be considered
to be 16-bit length. It will be easy to handle, if you directly pre-download the data
set to a specific memory location by writing and assembling it with your assembly
code.
As a conclusion to the above parameter passing requirements, it is obvious that you
need to develop your function capable of handling a vector (array) of any size. You
can develop your program to handle vectors with fixed size. But this will bring a very
little performance grade.
Another requirement of your function is that, it must return a value according to the
number of vectors and size. This return value must be held by a data register. When
the size of the vector is entered to be zero, i.e. the value of the data register that is
passed to the function, the return value will be “-1”. Otherwise low order word of this
data register contains “0” if the sum of the elements of the vector (not the result of
the average calculation) can be contained in 16-bits, or “+1” if the sum requires 32bits.
During the lab session, be ready to be asked to make any modifications to the above
programs…
Also, you will call the subroutines that you wrote in an upper (parent/main) routine.
Hence try to pass parameters on the stack before calling the subroutine. Remember
that (most of) you experienced passing the parameters in registers in the previous
lab. And force your subroutines to be transparent and reentrant (Look at class notes
week05). Take care of your codes-subroutines-programs in proceeding labs to be
dynamic, transparent and reentrant. This will help you be better coders.
For example, the C-version of extended multiplication may be as following;
void mult_ext(long &number1, long &number2);
void mult_ext(long number1, long number2);
(1)
(2)
this can be interpreted as following: two input parameters will be passed into the
function (or subroutine). These are pointers (or addresses) of two 32-bit numbers to
be multiplied (1). Or we pass two numbers themselves as input parameters (2). The
output maybe the address of 64-bit result stored in a memory address or the 64-bit
number itself returned in two data registers or the 64-bit number passed on the
stack. For dynamic codes, passing the input/output parameters in registers or on
stack is important.
2.3
Stack and Local Variables
The objective of this part is to implement the use of the stack frames by using a
complementary pair of instructions, LINK and UNLNK.
So far we have covered how the parameters are passed to the subroutines with the
use of the stack. What a subroutine also needs is a local workspace for the
temporary variables that it makes use of. This local workspace is private to that
subroutine and it is not accessed by another subroutine. You must be familiar with
this concept from the high level programming languages. In a high level
programming language, none of the local variables of a function can be accessed
outside the scope of that function.
If a subroutine (i.e. a function in a high level language) is to be made reentrant or is
to be used recursively, a new workspace must be assigned to it each time the
subroutine is called. This is implemented in assembly language with dynamic storage
techniques which makes use of the stack frames (SF) and frame pointers (FP).
In this lab you are asked to develop a subroutine named “exp” which will be called
from the main program to perform the calculation below.

xi
x2 x3 x4
e 
 1 x 


 ...
2! 3! 4!
n  0 n!
x
To handle this calculation easily, you will be permitted to perform the series
operation above, up to a predefined index value (N), not up to infinity. So it is
obvious that, in addition to the value of x and the address of the result, an input
value for the index will be needed. Of course you are supposed to pass these three
input variables using the stack. Also the result will have to be written into a
predefined memory location (label it as OUTPTR) before returning from the
subroutine. You are not supposed to implement two more subroutines which will be
called from “exp” subroutine to perform the power and factorial calculations, but if
you want if you may. When you implement two more subroutines for power and
factorial calculations, be careful to handle stack frames also for those subroutines.
An important requirement of the implementation is that, you need to use stack
frames, as told in the note submitted with this manual (modular.pdf). On pages 9
and 10, an example program exists which uses the stack frames. The technique you
are asked to follow for the implementation of the above series is the same which is
demonstrated in that example.
For the implementation, you are not supposed to perform any floating-point
calculations. In fact, you will not be able to perform a floating-point calculation with
this processor, that’s why there exist neither any floating-point instructions, nor any
floating-point library. But it is recommended to use 32-bit fixed-point numbers to
prevent overflows in the calculations.
During the lab, the values for the input parameters x, index n and the memory
location for the output will be given to you. But the two input parameters will not be
very big numbers in order not to cause any overflow. Also, you will never be asked
to perform any signed mathematical operation in this implementation.
You can temporarily try the values x = 2 or 3 or 4, N = 3 or 4 or 5, and the memory
location labeled as INPUTPTR = $00400700. The result address (labeled as OUTPTR)
may be chosen as $00400710.
A full performance for this lab will include submission of the memory dump that
demonstrates how the stack is used. During the lab, you will only be asked to
perform the calculation and show your work, the memory dump of the stack usage
will be a part of your report. After showing that your code works correctly, you may
take the memory dump by using the monitor program and copy it to the Wordpad to
take the printout. On this printout of the memory dump, you are supposed to
indicate the stack usage clearly. Another important point is that, you also will be
supposed to submit the softcopies of your assembly codes in addition to the report.
So, you possibly got the point that, the hardcopies of your codes and the resulting
memory dump with your explanations and comments will be your reports, while the
softcopies of your codes will be checked whether you submitted a working program.
On completion of the requirement of this manual, you will be asked to perform one
more, quite easy step to practice on stack frames.
LAB GRADINGS (Bring a print-out of this page to your teaching assistant
TA)
Student Name:
2.1 Extension of multiplication
Calculation correct?
2.2 Calculating mean of a vector
Dynamic vector size
Handling exceptions (the return value)
2.3 Stack and local variables
Error tolerance of the calculation (number of terms):
Is reentrant?
Is recursive?
Stack usage demonstration (in report)
Download