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

  1. 02200000000801
  2. 1
  3. 2
  4. 9[...............................................................]0
  5. ü68000 ASSEMBLY LANGUAGE COURSE PART IIÇ by Mark van den Boer
  6.  
  7. Welcome to part II of this course.  In part I,  some fundamentals 
  8. of  the 68000 were shown.  In this part,  I will show  you  which 
  9. addressing modes the 68000 uses.  First an example of  addressing 
  10. modes which the 6502 and 6809 use:
  11.  
  12. lda #10   * immediate addressing
  13. lda $10   * zero-page (6502) or direct-page addressing (6809)
  14. inx       * inherent (6502)
  15. inca      * inherent (6809)
  16.  
  17. Now, what does a line of code in 68000 assembler look like?
  18. ü
  19. LABEL   OPCODE  OPER1,OPER2      COMMENT
  20. Ç
  21. The meanings of these fields are:
  22. label:   A  name  given to this line  of  code.  Some  assemblers 
  23.          require  a :  to follow the label-name.  This  field  is 
  24.          optional.
  25.  
  26.  
  27. opcode:  This field specifies the operation you wish to  perform. 
  28.          It is the only field that isn't optional.  Depending  on 
  29.          the opcode the 68000 expects 0, 1 or 2 operands.
  30. oper1:   The  first  operand  to  appear  with  the  opcode.  The 
  31.          appearance  of  this  field  depends  on  the  specified 
  32.          opcode.
  33. oper2:   The  second  operand  to appear  with  the  opcode.  The 
  34.          appearance of this field depends (surprise, surprise) on 
  35.          the specified opcode.
  36. comment: Another optional field which is used for commenting  all 
  37.          tricks  people put in their  programs.  Most  assemblers 
  38.          require a * as the first character of the comment field. 
  39.          The comment field is optional.
  40.  
  41. Now what does an addressing mode do? An addressing mode specifies 
  42. on which data the opcode (instruction) must operate.
  43. The  68000 has a total of 14 addressing modes,  all of which  now 
  44. will  explained.  As examples in all addressing modes I will  use 
  45. the üMOVEÇ instruction. üMOVEÇ can have the .b, .w and .l suffixes as 
  46. mentioned in part I of the course. The üMOVEÇ instruction moves the 
  47. data  specified  by oper1 to the place specified  by  oper2.  For 
  48.  
  49. example:  üMOVE.B $1,$2Ç performs exactly the same operation as the 
  50. following 6502 and 6809 code: üLDA $1    STA $2.
  51. Ç
  52. The addressing modes:
  53.  
  54. ü1. Inherent addressing
  55. Ç
  56. In  this  addressing mode there are no operands  since  they  are 
  57. already supplied by the opcode.
  58. E.g.: üRESETÇ    * reset all peripherals
  59. üRESETÇ  is  an 68000 instruction which is used to  reset  all  the 
  60. peripherals.
  61.  
  62. ü2. DATA REGISTER DIRECT ADDRESSING
  63. Ç
  64. Assembler syntax: Dn (n can range from 0 to 7)
  65. In this addressing mode a data register contains the operand.
  66. E.g.:
  67.  
  68.  
  69.  
  70.  
  71. Instruction          Before             After
  72. üMOVE.B D1,D0Ç      d0=ffffffff         d0=ffffff67
  73.                   d1=01234567         d1=01234567
  74. üMOVE.W D1,D0      Çd0=ffffffff         d0=ffff4567
  75. ü       Ç           d1=01234567         d1=01234567
  76. üMOVE.L D1,D0      Çd0=ffffffff         d0=01234567
  77.                   d1=01234567         d1=01234567
  78.  
  79. As  you might have noticed,  an instruction with .b as  a  suffix 
  80. only  changes  the  lowest  8  bits  of  the   destination,   and 
  81. instructions  with .w as a suffix only change the lowest 16  bits 
  82. of the destination.  Instructions with .l as a suffix change  all 
  83. 32 bits of the destination.
  84.  
  85. ü3. ADDRESS REGISTER DIRECT ADDRESSING
  86. Ç
  87. Assembler syntax: An (n can range from 0 to 7)
  88. In this addressing mode an address register contains the operand. 
  89. Byte  operators  (those with .b suffix) are not allowed  in  this 
  90. addressing mode. When using the address register as a destination 
  91. and  it  is a word operation (suffix is .w),  the word  is  sign-
  92. extended into a longword.  This means that during a  wordtransfer 
  93. into a data register the upper 16 bits are filled with the  value 
  94. of  the  most-significant bit (this is bit 15) of  the  word.  An 
  95. example below will show you how it's done.
  96. E.g.:
  97.  
  98. Instruction          Before             After
  99. üMOVE.W A1,D0Ç       d0=ffffffff        d0=ffff4567
  100.                    a1=01234567        a1=01234567
  101. üMOVE.W D0,A1Ç       d0=01234567        d0=01234567
  102.                    a1=ffffffff        a1=00004567  <- extend!!
  103. üMOVE.W D0,A1Ç       d0=0000ffff        d0=0000ffff
  104.                    a1=00000000        a1=ffffffff  <- extend!!
  105. üMOVE.L A1,D0Ç       d0=ffffffff        d0=01234567
  106.                    a1=01234567        a1=01234567
  107.  
  108. ü4. ADDRESS REGISTER INDIRECT ADDRESSING
  109. Ç
  110. Assembler syntax: (An)   (n between 0 and 7)
  111. In  this  addressing  mode,  the address  register  contains  the 
  112. address of the operand.  In assembler this is being denotated  by 
  113. putting parentheses around an address registers name,  e.g. (a0). 
  114. The contents of a0 points to the address where the data has to be 
  115. fetched from. When using word (.w) or longword (.l) addressing it 
  116. is  êabsolutely  necessaryÇ that the address register  contains  an 
  117. even number (I will explain the reason for this in a  forthcoming 
  118. article).
  119. E.g.:
  120.  
  121. Instruction          Before             After
  122. üMOVE.L (A1),D0Ç    d0=ffffffff        d0=01234567
  123.                   a1=00001000        a1=00001000
  124.             address $1000 contains 01234567
  125. üMOVE.L D0,(A1)Ç    d0=76543210        d0=76543210
  126.                   a1=00001000        a1=00001000
  127.             address $1000 now contains 76543210
  128.  
  129. ü5.Ç üADDRESS REGISTER INDIRECT ADDRESSING WITH POST-INCREMENT
  130. Ç
  131. Assembler syntax: (An)+     (n between 0 and 7)
  132. This  addressing  mode resembles the  address  register  indirect 
  133. addressing mode. The only difference is that after having fetched 
  134. or  stored the data,  the address register  is  incremented.  The 
  135. increment depends on the suffix used in the opcode. If the suffix 
  136. is  .b then the address register will be incremented by  one.  If 
  137. the suffix is .w then the address register will be incremented by 
  138. two (one word is two bytes). If the suffix is .l then the address 
  139. register  will  be  incremented by four  (one  longword  is  four 
  140. bytes). In assembler this addressing mode is denotated by putting 
  141. the address register within parentheses followed by a + sign. For 
  142. example: (a7)+
  143. E.g.:
  144.  
  145. Instruction          Before             After
  146. üMOVE.L (A1)+,D0Ç   d0=ffffffff        d0=01234567
  147.                   a1=00001000        a1=00001004
  148.             address $1000 contains 01234567
  149. üMOVE.W (A1)+,D0Ç   d0=ffffffff        d0=ffff0123
  150.                   a1=00001000        a1=00001002
  151.             address $1000 contains 01234567
  152. üMOVE.B (A1)+,D0Ç   d0=ffffffff        d0=ffffff01
  153.                   a1=00001000        a1=00001001
  154.             address $1000 contains 01234567
  155. üMOVE.L D0,(A1)+Ç   d0=76543210        d0=76543210
  156.                   a1=00001000        a1=00001004
  157.             address $1000 now contains 76543210
  158.  
  159. ü6.Ç üADDRESS REGISTER INDIRECT ADDRESSING WITH PRE-DECREMENT
  160. Ç
  161. Assembler syntax: -(An)     (n between 0 and 7)
  162. This  addressing  mode resembles the  address  register  indirect 
  163. addressing  mode.  The  only  difference  is  that  after  before 
  164. fetching  or  storing the data,  the address register  is  decre⑨
  165. mented.  The decrement depends on the suffix used in the  opcode. 
  166. If the suffix is .b then the address register will be decremented 
  167. by  one.  If the suffix is .w then the address register  will  be 
  168. decremented by two (one word is two bytes).  If the suffix is  .l 
  169. then  the  address  register will be  decremented  by  four  (one 
  170. longword  is four bytes).  In assembler this addressing  mode  is 
  171. denotated  by  putting the address  register  within  parentheses 
  172. preceded by a - sign. For example: -(a7)
  173. E.g.:
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. Instruction          Before             After
  182. üMOVE.L -(A1),D0Ç   d0=ffffffff        d0=01234567
  183.                   a1=00001004        a1=00001000
  184.             address $1000 contains 01234567
  185. üMOVE.W -(A1),D0Ç   d0=ffffffff        d0=ffff4567
  186.                   a1=00001004        a1=00001002
  187.             address $1000 contains 01234567
  188. üMOVE.B -(A1),D0Ç   d0=ffffffff        d0=ffffff67
  189.                   a1=00001004        a1=00001003
  190.             address $1000 contains 01234567
  191. üMOVE.L D0,-(A1)Ç   d0=76543210        d0=76543210
  192.                   a1=00001004        a1=00001000
  193.             address $1000 now contains 76543210
  194.  
  195. ü7. ADDRESS REGISTER INDIRECT ADDRESSING WITH DISPLACEMENTÇ
  196.  
  197. Assembler syntax: w(An)    (w stands for word displacement)
  198. This  addressing  is  also rather  similar  to  address  register 
  199. indirect  addressing.  The only difference lies in the fact  that 
  200. before  fetching or moving the data a 16-bit signed  displacement 
  201. is  added  to the contents of the address register  (the  address 
  202. register  itself does ênotÇ change).  In assembler this  addressing 
  203. mode  is  denotated  by enclosing the address  register  name  in 
  204. parentheses  preceded by a 16-bit constant.  For  example:  8(a6) 
  205. denotes  the memory location whose address is the contents of  a6 
  206. plus 8.  This addressing method comes in very handy when  passing 
  207. parameters to subroutines.
  208. By the way, did you ever wonder why the ATARI ST has a resolution 
  209. of  640  by  400  pixels?
  210. Here's one reason:  640*400=256000 bits=32000 bytes.  Since 32000 
  211. bytes  can  be  addressed using 16  bits,  the  address  register 
  212. indirect with displacement is an easy way to address the screen.
  213. E.g.:
  214.  
  215. Instruction          Before             After
  216. üMOVE.L 8(A1),D0Ç   d0=ffffffff        d0=01234567
  217.                   a1=00001000        a1=00001000
  218.             address $1008 contains 01234567
  219. üMOVE.L D0,-6(A1)Ç  d0=76543210        d0=76543210
  220.                   a1=00001006        a1=00001006
  221.             address $1000 now contains 76543210
  222.  
  223. ü
  224.  
  225. 8. ADDRESS REGISTER INDIRECT ADDRESSING WITH INDEXÇ
  226.  
  227. Assembler syntax: b(An,Rn.w) or b(An,Rn.l)
  228. (  b  stands for byte,  w and l for word and longword and  R  for 
  229. register).
  230. This  addressing mode makes it possible to add a  variable  index 
  231. (contained in an address or data register) to an address register 
  232. and  also an eight bit êsignedÇ displacement.   The variable  index 
  233. may be either word or longword.  Both the index and  displacement 
  234. are sign extended before they are added to the address register.
  235. E.g.:
  236.  
  237. Instruction            Before             After
  238. üMOVE.L 8(A1,A0.L),D0Ç   d0=ffffffff        d0=01234567
  239.                        a1=00001000        a1=00001000
  240.                        a0=00078000        a0=00078000
  241.                    address $79008 contains 01234567
  242. üMOVE.L 8(A1,A0.W),D0Ç   d0=ffffffff        d0=01234567
  243.                        a1=00001000        a1=00001000
  244.                        a0=00078000        a0=00078000
  245. *** a0.w=8000 -> sign-extend gives ffff8000 ***
  246.                    address $ffff8008 contains 01234567
  247. üMOVE.W 8(A1,D0.L),D0Ç   d0=0001fffe        d0=00010123
  248.                        a1=00001000        a1=00001000
  249. *** 00001000 (contents of a1)
  250.     0001fffe (contents of d0.l)
  251.     00000008 (sign-extended byte displacement)
  252.     ---------
  253.     00021006
  254.                    address $21006 contains 01234567
  255. üMOVE.L 8(A1,D0.W),D0Ç   d0=0001fffe        d0=01234567
  256.                        a1=00001000        a1=00001000
  257. *** 00001000 (contents of a1)
  258.     fffffffe (sign-extended contents of d0.w)
  259.     00000008 (sign-extended byte displacement)
  260.     ---------
  261.     00001006
  262.                    address $1006 contains 01234567
  263.  
  264. ü9. ABSOLUTE SHORT ADDRESSING
  265. Ç
  266. Assembler syntax: x  (x is a 16 bit constant)
  267. With  absolute short addressing it is only possible to specify  a 
  268. 16  bit constant.  At execution time the 68000 sign  extends  the 
  269. word into a long address,  meaning that only addresses 0 to  7fff 
  270. and ffff8000 to ffffffff can be addressed using this  form.  This 
  271. addressing mode can be compared with zero-page addressing on  the 
  272. 6502 and direct-page addressing on the 6809.Like on the 6502  and 
  273. 6809  this mode is faster than any other  mode.  This  addressing 
  274. mode  can be compared with zero-page addressing on the  6502  and 
  275. direct-page addressing on the 6809.
  276. By the way, on the Atari ST, the lower 32 K of memory can only be 
  277. accessed in supervisor-mode (the S-bit in SR is set, see part I).
  278. E.g.:
  279.  
  280. Instruction            Before             After
  281. üMOVE.L $1234,D0Ç      d0=ffffffff       d0=01234567
  282.                     address 1234 contains 01234567
  283.                    ( the $ sign is used to denote a hex digit)
  284. üMOVE.L $8000,D0Ç      d0=ffffffff       d0=76543210
  285.                     address $ffff8000 contains 76543210
  286.  
  287. ü
  288.  
  289.  
  290.  
  291. 10. ABSOLUTE LONG ADDRESSINGÇ
  292.  
  293. Assembler syntax: l   (l is 32 bit constant)
  294. With this addressing mode a long address is supplied.  It is very 
  295. similar to absolute short addressing.
  296. E.g.:
  297. Instruction              Before             After
  298. üMOVE.L $12345678,D0Ç   d0=ffffffff         d0=01234567
  299.                       address $00345678 contains 01234567
  300. Note  that since the address bus is only 24 bits wide  the  upper 
  301. byte of the address is ignored by the 68000.
  302.  
  303. ü11. PROGRAM COUNTER WITH DISPLACEMENTÇ
  304.  
  305. Assembler syntax: x(PC)    (x is a 16 bit constant)
  306. This  addressing  mode is in fact the same  as  address  register 
  307. indirect  with  displacement.  The only difference  is  that  the 
  308. address register is replaced with the PC (the PC is in fact  also 
  309. an address register).
  310. E.g.:
  311.  
  312.  
  313. Instruction          Before             Afterü
  314. MOVE.L 8(PC),D0Ç   d0=ffffffff        d0=01234567
  315.                   pc=00001000        pc=00001000
  316.             address $1008 contains 01234567
  317.  
  318. ü12. PROGRAM COUNTER WITH INDEXÇ
  319.  
  320. Assembler syntax: b(PC,Rn.L) or b(PC,Rn.w)   (b is 8 bits)
  321. This  mode  is  in  fact  the  same  address  register   indirect 
  322. addressing with index.
  323. E.g.:
  324.  
  325. Instruction            Before             After
  326. üMOVE.L 8(PC,A0.L),D0Ç   d0=ffffffff        d0=01234567
  327.                        pc=00001000        pc=00001000
  328.                        a0=00078000        a0=00078000
  329.                    address $79008 contains 01234567
  330. üMOVE.L 8(PC,A0.W),D0Ç   d0=ffffffff        d0=01234567
  331.                        pc=00001000        pc=00001000
  332.                        a0=00078000        a0=00078000
  333. *** a0.w=8000 -> sign-extend gives ffff8000 ***
  334.                    address $ffff8008 contains 01234567
  335. üMOVE.W 8(PC,D0.L),D0Ç   d0=0001fffe        d0=00010123
  336.                        pc=00001000        pc=00001000
  337. *** 00001000 (contents of pc)
  338.     0001fffe (contents of d0.l)
  339.     00000008 (sign-extended byte displacement)
  340.     ---------
  341.     00021006
  342.                    address $21006 contains 01234567
  343. üMOVE.L 8(PC,D0.W),D0Ç   d0=0001fffe        d0=01234567
  344.                        pc=00001000        pc=00001000
  345. *** 00001000 (contents of pc)
  346.     fffffffe (sign-extended contents of d0.w)
  347.     00000008 (sign-extended byte displacement)
  348.     ---------
  349.     00001006
  350.                    address $1006 contains 01234567
  351.  
  352. ü13. IMMEDIATE ADDRESSING
  353. Ç
  354. Assembler syntax: #x   (x is byte, word or longword)
  355. The  data for the operation is the value x.  Programmers  of  the 
  356. 6502  and 6809 will recognize this addressing mode.  For  example 
  357. (6502 and 6809) LDA #$21.
  358. E.g.:
  359.  
  360. Instruction               Before             Afterü
  361. MOVE.L #$A03B4C11,D0Ç    d0=00000000       d0=a03b4c11
  362.  
  363. ü14. STATUS REGISTER ADDRESSINGÇ
  364.  
  365. Assembler syntax: SR or CCR
  366. This mode is used to control the contents of this  register.  See 
  367. part  I  of this course for the individual meanings of  the  bits 
  368. contained  in this register.  Changes to the SR can only be  made 
  369. when in user-mode. Changes to the CCR can be made in any mode.
  370. E.g.:
  371.  
  372. Instruction            Before             After
  373. üMOVE.W SR,D0Ç        d0=87654321        d0=87652700
  374.                     sr=2700            sr=2700
  375. üMOVE.W #$0500,SRÇ    sr=2700            sr=0500
  376. Notice that the 68000 was in supervisor mode before executing the 
  377. instruction  but  after  completion it is  in  user  mode!!  This 
  378. operation isn't possible the other way around.
  379. To  conclude  this  part,  I  will give  you  a  summary  of  the 
  380. addressing modes of the 68000.
  381.  
  382. üSYNTAX          NAMEÇ
  383. -----------------------------------
  384. Dn          | Data register direct
  385. An          | Address register direct
  386. (An)        | Address register indirect
  387. (An)+       | Address register indirect with post-increment
  388. -(An)       | Address register indirect with pre-decrement
  389. w(An)       | Address register with displacement
  390. b(An,Rn)    | Address register with index
  391. w           | Absolute short
  392. l           | Absolute long
  393. w(PC)       | PC with displacement
  394. b(PC,Rn)    | PC with index
  395. #x          | Immediate
  396. SR or CCR   | Status register
  397.  
  398.  
  399.  
  400.  
  401. b is a byte constant
  402. w is a word constant
  403. l is a long constant
  404. x any of b, l or w
  405. n is a register number ranging from 0 to 7
  406. R is a register specifier, either A or D
  407.  
  408. If you have any comments on these courses, please let me know!
  409.  
  410. Originally published in üST NEWSÇ Volume 2 Issue 1.