
Logical, Shift and Rotate Instructions 157
The rotate instructions have the same format as the shift instructions.
<rotate>[.<size>] Dx,Dy
<rotate>[.<size>l #<data>,Dy
<rotate>[.W] <ea>
<rotate> = ROL, ROR, ROXL, ROXR
<size> = B, W, L
<data> = 1-8
The following subroutine, OUTHEX, demonstrates the use of a rotate
instruction and a logical instruction to output the contents of the DO regis
ter as a hexadecimal number.
OUTHEXI MOVE.L DO,-(SP)
MOVE.L
Dl,— (SP)
MOVEQ
#7,D1
OUTL1:
ROL.L *4,DO
JSR
OUTDIG
DBRA
Dl,OUTL1
MOVE.L
(SP)+,D1
MOVE.L
RTS
(SP)+,D0
*
OUTDIGs
MOVE.L
D0,-(SP)
ANDI.L #$F,D0
CMPI.B *9,DO
BLS OUTD1
ADDI.B #*A'-'0'-10,D0
OUTD1: ADDI.B
#'0',D0
JSR
RTS
PUTC
SAVE REG. VALUES
f9
8 NIBBLES
ROTATE NIBBLE INTO PLACE
OUTPUT NIBBLE
LOOP UNTIL DONE
RESTORE REGS.
19
RETURN
SAVE DO
ISOLATE NIBBLE
>9?
NO
YES, MAKE A-P
MAKE DIG. INTO ASCII
OUTPUT DIGIT
RETURN
The subroutine OUTDIG is used to convert a 4-bit hexadecimal digit to
its ASCII character value. Since a hexadecimal digit can range from 0 to
9 and A to F, a check must be made to ensure that the proper ASCII
character value is selected for digits with decimal values between 10 and
15. In OUTHEX, a rotate instruction rather than a shift instruction is used,
since the digits must be output starting with the high-order digit. The left
rotate accomplishes this quite nicely.
Bit Manipulation
Sometimes we desire to manipulate only one bit in a byte, word,
or longword. While it is possible to use the logical instructions for this
purpose, it is much easier to use a special group of instructions known as
the bit manipulation instructions. There are four of them: BTST, BSET,
BCLR, and BCHG. They all have the same general form:
Komentáře k této Příručce