Special Instructions (Microcontrollers)

2.7
Table 2.10 lists 6812′s special instructions, which are arithmetic instructions of primary interest in fuzzy logic. They use index addressing, which is discussed in the next topic. Fuzzy logic uses minimum and maximum functions to logically AND and OR fuzzy variables. The 6812 has instructions max a, maxm, mina, minm, emaxd, emaxm. emind, and eminm to determine the maximum or minimum of an 8-bit or a 16-bit pair of unsigned numbers, one of which is in a register (A or D) and the other of which is one or two bytes at the effective address, and to put the maximum or minimum
Table 2.10. Special Instructions
Special Instructions
in either the register or the memory at the effective address. EMACS is a multiply-and-accumulate instruction similar to such instructions used in digital signal processors (DSPs).
The following examples use pointer addressing, in which the effective address is the contents of an index register, without adding any other value to it.
We are about to output the contents of accumulator D to an output device, but the output must be limited to be at least Vmin, and at most Vmax. Suppose location $803 has the address of Vmax and location $805 has the address of Vmin. Pointer addressing (§3.2) is one of the modes usable with the EMAXD and EMIND instructions. Figure 2.22 limits the value of accumulator D to be Vmin s D sVmax.
Figure 2.23 illustrates the use of index registers in the multiply-and-accumulate instruction to evaluate the expression: A = A + (B * C), where A is a signed 32-bit number at $910, B is a signed 16-bit number at $914, and C is a signed 16-bit number at $916. Pointer addressing is the only mode that can be used with the EMACS instruction. From Table 2.10, the EMACS instruction executes the expression (X):(X+1) x (Y):(Y+1) + (E):(E+l):(E+2):(E+3) -> (E):(E+l):(E+2):(E+3); from the CPU12RG/D manual, it executes this operation in thirteen clock cycles, a little under 2 /<sec.
Program Segment for Ensuring a Value Is between Limits
Figure 2.22. Program Segment for Ensuring a Value Is between Limits
Program Segment for a Multiply and Add Operation
Figure 2.23. Program Segment for a Multiply and Add Operation
The TBL and BTBL 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+t) + (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 SFFFF 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.


Next post:

Previous post: