Short Cuts, Hint & Tips Etc: Difference between revisions

From Atari Wiki
Jump to navigation Jump to search
No edit summary
 
mNo edit summary
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
'''Quick instructions'''
<pre>
 
Short Cuts, Hint & Tips Etc.
 
============================
 
   
  +
There are various 'quick' instructions in 68000 that can be used to speed up your code. These 'quick' instructions are a special form of immediate addressing. A 'quick' instruction is usually limited to operating on a number in the range 0 to 7, an exception being MOVEQ, which can operate on a number in the range -128 to 127. These 'quick' instructions are detailed below:
Quick intructions
 
-----------------
 
There are various 'quick' instructions in 68000 that can be used to
 
speed up your code. These 'quick' instructions are a special form of
 
immediate addressing. A 'quick' instruction is usually limited to
 
operating on a number in the range 0 to 7, an exception being MOVEQ,
 
which can operate on a number in the range -128 to 127. These 'quick'
 
instructions are detailed below:
 
   
 
<pre>
 
ADDQ.B #1,D0 is quicker than ADD.B #1,D0
 
ADDQ.B #1,D0 is quicker than ADD.B #1,D0
 
MOVEQ.W #78,D0 is quicker than MOVE.W #78,D0
 
MOVEQ.W #78,D0 is quicker than MOVE.W #78,D0
 
SUBQ.L #2,D0 is quicker than SUB.L #2,D0
 
SUBQ.L #2,D0 is quicker than SUB.L #2,D0
 
</pre>
   
Note: a MOVEQ.W always clears the top 16 bits and MOVEQ.B always
+
Note: a MOVEQ.W always clears the top 16 bits and MOVEQ.B always clears the top 24 bits.
clears the top 24 bits.
 
 
 
Short cuts
+
'''Short cuts'''
  +
----------
 
Some types of intruction(s) can be substituted by different, but quicker
+
Some types of instruction(s) can be substituted by different, but quicker instruction(s) that achieve the same result. Some other techniques can be used to speed up execution time. Details follow:
instruction(s) that achieve the same result. Some other techniques can be
 
used to speed up execution time. Details follow:
 
   
Using LEA ??(SP),SP is quicker than ADD.L #??,SP unless ?? is
+
Using ''LEA ??(SP),SP'' is quicker than ''ADD.L #??,SP'' unless ''??'' is less than 9, in which case ADDQ or SUBQ should be used.
less than 9, in which case ADDQ or SUBQ should be used.
 
 
 
Using B??.S <label> instead of B?? <label> (where ?? is a
+
Using B??.S <label> instead of B?? <label> (where ?? is a condition code such as RA, CC, CS, EQ, NE, SR etc) is a quicker way of performing a relative jump. Note that using this faster method only allows you to jump +127/-128 bytes forward/backward.
condition code such as RA, CC, CS, EQ, NE, SR etc) is a quicker
 
way of performing a relative jump. Note that using this faster
 
method only allows you to jump +127/-128 bytes forward/backward.
 
 
 
Using AND, OR & EOR instead of BLCR, BSET & BCHG is a quick way
+
Using AND, OR & EOR instead of BLCR, BSET & BCHG is a quick way of resetting, setting or inverting individual bits.
of resetting, setting or inverting individual bits.
 
 
 
 
e.g. AND.W #254,D0 is quicker than BCLR #0,D0
 
e.g. AND.W #254,D0 is quicker than BCLR #0,D0
Line 40: Line 25:
 
EOR.W #1,D0 is quicker than BCHG #0,D0
 
EOR.W #1,D0 is quicker than BCHG #0,D0
 
 
Using TST.W ?? is equivalent to CMP.W #0,??. The TST.W is
+
Using TST.W ?? is equivalent to CMP.W #0,??. The TST.W is quicker than the CMP.W!!
quicker than the CMP.W!!
 
 
 
Using MOVEQ.W #0,D? is quicker than using CLR.W D?.
+
Using MOVEQ.W #0,D? is quicker than using CLR.W D?.
 
 
Using shift instructions e.g. LSR, LSL, ASR, ASL to multiply
+
Using shift instructions e.g. LSR, LSL, ASR, ASL to multiply or divide by powers of 2 is quicker than using the equivalent
 
multiply or divide instruction.
or divide by powers of 2 is quicker than using the equivalent
 
multiply or divide instruction.
 
 
 
 
e.g. LSL.W #1,D0 is quicker than MULU.W #2,D0
 
e.g. LSL.W #1,D0 is quicker than MULU.W #2,D0
 
