ASSEMBLY LANGUAGE COURSE PART VI by Mark van den Boer
Shift and Rotate Operations
Instruction: ASL
Syntax: ASL #,Dn (the immediate operand always modulo 8)
ASL Dn,Dn (the first operand always modulo 8)
ASL <ea>
Data sizes: byte, word, long except for ASL <ea> which only
allows word and long as data sizes.
Condition codes affected:
X set to the last bit shifted out
N set to the most significant bit of the result
Z set if the result is zero, cleared otherwise
V set if the most significant bit is changed
during the operation
C see the X-bit
Addressing modes allowed with the ASL <ea> instruction:
Destination:
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
Function: Perform a shift left of the destination operand. This
instruction can be used as a fast form of multiplying an
operand with a power of two. On a processor like the
6502 this instruction is the only way to perform a
multiply operation. The lower bit of the destination is
always set to zero.
Examples:
Instruction Before After
ASL.L d0,d1 d0=33333333 d0=33333333
d1=00000005 d1=00000028
ASL.W $4ee $4ee=0009 $4ee=0012
Instruction: ASR
Syntax: ASR #,Dn (the immediate operand always modulo 8)
ASR Dn,Dn (the first operand always modulo 8)
ASR <ea>
Data sizes: byte, word, long except for ASR <ea> which only
allows word and long as data sizes.
Condition codes affected:
X set to the last bit shifted out
N set to the most significant bit of the result
Z set if the result is zero, cleared otherwise
V set if the most significant bit is changed
during the operation
C see the X-bit
Addressing modes allowed with the ASR <ea> instruction:
Destination:
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
Function: Perform a shift right of the destination operand. This
instruction can be used as a fast form of dividing an
operand with a power of two. On a processor like the
6502 this instruction is the only way to perform a
divide operation. The upper bit (sign bit) is always
repeated.
Examples:
Instruction Before After
ASR.L d0,d1 d0=33333333 d0=33333333
d1=00000005 d1=00000002
ASR.W $4ee $4ee=8009 $4ee=c004
Instruction: LSL
See the ASL instruction. The LSL instruction is exactly the same.
At the moment I haven't got the machine codes for the ASL and LSL
operations but I think that even the machine codes are the same.
E.g. on the 6809 both ASL and LSL exist but translate to the same
machine code.
Instruction: LSR
Syntax: LSR #,Dn (the immediate operand always modulo 8)
LSR Dn,Dn (the first operand always modulo 8)
LSR <ea>
Data sizes: byte, word, long except for LSR <ea> which only
allows word and long as data sizes.
Condition codes affected:
X set to the last bit shifted out
N set to the most significant bit of the result
Z set if the result is zero, cleared otherwise
V set if the most significant bit is changed
during the operation
C see the X-bit
Addressing modes allowed with the LSR <ea> instruction:
Destination:
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
Function: Perform a shift right of the destination operand. This
instruction differs from ASR in that the high order bit
is always cleared.
Examples:
Instruction Before After
LSR.L d0,d1 d0=33333333 d0=33333333
d1=00000005 d1=00000002
LSR.W $4ee $4ee=0009 $4ee=0004
Instruction: ROL
Syntax: ROL #,Dn (the immediate operand always modulo 8)
ROL Dn,Dn (the first operand always modulo 8)
ROL <ea>
Data sizes: byte, word, long
Condition codes affected:
X not affected
N set to the most significant bit of the result
Z set if the result is zero, cleared otherwise
V always cleared
C set to the last bit shifted out the operand
Addressing modes allowed with the ROL <ea> instruction:
Destination:
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
Function: Perform a bitwise rotate left of the destination
operand.
Examples:
Instruction Before After
ROL.L d0,d1 d0=00000001 d0=00000001
d1=88000001 d1=10000002 (C bit set)
ROL.W $4ee $4ee=8009 $4ee=0012
Instruction: ROR
Syntax: ROR #,Dn (the immediate operand always modulo 8)
ROR Dn,Dn (the first operand always modulo 8)
ROR <ea>
Data sizes: byte, word, long
Condition codes affected:
X not affected
N set to the most significant bit of the result
Z set if the result is zero, cleared otherwise
V always cleared
C set to the last bit shifted out the operand
Addressing modes allowed with the ROR <ea> instruction:
Destination:
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
Function: Perform a bitwise rotate right of the destination
operand.
Examples:
Instruction Before After
ROR.L d0,d1 d0=00000001 d0=00000001
d1=88000001 d1=c4000000 (C bit set)
ROR.W $4ee $4ee=8009 $4ee=c004
Instruction: ROXL
Syntax: ROXL #,Dn (the immediate operand always modulo 8)
ROXL Dn,Dn (the first operand always modulo 8)
ROXL <ea>
Data sizes: byte, word, long
Condition codes affected:
X set to the last bit shifted out the operand
N set to the most significant bit of the result
Z set if the result is zero, cleared otherwise
V always cleared
C set to the last bit shifted out the operand
Addressing modes allowed with the ROXL <ea> instruction:
Destination:
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
Function: Perform a bitwise rotate left of the destination
operand. There is very little difference with the ROL
instruction. By the way, it is very handy to have a
wordprocessor with cut/paste and find/replace
facilities. All I did was cut out the complete ROL
instruction and replaced all ROL's by ROXL's.
Examples:
Instruction Before After
ROXL.L d0,d1 d0=00000001 d0=00000001
d1=88000001 d1=10000002
ROXL.W $4ee $4ee=8009 $4ee=0012
Instruction: ROXR
Syntax: ROXR #,Dn (the immediate operand always modulo 8)
ROXR Dn,Dn (the first operand always modulo 8)
ROXR <ea>
Data sizes: byte, word, long
Condition codes affected:
X set to the last bit shifted out the operand
N set to the most significant bit of the result
Z set if the result is zero, cleared otherwise
V always cleared
C set to the last bit shifted out the operand
Addressing modes allowed with the ROXR <ea> instruction:
Destination:
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
Function: Perform a bitwise rotate right of the destination
operand. There is very little difference with the ROR
instruction. By the way, it is very handy to have a
wordprocessor with cut/paste and find/replace
facilities. All I did was cut out the complete ROXL
instruction and replaced all ROXL's by ROXR's.
Examples:
Instruction Before After
ROXR.L d0,d1 d0=00000001 d0=00000001
d1=88000001 d1=10000002
ROXR.W $4ee $4ee=8009 $4ee=0012
Disclaimer
The text of the articles is identical to the originals like they appeared
in old ST NEWS issues. Please take into consideration that the author(s)
was (were) a lot younger and less responsible back then. So bad jokes,
bad English, youthful arrogance, insults, bravura, over-crediting and
tastelessness should be taken with at least a grain of salt. Any contact
and/or payment information, as well as deadlines/release dates of any
kind should be regarded as outdated. Due to the fact that these pages are
not actually contained in an Atari executable here, references to scroll
texts, featured demo screens and hidden articles may also be irrelevant.