Motorola HC12 Refrence Manual page 378

Table of Contents

Advertisement

B.7.5 Minimum and Maximum Instructions
Control programs often need to restrict data values within upper and lower limits. The
CPU12 facilitates this function with 8- and 16-bit versions of MIN and MAX instruc-
tions. Each of these instructions has a version that stores the result in either the accu-
mulator or in memory.
For example, in a fuzzy logic inference program, rule evaluation consists of a series of
MIN and MAX operations. The min operation is used to determine the smallest rule
input (the running result is held in an accumulator), and the max operation is used to
store the largest rule truth value (in an accumulator) or the previous fuzzy output val-
ue (in a RAM location), to the fuzzy output in RAM. The following code demonstrates
how MIN and MAX instructions can be used to evaluate a rule with four inputs and
two outputs.
LDY
LDX
LDAA
MINA
MINA
MINA
MINA
MAXM
MAXM
Before this sequence is executed, the fuzzy outputs must be cleared to zeros (not
shown). M68HC11 MIN or MAX operations are performed by executing a compare
followed by a conditional branch around a load or store operation.
These instructions can also be used to limit a data value prior to using it as an input to
a table lookup or other routine. Suppose a table is valid for input values between $20
and $7F. An arbitrary input value can be tested against these limits and be replaced
by the largest legal value if it is too big, or the smallest legal value if too small using
the following two CPU12 instructions.
HILIMIT
LOWLIMIT FCB
The ",PCR" notation is also new for the CPU12. This notation indicates the program-
mer wants an appropriate offset from the PC reference to the memory location
(HILIMIT or LOWLIMIT in this example), and then to assemble this instruction into a
PC-relative indexed MIN or MAX instruction.
B.7.6 Fuzzy Logic Support
The CPU12 includes four instructions (MEM, REV, REVW, and WAV) specifically de-
signed to support fuzzy logic programs. These instructions have a very small impact
on the size of the CPU, and even less impact on the cost of a complete MCU. At the
same time these instructions dramatically reduce the object code size and execution
time for a fuzzy logic inference program. A kernel written for the M68HC11 required
about 250 bytes and executed in about 750 milliseconds. The CPU12 kernel uses
about 50 bytes and executes in about 50 microseconds.
MOTOROLA
B-14
#OUT1
;Point at first output
#IN1
;Point at first input value
#$FF
;start with largest 8-bit number in A
1,X+
;A=MIN(A,IN1)
1,X+
;A=MIN(A,IN2)
1,X+
;A=MIN(A,IN3)
1,X+
;A=MIN(A,IN4) so A holds smallest input
1,Y+
;OUT1=MAX(A,OUT1) and A is unchanged
1,Y+
;OUT1=MAX(A,OUT2) A still has min input
FCB
$7F
$20
MINA
HILIMIT,PCR ;A=MIN(A,$7F)
MAXA
LOWLIMIT,PCR;A=MAX(A,$20)
M68HC11 TO M68HC12 UPGRADE PATH
;comparison value needs to be in mem
;so it can be referenced via indexed
;A now within the legal range $20 to $7F
CPU12
REFERENCE MANUAL

Advertisement

Table of Contents
loading

This manual is also suitable for:

Cpu12

Table of Contents