LSR.W #1,D0 os quicker than DIVU.W #2,D0
 
LSR.W #1,D0 os quicker than DIVU.W #2,D0
 
 
When moving more than one register use the MOVEM instruction.
+
When moving more than one register use the MOVEM instruction.
 
 
 
e.g. MOVEM.L D0/D4/A4-A5,-(SP)
 
e.g. MOVEM.L D0/D4/A4-A5,-(SP)
Line 61: Line 44:
 
MOVE.L A5,-(SP)
 
MOVE.L A5,-(SP)
 
 
Use short word addressing where possible.
+
Use short word addressing where possible.
 
 
 
e.g. MOVE.B $FFFF8240.W,D0
 
e.g. MOVE.B $FFFF8240.W,D0
Line 67: Line 50:
 
MOVE.B $FFFF8240,D0
 
MOVE.B $FFFF8240,D0
 
 
Use the 'address register indirect with index' addressing mode
+
Use the 'address register indirect with index' addressing mode where possible.
where possible.
 
 
 
 
e.g. MOVE.W 20(A0,D0.L),D1
 
e.g. MOVE.W 20(A0,D0.L),D1
Line 78: Line 60:
 
LEA 20(A0,D0.L),A0
 
LEA 20(A0,D0.L),A0
 
MOVE.L (A0),D1
 
MOVE.L (A0),D1
 
Back to [[ASM_Tutorial]]
</pre>
 
   
  +
[[Category:Assembly Language]]
Back to [[ASM_Tutorial]]
 

Latest revision as of 10:54, 5 May 2020

Quick instructions

There are various 'quick' instructions in 68000 that can be used to speed up your code. These 'quick' instructions are a special form of immediate addressing. A 'quick' instruction is usually limited to operating on a number in the range 0 to 7, an exception being MOVEQ, which can operate on a number in the range -128 to 127. These 'quick' instructions are detailed below:

        ADDQ.B #1,D0    is quicker than    ADD.B #1,D0
        MOVEQ.W #78,D0  is quicker than    MOVE.W #78,D0
        SUBQ.L #2,D0    is quicker than    SUB.L #2,D0

Note: a MOVEQ.W always clears the top 16 bits and MOVEQ.B always clears the top 24 bits.

Short cuts

Some types of instruction(s) can be substituted by different, but quicker instruction(s) that achieve the same result. Some other techniques can be used to speed up execution time. Details follow:

Using LEA ??(SP),SP is quicker than ADD.L #??,SP unless ?? is less than 9, in which case ADDQ or SUBQ should be used.

Using B??.S <label> instead of B?? <label> (where ?? is a condition code such as RA, CC, CS, EQ, NE, SR etc) is a quicker way of performing a relative jump. Note that using this faster method only allows you to jump +127/-128 bytes forward/backward.

Using AND, OR & EOR instead of BLCR, BSET & BCHG is a quick way of resetting, setting or inverting individual bits.

               e.g. AND.W  #254,D0 is quicker than  BCLR  #0,D0
                    OR.W   #1,D0   is quicker than  BSET  #0,D0
                    EOR.W  #1,D0   is quicker than  BCHG  #0,D0
                    

Using TST.W ?? is equivalent to CMP.W #0,??. The TST.W is quicker than the CMP.W!!

Using MOVEQ.W #0,D? is quicker than using CLR.W D?.

Using shift instructions e.g. LSR, LSL, ASR, ASL to multiply or divide by powers of 2 is quicker than using the equivalent multiply or divide instruction.

               e.g. LSL.W  #1,D0 is quicker than MULU.W  #2,D0
                    LSR.W  #1,D0 os quicker than DIVU.W  #2,D0
                    

When moving more than one register use the MOVEM instruction.

               e.g. MOVEM.L  D0/D4/A4-A5,-(SP)
                         is quicker than
                    MOVE.L   D0,-(SP)
                    MOVE.L   D4,-(SP)
                    MOVE.L   A4,-(SP)
                    MOVE.L   A5,-(SP)
                    

Use short word addressing where possible.

               e.g.  MOVE.B  $FFFF8240.W,D0
                         is quicker than
                     MOVE.B  $FFFF8240,D0
       

Use the 'address register indirect with index' addressing mode where possible.

               e.g.  MOVE.W  20(A0,D0.L),D1
                       is quicker than
                     LEA     20(A0),A0
                     ADD.L   D0,A0
                     MOVE.L  (A0),D1
                            or
                     LEA     20(A0,D0.L),A0
                     MOVE.L  (A0),D1

Back to ASM_Tutorial