Short Cuts, Hint & Tips Etc

From Atari Wiki
Revision as of 05:45, 26 October 2008 by Tompee (talk | contribs) (categorise)
Jump to navigation Jump to search

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