home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI03.ARJ / ictari.03 / ASSEMBLY / TIPS.TXT < prev    next >
Text File  |  1989-04-06  |  3KB  |  80 lines

  1. Short Cuts, Hint & Tips Etc.
  2. ============================
  3.  
  4. Quick intructions
  5. -----------------
  6. There are various 'quick' instructions in 68000 that can be used to
  7. speed up your code. These 'quick' instructions are a special form of
  8. immediate addressing. A 'quick' instruction is usually limited to
  9. operating on a number in the range 0 to 7, an exception being MOVEQ,
  10. which can operate on a number in the range -128 to 127. These 'quick'
  11. instructions are detailed below:
  12.  
  13.         ADDQ.B #1,D0    is quicker than    ADD.B #1,D0
  14.         MOVEQ.W #78,D0  is quicker than    MOVE.W #78,D0
  15.         SUBQ.L #2,D0    is quicker than    SUB.L #2,D0
  16.  
  17. Note: a MOVEQ.W always clears the top 16 bits and MOVEQ.B always
  18.       clears the top 24 bits.
  19.         
  20. Short cuts
  21. ----------
  22. Some types of intruction(s) can be substituted by different, but quicker
  23. instruction(s) that achieve the same result. Some other techniques can be
  24. used to speed up execution time. Details follow:
  25.  
  26.         Using LEA  ??(SP),SP is quicker than ADD.L  #??,SP unless ?? is
  27.         less than 9, in which case ADDQ or SUBQ should be used.
  28.         
  29.         Using B??.S <label> instead of B?? <label> (where ?? is a
  30.         condition code such as RA, CC, CS, EQ, NE, SR etc) is a quicker
  31.         way of performing a relative jump. Note that using this faster
  32.         method only allows you to jump +127/-128 bytes forward/backward.
  33.         
  34.         Using AND, OR & EOR instead of BLCR, BSET & BCHG is a quick way
  35.         of resetting, setting or inverting individual bits.
  36.         
  37.                 e.g. AND.W  #254,D0 is quicker than  BCLR  #0,D0
  38.                      OR.W   #1,D0   is quicker than  BSET  #0,D0
  39.                      EOR.W  #1,D0   is quicker than  BCHG  #0,D0
  40.                      
  41.         Using TST.W ?? is equivalent to CMP.W #0,??. The TST.W is
  42.         quicker than the CMP.W!!
  43.         
  44.         Using MOVEQ.W #0,D? is quicker than using CLR.W D?.
  45.         
  46.         Using shift instructions e.g. LSR, LSL, ASR, ASL to multiply
  47.         or divide by powers of 2 is quicker than using the equivalent
  48.         multiply or divide instruction.
  49.         
  50.                 e.g. LSL.W  #1,D0 is quicker than MULU.W  #2,D0
  51.                      LSR.W  #1,D0 os quicker than DIVU.W  #2,D0
  52.                      
  53.         When moving more than one register use the MOVEM instruction.
  54.         
  55.                 e.g. MOVEM.L  D0/D4/A4-A5,-(SP)
  56.                           is quicker than
  57.                      MOVE.L   D0,-(SP)
  58.                      MOVE.L   D4,-(SP)
  59.                      MOVE.L   A4,-(SP)
  60.                      MOVE.L   A5,-(SP)
  61.                      
  62.         Use short word addressing where possible.
  63.         
  64.                 e.g.  MOVE.B  $FFFF8240.W,D0
  65.                           is quicker than
  66.                       MOVE.B  $FFFF8240,D0
  67.         
  68.         Use the 'address register indirect with index' addressing mode
  69.         where possible.
  70.         
  71.                 e.g.  MOVE.W  20(A0,D0.L),D1
  72.                         is quicker than
  73.                       LEA     20(A0),A0
  74.                       ADD.L   D0,A0
  75.                       MOVE.L  (A0),D1
  76.                              or
  77.                       LEA     20(A0,D0.L),A0
  78.                       MOVE.L  (A0),D1
  79.                              
  80.