02200000000801 1 2 9[...............................................................]0 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 Data sizes: byte, word, long except for ASL 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 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 Data sizes: byte, word, long except for ASR 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 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 Data sizes: byte, word, long except for LSR 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 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 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 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 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 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 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 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 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 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 Originally published in ST NEWS€ Volume 2 Issue 5.