Page 74 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 74
2.8 Remarks 51
Figure 2.23. Program Segment for a Multiply and Add Operation
The TBL and ETBL instructions perform 8-bit and 16-bit table lookup and
interpolation. TBL puts into accumulator A the value (E) + (B * ((E+l) - E)) where E is
the effective address, which can be the pointer address as in EMAXD, and B is
accumulator B, considered as an unsigned fraction. CMPB can search a list of values,
which are in increasing order, for the nearest value just below, and B and TBL can
interpolate between that value and the next higher value. ETBL is similar but is for 16-
bit unsigned number interpolation: It puts into accumulator D the value (E):(E+1) + (B *
((E+2):(E+2) - E:(E+1))). The CPD instruction can search a list of values to use ETBL.
The instructions MEM, REVW, REV, and WAV are used for fuzzy logic rule
evaluations, which are developed in §7.6. These highly specific and efficient operations
make the 6812 singularly well-suited to fuzzy logic control applications.
The fuzzy logic membership instruction MEM uses accumulator A as the current
input, and X points to a 4-byte data structure that describes a trapezoidal membership
function (PI, P2, SI, S2). The instruction puts into the byte pointed to by Y, the
function value, and then adds 4 to X and 1 to Y to access the next trapezoid and output
value. If A < PI or A > P2, then the output function value is 0, or else the output
function value is MIN(A - PI) * SI, (P2 - A) * S2, $FF).
REV and REVW perform min-max rule evaluation for 8-bit and 16-bit unsigned
numbers. For REV, each rule input is an 8-bit offset from the base address in Y. Each
rule output is an 8-bit offset from the base address in Y. $FE separates rule inputs from
rule outputs, and $FF terminates the rule list. REV may be interrupted. For REVW, each
rule input is the 16-bit address of a fuzzy input. Each rule output is the 16-bit address of
a fuzzy output. The value $FFFE separates rule inputs from rule outputs, and $FFFF
terminates the rule list. REV and REVW use this MIN-MAX rule: Find the smallest rule
input (MIN), and store to rule outputs unless fuzzy output is already larger (MAX).
WAV calculates the sum-of-products and sum-of-weights for a list of 8-bit unsigned
elements. Accumulator B is the number of elements in both lists, X points to the first
list, and Y points to the second list. The sum-of-products is put in registers Y (high-
order 16 bits) and D (low-order 16 bits), and the sum of weights, pointed to by Y, is put
into register X. The instruction wavr resumes the execution of the WAV instruction if it
is interrupted in the middle of its execution.
2.8 Remarks
One might wonder why some move instructions, such as LDAA, TSTA, and STAA,
always put V = 0 rather than leaving V unchanged as they do C. The reason is that doing
so allows all of the signed branches to work after these instructions as well as after the