Logical instructions , shift and rotate instructions , bit manipulation instructions and binary-coded-decimal instructions

10.6.1 Logical Instructions

These instructions include logical OR, EOR, AND, and NOT as shown in Table 10.7.

• Consider AND. B # $8 F, DO . If prior to execution of this instruction, [DO.B] = $72, then after execution of AND. B # $ 8 F, D0, the following result is obtained:

imageZ = 0 (Result is nonzero) and N = 0 (Most Significant Bit of the result is 0). C and V are always cleared to 0 after logic operation. The condition codes are similarly affected after execution of other logical instructions such as OR, EOR, and NOT. The AND instruction can be used to perform a masking operation. If the bit value in a particular bit position is desired in a word, the word can be logically ANDed with appropriate data to accomplish this. For example, the bit value at bit 2 of an 8- bit number 0100 IY10 (where unknown bit value ofY is to be determined) can be obtained as follows:

image

If the bit value Y at bit 2 is 1, then the result is nonzero (Flag Z=O); otherwise, the result is zero (Z= 1) . The Z flag can be tested using typical conditional ru MP instructions such as BEQ (Branch if Z= 1) or BNE (Branch if Z=O) to determine

image

whether Y is 0 or I. This is called masking operation. The AND instruction can also be used to determine whether a binary number is ODD or EVEN by checking the Least Significant bit (LSB) of the number (LS8=0 for even and LS8=1 for odd).

image

execution of this EOR, register D2.W will contain 0000 16, and Dl will remain unchanged at FFFF 16

• Consider NOT. B 05. If [D5.B] = 02 16,then, after execution of this NOT, the low byte ofD5 will contain FD 16

• Consider OR. B 02, D3 . If prior to execution of this instruction, [D2.B] = A2 16 and lD3.B] = 5D16, then after exection of OR. B 02, 03, the contents of D3.B are FFH. All flags are affected similar to the AND instruction. The OR instruction can typically be used to insert a 1 in a particular bit position of a binary number without changing the values of the other bits. For example, a 1 can be inserted using the OR instruction at bit number 3 of the 8-bit binary number 0 1 1 1 0 0 1 1 without changing the values of the other bits as follows:

image

10.6.2 Shift and Rotate Instructions

The 68000 shift and rotate instruction are listed in Table I0.8.

• All the instructions in Table 10.8 affect Nand Z flags according to the result. Vis reset to zero except for ASL.

• Note that in the 68000 there is no true arithmetic shift left instruction. In true arithmetic shifts, the sign bit of the number being shifted is retained. In the 68000, the instruction ASL does not retain the sign bit, whereas the instruction ASR retains the sign bit after performing the arithmetic shift operation.

image

image

image

• (EA) in ASL, ASR, LSL, LSR, ROL, ROR, ROXL, and ROXR can use all modes except Dn, An, relative, and immediate.

• Consider ASL. W Dl, 05. If [D1]1ow 16 bits = 0002 16 and [D5]1ow 16 bits = 9FF0 16, then, after this ASL instruction, [D5]10w l6bits = 7FC016, C = 0, and X= 0. Note that the sign of the contents of D5 is changed from 1 to 0 and, therefore, the overflow is set. The sign bit of D5 is changed after shifting [D5] twice. For ASL, the overflow flag is set to one if the sign bit changes during or after shifting. The contents of D5 are not updated after each shift. The ASL instruction can be used to multiply a signed number by 2" by shifting the number n times to the left; the result is correct if V = 0 while the result is incorrect if V = 1. Since execution time of the multiplication instruction is longer, multiplication by shifting may be more efficient when multiplication of a signed number by 2" is desired.

• ASR retains the sign bit. For example, consider ASR. W #2, Dl. If[D1.W] = FFE2 16, then, after this ASR, the low 16 bits of [D1] = FFF8 16, C = 1, and X = 1. Note that the sign bit is retained.

• ASL (EA) or ASR (EA) shifts (EA) 1 bit to left or right, respectively. For example, consider ASL. W (AO). If [AO] = 00002000 16 and [00200016] = 9001 16, then, after execution of this ASL, [00200016] = 2002 16, X= 1, and C = 1. On the other hand, after ASR. w (AO), memory location 002000 16 will contain C80016, C = 1, and X= I.

• The LSL and ASL instructions are the same in the 68000 except that with the ASL, V is set to 1 if the sign of the result is changed from the sign of the original value during or after shifting. This will allow one to multiply a signed number by 2" by shifting the number n times to left; the result is correct if V = 0 while the result is incorrect if V = 1. Since execution time of the multiplication instruction is longer, multiplication by shifting may be more efficient when multiplication of a signed number by 2" is desired.

image

10.6.3 Bit Manipulation Instructions

The 68000 has four bit manipulation instructions, and these are listed in Table 10.9.

10.6.4 Binary-Coded-Decimal Instructions

The 68000 instruction set contains three BCD instructions, namely, ABCD for adding, SBCO for subtracting, and NBCO for negating. They operate on packed BCD byte(s) and provide the result containing one packed BCD byte. These instructions always include the

image

extend (X) bit in the operation. The BCD instructions are listed in Table 10.10.

Note that packed BCD subtraction used in the instructions SBCO and NBCO can be obtained

by using the concepts discussed in Chapter 2 (Section 2.5.2).

Labels: