CONTINUATION OF THE COURSE ON INSTRUCTIONS from the INSTRUC.DOC file
LSL #BBB,dn (.B),[.W],(.L) (Logical Shift Left)
--------------
or
LSL dm,dn (.B),[.W],(.L)
--------------
or
LSL.W destination (.W)
------------------
Performs a shift of #BBB or dm (depending on the syntax) BITS
of the data register dn to the left.
The replacement bits are ZEROS.
It is necessary that 1<= #BBB <= 8 for the 1st form.
-------------
For the 3rd form, the allowed addressing modes for the
destination operand are:
-----------
BBBB
BB
(an)
-(an)
(an)+
d(an)
d(an,rn)
But in this case, the operation can only shift
1 SINGLE BIT.
For example, if d0=%10000101110001101111011100000110 (word)
------
And if I write LSL.W #1,dn
or MOVE.W #1,d1
LSL.W d1,d0, we get:
d0=%00001011100011011110111000001100
<-------- <--:0
All the bits of the lower WORD of the data register dn (.W)
have been shifted by 1 bit to the left:
The least significant bit entering is always replaced by a
NULL bit.
Meaning: #BBB or dm BITS are shifted out of dn to the left and the
replacement bits entering on the right of dn are NULL BITS.
The contents of dn are therefore changed, the MSB is also likely to change,
that's why the SIGN of dn may not necessarily be preserved.
The CCR will change according to the new value of dn.
---
N=1 if the MSB is 1, otherwise it is 0
Z=1 if all bits of dn are null, otherwise it is 0
V is always set to 0
C and X are set to the value of the LAST BIT EXITED from dn.
Example of use:
----------------------
MOVE #%1111111101010101,d0
LSL.B #5,d0
A shift of 5 bits of the lower BYTE of d0 is operated
(only bits 0 to 7 of d0 are therefore concerned by lsl.B)
We get:
CCR --------<------<:0
X=C=0 <- 1111111110100000 in d0
5 null bits have entered the right of the lower byte of d0, the
last bit to exit from d0 was null: bit X=C=0 in the CCR
LSR #BBB,dn (.B),[.W],(.L) (Logical Shift Right)
--------------
or
LSR dm,dn (.B),[.W],(.L)
--------------
or
LSR.W destination (.W)
------------------
Performs a shift of #BBB or dm (depending on the syntax) BITS
of the data register dn to the right.
The replacement bits are ZEROS.
It is necessary that 1<= #BBB <= 8 for the 1st form.
-------------
For the 3rd form, the allowed addressing modes for the
destination operand are:
-----------
BBBB
BB
(an)
-(an)
(an)+
d(an)
d(an,rn)
But in this case, the operation can only shift
1 SINGLE BIT.
For example, if d0=%10000101110001101111011100000110 (word)
------
And if I write LSR.W #1,dn
or MOVE.W #1,d1
LSR.W d1,d0, we get:
d0=%01000010111000110111101110000011
0:--> ------->
All the bits of the lower WORD of the data register dn (.W)
have been shifted by 1 bit to the right:
The most significant bit entering is always replaced by a
NULL bit.
Meaning: #BBB or dm BITS are shifted out of dn to the right and the
replacement bits entering on the left of dn are NULL BITS.
The contents of dn are therefore changed, the MSB is also likely to change,
that's why the SIGN of dn may not necessarily be preserved.
The CCR will change according to the new value of dn.
---
N=1 if the MSB is 1, otherwise it is 0
Z=1 if all bits of dn are null, otherwise it is 0
V is always set to 0
C and X are set to the value of the LAST BIT EXITED from dn.
Example of use:
----------------------
MOVE #%1111111101010101,d0
LSR.B #5,d0
A shift of 5 bits of the lower BYTE of d0 is operated.
(only bits 0 to 7 of d0 are therefore concerned by lsr.B)
We get:
------0:>------> CCR
d0 :1111111100000010 -> X=C=1
5 null bits have entered the left of the lower byte of d0, the
last bit to exit from d0 was 1: bit X=C=1 in the CCR
ASL #BBB,dn (.B),[.W],(.L) (Arithmetic Shift Left)
--------------
or
ASL dm,dn (.B),[.W],(.L)
--------------
or
ASL.W destination (.W)
------------------
This instruction is identical to LSL.
However, with ASL, the V bit of the CCR is set to 1 if the MSB of the
destination operand is changed.
---
ASR #BBB,dn (.B),[.W],(.L) (Arithmetic Shift Right)
--------------
or
ASR dm,dn (.B),[.W],(.L)
--------------
or
ASR.W destination (.W)
------------------
Performs a shift of #BBB or dm (depending on the syntax) BITS
of the data register dn to the right.
The replacement bits are equal to the most significant bit.
It is necessary that 1<= #BBB <= 8 for the 1st form.
-------------
For the 3rd form, the allowed addressing modes for the
destination operand are:
-----------
BBBB
BB
(an)
-(an)
(an)+
d(an)
d(an,rn)
But in this case, the operation can only rotate
1 SINGLE BIT.
For example, if d0=%10000101110001101111011100000110 (word)
------
MSB=1
And if I write ASR.W #1,dn
or MOVE.W #1,d1
ASR.W d1,d0, we get:
d0=%11000010111000110111101110000011
MSB=1:--> ------->
All the bits of the lower WORD of the data register dn (.W)
have been shifted by 1 bit to the right:
The least significant bit exits on the right.
The replacement bit is identical to the MSB preceding the rotation.
Meaning: #BBB or dm BITS are shifted out of dn to the right and they
enter bits equal to the most significant bit on the left, in place
of the missing bit.
The contents of dn are therefore changed but its SIGN is PRESERVED because the
MSB remains unchanged.
The CCR will change according to the new value of dn.
---
N=1 if the MSB is 1, otherwise it is 0
Z=1 if all bits of dn are null, otherwise it is 0
V is set to 1 if the MSB of the destination operand has been changed.
C and X are set to the value of the LAST BIT EXITED from dn.
Example of use:
----------------------
MOVE #%1111111101010101,d0
ASR.W #5,d0
bit nr°15=1
A shift of 5 bits of the lower WORD of d0 is operated.
(only bits 0 to 15 of d0 are therefore concerned by asr.W)
We get:
MSB>---------------> CCR
d0 :1111111111111010 -> X=C=1 at the end
5 bits are shifted out to the right of the lower WORD of d0 and we
placed successively 5 bits equal to 1 (bit nr°15=1) in place of the
most significant bit of the WORD.
The sign of d0 remains preserved.
The last bit to exit from d0 was equal to 1:
the bit X=C=1 in the CCR
ROL #BBB,dn (.B),[.W],(.L) ROtate Left
--------------
or
ROL dm,dn (.B),[.W],(.L)
--------------
or
ROL.W destination (.W)
------------------
Performs a ROTATION of #BBB or dm (depending on the syntax) BITS
of the data register dn to the left.
The replacement bits are equal to those that just exited.
It is necessary that 1<= #BBB <= 8 for the 1st form.
-------------
For the 3rd form, the allowed addressing modes for the
destination operand are:
-----------
BBBB
BB
(an)
-(an)
(an)+
d(an)
d(an,rn)
But in this case, the operation can only rotate
1 SINGLE BIT.
For example, if d0=%10000101110001101111011100000110 (word)
------
And if I write ROL.W #1,dn
or MOVE.W #1,d1
ROL.W d1,d0, we get:
d0=%00001011100011011110111000001101
<----- <:1
All the bits of the lower WORD of the data register dn (.W)
have been rotated by 1 bit to the left:
The most significant bit exits on the left and returns on the
right. (rotation)
Meaning: #BBB or dm BITS are rotated out of dn on the left and they
re-enter on the right, in place of the missing bits.
The contents of dn are therefore changed, the MSB is also likely to be
changed: the sign of the register is therefore not necessarily preserved.
The CCR will change according to the new value of dn.
---
N=1 if the MSB is 1, otherwise it is 0
Z=1 if all bits of dn are null, otherwise it is 0
V is set to 1 if the MSB of the destination operand has been changed.
C is set to the value of the LAST BIT EXITED from dn.
X is not affected.
Example of use:
----------------------
MOVE #%1111111101010101,d0
ROL.B #5,d0
A rotation of 5 bits of the lower BYTE of d0 is operated.
(only bits 0 to 7 of d0 are therefore concerned by rol.B)
We get:
-------C<------<:C CCR
d0 :1111111110101010 -> C=0 at the end
5 bits are rotated out to the left of the lower byte of d0 and were
replaced with bits equal to the least significant bit of the byte.
The last bit to exit from d0 was equal to 0:
the bit C=0 in the CCR
ROR #BBB,dn (.B),[.W],(.L) ROtate Right
--------------
or
ROR dm,dn (.B),[.W],(.L)
--------------
or
ROR.W destination (.W)
------------------
Performs a ROTATION of #BBB or dm (depending on the syntax) BITS
of the data register dn to the right.
The replacement bits are equal to those that just exited.
It is necessary that 1<= #BBB <= 8 for the 1st form.
-------------
For the 3rd form, the allowed addressing modes for the
destination operand are:
-----------
BBBB
BB
(an)
-(an)
(an)+
d(an)
d(an,rn)
But in this case, the operation can only rotate
1 SINGLE BIT.
For example, if d0=%10000101110001101111011100000110 (word)
------
And if I write ROR.W #1,dn
or MOVE.W #1,d1
ROR.W d1,d0, we get:
d0=%01000010111000110111101110000011
--> --->
All the bits of the lower WORD of the data register dn (.W)
have been rotated by 1 bit to the right:
The least significant bit exits on the right and returns on the
left. (rotation)
Meaning: #BBB or dm BITS are rotated out of dn to the right and they
re-enter on the left, in place of the missing bits.
The contents of dn are therefore changed, the MSB is also likely to be
changed: the sign of the register is therefore not necessarily preserved.
The CCR will change according to the new value of dn.
---
N=1 if the MSB is 1, otherwise it is 0
Z=1 if all bits of dn are null, otherwise it is 0
V is set to 1 if the MSB of the destination operand has been changed.
C is set to the value of the LAST BIT EXITED from dn.
X is not affected.
Example of use:
----------------------
MOVE #%1111111101010101,d0
ROR.B #5,d0
A rotation of 5 bits of the lower BYTE of d0 is operated.
(only bits 0 to 7 of d0 are therefore concerned by ror.B)
We get:
-------C>------>:C CCR
d0 :1111111110101010 -> C=1 at the end
5 bits are rotated out to the right of the lower byte of d0 and were
replaced with bits equal to the most significant bit of the byte.
The last bit to exit from d0 was equal to 1:
the bit C=1 in the CCR
ROXL #BBB,dn (.B),[.W],(.L) ROtate Left with eXtend
--------------
or
ROXL dm,dn (.B),[.W],(.L)
--------------
or
ROXL.W destination (.W)
-------------------
ROXL is identical to ROL except that here the X bit of the CCR is (like
the C bit) loaded with the last bit that just exited and
it is copied in place of the missing bit.
ROXR #BBB,dn (.B),[.W],(.L) ROtate Right with eXtend
--------------
or
ROXR dm,dn (.B),[.W],(.L)
--------------
or
ROXR.W destination (.W)
-------------------
ROXR is identical to ROR except that here the X bit of the CCR is (like
the C bit) loaded with the last bit that just exited and
it is copied in place of the missing bit.
BTST source,dn (.B),[.W],(.L) (TeST a Bit)
----------------
or
BTST source,destination (.B),[.W],(.L)
------------------------
Tests the value (0 or 1) of a BIT.
If the BIT is NULL: the Z bit of the CCR is set to 1
- -
If the BIT is ACTIVE: the Z bit of the CCR is set to 0
- -
For the first form:
--------------
The source operand indicates the BIT number to test, it admits the
addressing modes: --
dn
#BBB
(with 0<= NR° <=32, modulo 32)
The destination operand is a data register.
-----------
For the second form:
-------------
The source operand indicates the BIT number to test, it admits the
addressing modes: --
dn
#BBB
(with 0<= NR° <=32, modulo 32)
The destination operand indicates the data to process, it admits the
addressing modes:
dn
BBBB
BB
(an)
-(an)
(an)+
d(an)
d(an,rn)
d(pc)
d(pc,rn)
Apart from the Z bit of the CCR, the bits of the CCR are not affected by
the instruction. ---
Example of use:
----------------------
MOVE #%0111101101100101,d0
BTST.B #3,d0 ;Test the bit nr°3 of d0
BEQ zero ;Z=1 ?
BNE un ;Z=0 ?
The BIT nr°3 of the lower byte of the word
%0111101101100101 is tested.
It is equal to 0: Z=1 in the CCR, we jump to 'zero'
BSET source,dn (.B),[.W],(.L) (test a Bit and SET)
----------------
or
BSET source,destination (.B),[.W],(.L)
------------------------
Tests the value (0 or 1) of a BIT.
. If the BIT is NULL: the Z bit of the CCR is set to 1
- -
. If the BIT is ACTIVE: the Z bit of the CCR is set to 0
- -
. After the test, the concerned BIT is set to 1
--- -------
For the first form:
--------------
The source operand indicates the BIT number to test, it admits the
addressing modes: --
dn
#BBB
(with 0<= NR° <=32, modulo 32)
The destination operand is a data register.
----------- ------------------
For the second form:
-------------
The source operand indicates the BIT number to test, it admits the
addressing modes: --
dn
#BBB
(with 0<= NR° <=32, modulo 32)
The destination operand indicates the data to process, it admits the
addressing modes:
dn
BBBB
BB
(an)
-(an)
(an)+
d(an)
d(an,rn)
Apart from the Z bit of the CCR, the bits of the CCR are not affected by
the instruction. ---
Example of use:
---------------------
MOVE #%0111101101100101,d0
BSET.B #3,d0 ;Test the bit nr°3 of d0 and SET to 1
BEQ zero ;Z=1 ?
BNE un ;Z=0 ?
The BIT nr°3 of the lower byte of the word
%0111101101100101 is tested.
It is equal to 0: Z=1 in the CCR, we jump to 'zero'.
The bit nr°3 has been set to 1: thus d0=%0111101101101101
BCHG source,dn (.B),[.W],(.L) (Bit CHanGe)
----------------
or
BCHG source,destination (.B),[.W],(.L)
------------------------
Tests the value (0 or 1) of a BIT.
If the BIT is NULL: the Z bit of the CCR is set to 1
If the BIT is ACTIVE: the Z bit of the CCR is set to 0
After the test, the concerned bit is changed to its opposite:
. 0 if it was equal to 1
. 1 if it was equal to 0
For the first form:
--------------
The source operand indicates the BIT number to test, it admits the
addressing modes: --
dn
#BBB
(with 0<= NR° <=32, modulo 32)
The destination operand is a data register.
----------- ------------------
For the second form:
-------------
The source operand indicates the BIT number to test, it admits the
addressing modes: --
dn
#BBB
(with 0<= BIT number <=32, modulo 32)
The destination operand indicates the data to be processed, it admits
the addressing modes:
dn
BBBB
BB
(an)
-(an)
(an)+
d(an)
d(an,rn)
Apart from the Z bit of the CCR, the bits of the CCR are not affected by
the instruction. ---
Example of use:
----------------------
MOVE #%0111101101100101,d0
BTST.B #3,d0 ;Test bit nr°3 of d0
BEQ zero ;Z=1 ?
BNE un ;Z=0 ?
Test the BIT nr°3 of the lower byte of the word
%0111101101100101.
It is equal to 0: Z=1 in the CCR, jump to 'zero'.
The bit nr°3 has been changed to its opposite: therefore, d0=%0111101101101101
BCLR source,dn (.B),[.W],(.L) (Bit CLeaR)
----------------
or
BCLR source,destination (.B),[.W],(.L)
------------------------
Tests the value (0 or 1) of a BIT.
. If the BIT is NULL: the Z bit of the CCR is set to 1
--- - -
. If the BIT is ACTIVE: the Z bit of the CCR is set to 0
----- - -
. After the test, the concerned bit is set to 0.
--- -------
For the first form:
--------------
The source operand indicates the BIT number to test, it admits the
addressing modes: --
dn
#BBB
(with 0<= BIT number <=32, modulo 32)
The destination operand is a data register.
----------- ------------------
For the second form:
-------------
The source operand indicates the BIT number to test, it admits the
addressing modes: --
dn
#BBB
(with 0<= BIT number <=32, modulo 32)
The destination operand indicates the data to process, it admits
the addressing modes:
dn
BBBB
BB
(an)
-(an)
(an)+
d(an)
d(an,rn)
Apart from the Z bit of the CCR, the bits of the CCR are not affected by
the instruction. ---
Example of use:
---------------------
MOVE #%0111101101100101,d0
BTST.B #3,d0 ;Test bit nr°3 of d0
BEQ zero ;Z=1 ?
BNE un ;Z=0 ?
Test the BIT nr°3 of the lower byte of the word
%0111101101100101.
It is equal to 0: Z=1 in the CCR, jump to 'zero'
The bit nr°3 of d0 has been set to 0: d0 remains unchanged
ADDX dm,dn (.B),[.W],(.L) (ADD with eXtend)
--------------
or
ADDX -(am),-(an) (.B),[.W],(.L)
------------------
ADDX is identical to ADD, except here the source operand is increased
by the X bit of the CCR and added to (in) the destination operand.
The X bit of the CCR is a copy of the C bit and is set to 1 if the result
of an operation causes a carry.
This allows for additions with precision greater
than a L-M: two L-Ms can be added with ADDX!
All bits of the CCR are affected by ADDX.
---
NB: To avoid a previous carry interfering with an addition with
-- ADDX, you can set the X bit of the CCR to 0 with MOVE #0,CCR before
the addition.
ABCD.B dm,dn (.B) (ADD Decimal with eXtend)
----------------
or
ABCD.B -(am),-(an) (.B)
--------------------
ABCD is identical to ADD, except here the source operand is increased
by the X bit of the CCR and added to (in) the destination operand.
Only the .B size is allowed.
The X bit of the CCR is a copy of the C bit and is set to 1 if the result
of an operation causes a carry.
The V and N bits of the CCR are not affected by ABCD.
---
The C bit is set to 1 only if there is a Decimal carry.
NB: To avoid a previous carry interfering with an addition with
-- ABCD, you can set the X bit of the CCR to 0 with MOVE #0,CCR before
the addition.
SUBX dm,dn (.B),[.W],(.L) (SUBtract with eXtend)
--------------
or
SUBX -(am),-(an) (.B),[.W],(.L)
------------------
SUBX is identical to SUB, except here the source operand is increased
by the X bit of the CCR and subtracted from (in) the destination operand.
The X bit of the CCR is a copy of the C bit and is set to 1 if the result
of an operation causes a carry.
This allows for subtractions with precision
greater than a L-M: two L-Ms can be subtracted with SUBX!
All bits of the CCR are affected by SUBX.
---
NB: To avoid a previous carry interfering with a subtraction with
-- SUBX, you can set the X bit of the CCR to 0 with MOVE #0,CCR before
the subtraction.
SBCD.B dm,dn (.B) (Subtract Decimal with eXtend)
----------------
or
SBCD.B -(am),-(an) (.B)
--------------------
SBCD is identical to SUB, except here the source operand is increased
by the X bit of the CCR and added to (in) the destination operand.
Only the .B size is allowed.
The X bit of the CCR is a copy of the C bit and is set to 1 if the result
of an operation causes a carry.
The V and N bits of the CCR are not affected by SBCD.
---
The C bit is set to 1 only if there is a Decimal carry.
NB: To avoid a previous carry interfering with a subtraction
-- with SBCD, you can set the X bit of the CCR to 0 with MOVE #0,CCR
before the subtraction.
Back to ASM_Tutorial