Page 343 - Programming Microcontrollers in C
P. 343
328 Chapter 6 Large Microcontrollers
two types of overflow that can occur. The first is when an addition
operation, which should always add fractions, causes an overflow
from bit 30 to 31. This type of overflow is reversible because the
arithmetic that caused the overflow cannot cause more than a 1-bit
overflow error, and bits AM[34-31] are there to absorb this type of
overflow. The contents of this register are signed, so that bit 35 of AM
is the sign bit. The maximum value that can be placed in the 36-bit
AM register is 0x7ffffffff. This value has a decimal value of
15.999969482. The minimum value is 0x800000000 correspond
ing to –16. Whenever arithmetic involves the bits AM[34-31] the
EV bit will be set, and the program will know that the bits in
AM[35-31] are the signed integer part of the number. If successive
operations cause the overflow to disappear, the EV bit will be reset.
Another situation is less tractable. Suppose an overflow occurs as
a result of an arithmetic operation into the AM that causes bit 34 to
overflow into bit 35. This type of error is not reversible as is the case
above. When this overflow occurs, the MV bit is set to notify the pro
gram of the result. An internal latch known as the sign latch SL will
contain the value of A[35] after the overflow has occurred. There
fore, SL is the complement of the sign-bit when the overflow occurred.
To communicate with the DSP portion of the MC68HC16, we
have to use assembly language. In keeping with the basic rule to use C
whenever possible, the approach to be taken will be to create C-call-
able functions that access these important capabilities. What features
should we include in these functions? Obviously, all possible func
tions cannot be conceived. A set of functions that will embody the
most important features of the DSP capabilities will be written.
Let us examine how this compiler transfers parameters to a func
tion. When more than one parameter is passed, the parameters are
pushed on the stack starting with the right-most parameter in the
function argument list. The leftmost parameter is put into the D reg
ister. If a single parameter is passed, it is placed in the D register
prior to the function call. Within the function, the D and X register is
saved on the stack, and the stack pointer is decremented by an amount
needed to provide space for all of the function variables. At that point,
the stack pointer is transferred into the X register. An example of this
code is shown below. This little function receives three parameters
and merely puts these values into three local variable locations.