home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / books / mc68ktu2 / mc680004.doc < prev    next >
Text File  |  1985-11-18  |  15KB  |  495 lines

  1. 02200000000801
  2. 1
  3. 2
  4. 9[...............................................................]0
  5. üMC 68000 MACHINE LANGUAGE COURSE PART IV Çby Mark van den Boer
  6.  
  7. What a pity!!  You missed the mega-surprise of part 3.  Next time 
  8. better luck! I am gonna take that holiday to Hawaii myself!
  9.  
  10. This time I will discuss the Integer Arithmetic Instructions. The 
  11. syntax used is of course the same as in part 3,  so when in doubt 
  12. refer  to  part  3.  This class of instructions  is  used  to  do 
  13. mathematical  calculations.  This  group is very  often  used  by 
  14. assembly  language programmers,  especially the instructions  for 
  15. adding and subtracting.
  16.  
  17. ë
  18. Integer Arithmetic InstructionsÇ
  19.  
  20.  
  21. Instruction:   ADD
  22. Syntax:        ADD Dn,<ea>
  23.                ADD <ea>,Dn
  24. Data sizes:    byte, word, long
  25.  
  26.  
  27. Condition codes affected:
  28.                X, C set by carry out of the most significant bit
  29.                N    set if the result was negative, cleared otherwise
  30.                Z    set if the result was zero, cleared otherwise
  31.                V    set if the result overflowed, cleared otherwise
  32. Addressing modes:
  33. Source: (destination is Dn)
  34.           Dn
  35.           An
  36.           (An)
  37.           (An)+
  38.           -(An)
  39.           w(An)
  40.           b(An,Rn)
  41.           w
  42.           l
  43.           w(PC)
  44.           b(PC,Rn)
  45.  
  46.  
  47.  
  48.  
  49. Destination:
  50.           Dn
  51.           (An)
  52.           (An)+
  53.           -(An)
  54.           w(An)
  55.           b(An,Rn)
  56.           w
  57.           l
  58. Function: Add  source  to  destination  and  put  the  result  in 
  59.           destination.
  60. Examples:
  61. Instruction              Before         After
  62. ADD.W d0,d1              d0=00000011    d0=00000011
  63.                          d1=0000FFFA    d1=0000000B
  64.                          XNZVC=00000    XNZVC=11001
  65. ADD.L (a0),d0            d0=00000022    d0=00000027
  66.                          a0=12345678    a0=12345678
  67.                     12345678 contains 5
  68.                          XNZVC=00000    XNZVC=00000
  69.  
  70.  
  71. Instruction:   ADDA
  72. Syntax:        ADDA <ea>,An
  73. Data sizes:    word, long
  74. Condition codes affected: None
  75. Addressing modes:
  76. Source:
  77.           Dn
  78.           An
  79.           (An)
  80.           (An)+
  81.           -(An)
  82.           w(An)
  83.           b(An,Rn)
  84.           w
  85.           l
  86.           w(PC)
  87.           b(PC,Rn)
  88.           #
  89. Destination:
  90.           An
  91.  
  92.  
  93. Function: Add a value to an address register. This operation does 
  94.           not change any of the condition code values.  Note that 
  95.           most  operations  that have an address  register  as  a 
  96.           destination does not change the condition codes.
  97. Example:
  98. Instruction              Before         After
  99. ADDA.L a0,a0             a0=00000002    a0=00000004
  100. Notice  that this instruction has the same effect as  multiplying 
  101. the address register with two (if this was possible).
  102.  
  103.  
  104. Instruction:   ADDI
  105. Syntax:        ADDI #,<ea>
  106. This instruction has exactly the same characteristics as the  ADD 
  107. instruction, except that the source can only be a constant.
  108.  
  109. Instruction:   ADDQ
  110. Syntax:        ADDQ #,<ea>
  111. Same story as for ADDI,  except that the immediate values in  the 
  112. source  field  can only range from 1 to 8.  Q stands  for  Quick, 
  113. since this instruction is the fastest way to add a number from  1 
  114. to 8 to a destination operand.
  115. A note on ADD, ADDI, ADDQ:
  116. Most assemblers accept the following instruction: ADD #1,Dn
  117. and will translate it automatically to ADDQ #1,Dn    thus  saving 
  118. a few bytes of object code and some clock cycles execution time.
  119.  
  120.  
  121. Instruction:   ADDX
  122. Syntax:        ADDX Dn,Dn
  123.                ADDX -(An),-(An)
  124. Data sizes:    byte, word, long
  125. Condition codes affected: see ADD
  126. Function: Add  X-bit  and  source to destination  and  store  the 
  127.           result  in destination.  This instruction is  used  for 
  128.           multiple  precision  operations and is  therefore  only 
  129.           available with the two addressing modes mentioned.
  130. Example:
  131. Instruction              Before         After
  132. ADDX.B -(a0),-(a1)       a0=10001001    a0=10001000
  133.                          a1=10002001    a1=10002000
  134.                  10001000 contains AA   the same
  135.                  10002000 contains 5A   10002000 contains 4
  136.                          X=0            X=1
  137. ADDX.B -(a0),-(a1)        a0=10001000    a0=10000fff
  138.                          a1=10002000    a1-10001fff
  139.                  10000fff contains 0    the same
  140.                  10001fff contains 0    10001fff contains 1
  141.                          X=1            X=0
  142. In this example the word that begins at 10000fff is added to  the 
  143. word that begins at 10001fff.  If one should try to do this  with 
  144. two  ADD.W instruction an address error would occur  since  words 
  145. always must be aligned to even addresses. This instruction can be 
  146. compared to the ADC instruction of the 6502 and 6809.
  147.  
  148.  
  149. Instruction:   CLR
  150. Syntax:        CLR <ea>
  151. Data sizes:    byte, word, long
  152. Condition codes affected:
  153.                N    always cleared
  154.                Z    always set
  155.                V    always cleared
  156.                C    always cleared
  157.  
  158.  
  159. Addressing modes:
  160.           Dn
  161.           (An)
  162.           (An)+
  163.           -(An)
  164.           w(An)
  165.           b(An,Rn)
  166.           w
  167.           l
  168. Function: Set an effective address to zero. You will have noticed 
  169.           that you can't CLR an address register.  However,  most 
  170.           assemblers  allow  the  programmer to  CLR  an  address 
  171.           register  by  substituting CLR a0 with SUB.L  a0,a0   . 
  172.           This instruction has exactly the same result.
  173. Example:
  174. Instruction              Before         After
  175. CLR.W d0                 d0=ffffffff    d0=00000000
  176.                          NZVC=1011      NZVC=0100
  177.  
  178.  
  179.  
  180.  
  181. Instruction:   CMP
  182. Syntax:        CMP <ea>,Dn
  183. Data sizes:    byte, word, long
  184. Condition codes affected: NZVC (X is not affected)
  185. Addressing modes (source):
  186.           Dn
  187.           An
  188.           (An)
  189.           (An)+
  190.           -(An)
  191.           w(An)
  192.           b(An,Rn)
  193.           w
  194.           l
  195.           w(PC)
  196.           b(PC,Rn)
  197. Function: compare an effective address with a data  register.  In 
  198.           fact  all  condition codes are set as  if  Dn-<ea>  was 
  199.           performed.  So CMP is kind of a subtraction which  only 
  200.           affects the conditon codes.
  201.  
  202.  
  203. Example:
  204. Instruction              Before         After
  205. CMP.L d0,d1              d0=00000001    d0=00000001
  206.                          d1=00000002    d1=00000002
  207.                          NZVC=1111      NZVC=0000
  208.  
  209.  
  210. Instruction:   CMPA
  211. Syntax:        CMPA <ea>,An
  212. Data sizes:    word, long
  213. Function: This  instruction  differs only from CMP  in  that  the 
  214.           second  operand  is an address register and  that  byte 
  215.           isn't allowed as a data size.
  216.  
  217.  
  218. Instruction:   CMPI
  219. Syntax:        CMPI #,Dn
  220. Function: Yes,  it is nearly exactly the same as compare but  now 
  221.           the first operand must be a constant.
  222.  
  223.  
  224.  
  225. Instruction:   CMPM
  226. Syntax:        CMPM (An)+,(An)+
  227. Function: Again, nearly exactly the same as CMP, but now both the 
  228.           source  and  destination operand must  be  (An)+.  This 
  229.           instruction  is used to compare areas  of  memory.  For 
  230.           those of you who have a working knowledge of C:  strcmp 
  231.           can be programmed easy with this instruction.
  232.  
  233. Note on all CMPx instructions.
  234. Most assemblers accept instructions like:
  235. CMP.W (a0)+,(a1)+
  236. CMP.L #3,d0
  237. Substitution of CMPM,  CMPI and CMPA are automatically  performed 
  238. by the assembler.
  239.  
  240.  
  241. Instruction:   DIVS
  242. Syntax:        DIVS <ea>,Dn
  243. Data sizes:    word
  244.  
  245.  
  246.  
  247. Condition codes affected:
  248.                N    behaves normal; undefined on overflow
  249.                Z    behaves normal; undefined on overflow
  250.                V    behaves normal
  251.                C    always cleared
  252. Addressing modes (source):
  253.           Dn
  254.           (An)
  255.           (An)+
  256.           -(An)
  257.           w(An)
  258.           b(An,Rn)
  259.           w
  260.           l
  261.           w(PC)
  262.           b(PC,Rn)
  263.           #
  264.  
  265.  
  266.  
  267.  
  268.  
  269. Function: Guess  what?   This  instruction  performs  a  division 
  270.           between two signed numbers. The 
  271.           destination  register  is  always a  longword  and  the 
  272.           source operand is always a word. After the division the 
  273.           destination operand contains the result.  The  quotient 
  274.           is üalwaysÇ in the lower word and the remainder is always 
  275.           in the high order word of the data register! This way a 
  276.           modulo operation is also performed,  you just SWAP  the 
  277.           data  register  and you have your result in  the  lower 
  278.           word  of the data register.  Overflow occurs  when  you 
  279.           attempt to divide a large number by a small number e.g. 
  280.           ffffff divided by 1,  the result doesn't fit in a word. 
  281.           Another error occurs when attempting to divide by zero. 
  282.           In this case the 68000 generates an exception and  will 
  283.           trap  to  a special routine which handles  division  by 
  284.           zero erros.  On the Atari you must set up this  routine 
  285.           yourself.  E.g.  FLOYD  (a  machine  language  monitor) 
  286.           responds  to  a  division by zero  with  the  following 
  287.           sentence "The answer is 42". Remember, don't panic when 
  288.           you see such an answer.
  289.  
  290.  
  291. Example:
  292. Instruction              Before         After
  293. DIVS #3,d0               d0=0000000B    d0=00020003
  294.                          NZVC=1111      NZVC=0000
  295.  
  296.  
  297. Instruction: DIVU
  298. Function: Nearly  exactly the same as DIVS,  only this time  both 
  299.           operands are assumed to be unsigned.
  300.  
  301.  
  302. Instruction:   EXT
  303. Syntax:        EXT Dn
  304. Data sizes:    word, long
  305. Condition codes affected:
  306.                N    behaves normal
  307.                Z    behaves normal
  308.                V    always cleared
  309.                C    always cleared
  310.  
  311.  
  312.  
  313. Function: turn  a byte into a word,  or turn a word into a  long. 
  314.           This  instruction provides a convenient way to  turn  a 
  315.           word into a long and still have the same value for that 
  316.           register. If the high order bit of the data register is 
  317.           0,  so the data register is positive, zeroes are padded 
  318.           in, otherwise ones are padded in.
  319. Example:
  320. Instruction              Before         After
  321. EXT.W d0                 d0=000000ff    d0=0000ffff
  322. EXT.L d0                 d0=ffff0000    d0=00000000
  323.  
  324.  
  325. Instruction:   MULS
  326. Syntax:        MULS <ea>,Dn
  327. Data sizes:    word
  328. Condition codes affected:
  329.                N    behaves normal
  330.                Z    behaves normal
  331.                V    always cleared
  332.                C    always cleared
  333.  
  334.  
  335. Addressing modes (source):
  336.           Dn
  337.           (An)
  338.           (An)+
  339.           -(An)
  340.           w(An)
  341.           b(An,Rn)
  342.           w
  343.           l
  344.           w(PC)
  345.           b(PC,Rn)
  346.           #
  347. Function: Ah!  another very handy instruction.  This  instruction 
  348.           performs a multiplication of the source and destination 
  349.           operand, putting the result in the destination operand.
  350. Example:
  351. Instruction              Before         After
  352. MULS #3,d0               d0=0000000B    d0=00000021
  353.                          NZVC=1111      NZVC=0000
  354.  
  355.  
  356.  
  357. Instruction: MULU
  358. Function: Nearly  exactly the same as MULUS,  only this time  both 
  359.           operands are assumed to be unsigned.
  360.  
  361.  
  362. Instruction:   NEG
  363. Syntax:        NEG <ea>
  364. Data sizes:    byte, word, long
  365. Condition codes affected: XNZVC (all behave normal)
  366. Addressing modes:
  367.           Dn
  368.           (An)
  369.           (An)+
  370.           -(An)
  371.           w(An)
  372.           b(An,Rn)
  373.           w
  374.           l
  375. Function: negate  an effective address operand.  In a high  level 
  376.           language it would look like this: a = -a
  377.  
  378.  
  379. Example:
  380. Instruction              Before         After
  381. NEG.L d0                 d0=00000001    d0=ffffffff
  382.  
  383.  
  384. Instruction:   NEGX
  385. Syntax:        NEGX <ea>
  386. Data sizes:    byte, word, long
  387. Condition codes affected: XNZVC (all behave normal)
  388. Addressing modes:
  389.           Dn
  390.           (An)
  391.           (An)+
  392.           -(An)
  393.           w(An)
  394.           b(An,Rn)
  395.           w
  396.           l
  397. Function: negate  an effective address operand and add the  X-bit 
  398.           to  the  result.  This  is  another  instruction  which 
  399.           provides a way to handle multi-precision  (e.g.  8-byte 
  400.           integers).
  401. Example:
  402. Instruction              Before         After
  403. NEGX.L d0                d0=00000001    d0=00000000
  404.                          X=1            X=1
  405.  
  406.  
  407. Instructions: SUB, SUBA, SUBI, SUBQ, SUBX
  408. All these instruction perform subtractions.  They only differ  in 
  409. that   way   from   from  the   ADD   instructions,   all   other 
  410. characteristics are the same.
  411.  
  412.  
  413. Instruction:   TAS
  414. Syntax:        TAS <ea>
  415. Data sizes:    byte
  416. Condition codes affected:
  417.                N    evaluated êbeforeÇ setting the byte
  418.                Z    evaluated êbeforeÇ setting the byte
  419.                V    always cleared
  420.                C    always cleared
  421.  
  422.  
  423. Addressing modes:
  424.           Dn
  425.           (An)
  426.           (An)+
  427.           -(An)
  428.           w(An)
  429.           b(An,Rn)
  430.           w
  431.           l
  432. Function: First  test  the operand and set the  condition  codes, 
  433.           then set the high-order bit to 1.  People who know what 
  434.           semaphores (in programming of course...) are,  immedia-
  435.           tely  will love this instruction.  For those who  don't 
  436.           know what semaphores are: M. Ben Ari has written a good 
  437.           book  on the subject called "Principles  of  Concurrent 
  438.           Programming".  Never,  I repeat never,  read a book  on 
  439.           this subject written by a certain Ir.  E.H.H.  Dijkstra 
  440.           (not the famous Dijkstra,  this Dijkstra will never  be 
  441.           famous).
  442.  
  443.  
  444.  
  445. Example:
  446. Instruction              Before         After
  447. TAS $436                 $436=00        $436=80
  448.                          NZVC=1111      NZVC=0100
  449. TAS $436                 $436=FF        $436=FF
  450.                          NZVC=1111      NZVC=1000
  451.  
  452.  
  453. Instruction:   TST
  454. Syntax:        TST <ea>
  455. Data sizes:    byte, word, long
  456. Condition codes affected:
  457.                N    behaves normal
  458.                Z    behaves normal
  459.                V    always cleared
  460.                C    always cleared
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467. Addressing modes:
  468.           Dn
  469.           (An)
  470.           (An)+
  471.           -(An)
  472.           w(An)
  473.           b(An,Rn)
  474.           w
  475.           l
  476. Function: test an effective address operand. This instruction can 
  477.           be  seen as CMP <ea>,d0 where d0 is 0.  TST  is  nearly 
  478.           always followed by a branch instruction (more on  these 
  479.           later)
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489. To  the people who also read the last lines (I hope  you've  also 
  490. read most of the preceeding ones):  Phone me and tell me how  you 
  491. like this course.
  492.  
  493. My phonenumber (in Holland) is: 013-422397
  494.  
  495. Originally published in üST NEWSÇ Volume 2 Issue 3.