home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / HISPEED2.LZH / NEWDOC / IA.DOC < prev   
Text File  |  1991-04-01  |  8KB  |  258 lines

  1. New for version 1.1, ASM, ASSEMBLER
  2.  
  3.  
  4. New Chapter
  5. The Inline Assembler
  6. HighSpeed Pascal enables you to type assembly source directly into the
  7. Pascal source. The full 68000 instruction set is supported. 
  8.  
  9. The assembler does not know of the size of a used Pascal variable.
  10. It is up to you to specify the right size on each assembly instruction
  11. if not using the default word size. If you code
  12.  
  13.       ASM move MyLongInt,d0 END;
  14.  
  15. you end up with only the hi part from the longint MyLongInt.
  16.  
  17. The assembler makes is much faster to write small code pieces without
  18. having to use the Inline or external system. Of cause, you can still
  19. use inline and external. 
  20.  
  21. The only directives implemented is DC to define constant blocks in the
  22. code. All other needed features must be coded in Pascal. The assembler
  23. can read Pascal constants and variables. 
  24.  
  25. These are the registers known by the assembler:
  26.  
  27.   D0, D1, D2, D3, D4, D5, D6, D7,
  28.   A0, A1, A2, A3, A4, A5, A6, A7,
  29.   SP, USP, PC, CCR, SR
  30.  
  31. Special variables only known to the assembler:
  32.  
  33.   @RESULT
  34.  
  35. These are the 68000 instructions known by the assembler:
  36.  
  37. ABCD, ADD, ADDA, ADDI, ADDQ, ADDX, AND, ANDI, ASL, ASR
  38. BCC, BCHG, BCLR, BCS, BEQ, BGE, BGT, BHI, BHS, BLE, BLO, BLS, BLT,
  39. BMI, BNE, BNZ, BPL, BRA, BSET, BSR, BTST, BVC, BVS, BZE
  40. CHK, CLR, CMP, CMPA, CMPI, CMPM
  41. DBCC, DBCS, DBEQ, DBF, DBGE, DBGT, DBHI, DBHS, DBLE, DBLO, DBLS, DBLT,
  42. DBMI, DBNE, DBNZ, DBPL, DBRA, DBT, DBVC, DBVS, DBZE, DIVS, DIVU
  43. EOR, EORI, EXG, EXT, ILLEGAL, JMP, JSR, LEA, LINK, LSL, LSR
  44. MOVE, MOVEA, MOVEM, MOVEP, MOVEQ, MULS, MULU
  45. NBCD, NEG, NEGX, NOP, NOT, OR, ORI, PEA
  46. RESET, ROL, ROR, ROXL, ROXR, RTE, RTR, RTS
  47. SBCD, SCC, SCS, SEQ, SF, SGE, SGT, SHI, SHS, SLE, SLO, SLS, SLT, SMI,
  48. SNE, SNZ, SPL, ST, STOP, SUB, SUBA, SUBI, SUBQ, SUBX, SVC, SVS, SWAP, SZE
  49. TAS, TRAP, TRAPV, TST, UNLK
  50.  
  51. You will have to find the description of these instructions somewhere else
  52. outside this manual.
  53.  
  54. The assembler is accessed through an ASM statement. The syntax of an ASM
  55. statement is:
  56.  
  57.   ASM [Label:] AsmStmt < Separator AsmStmt > END;
  58.  
  59. where Label is an optional label and AsmStmt is one assembler statement.
  60. The Separator is either a semicolon or a new-line. Notice that this is
  61. different from the rest of the HighSpeed Pascal compiler where a new-line
  62. only counts as a space. More than one AsmStmt can be placed on one line
  63. separated by semicolons or they can be placed one on each line just like
  64. that. 
  65.  
  66. An example:
  67.  
  68. Function Add3(X, Y, Z: Integer): Integer;
  69. begin
  70.   ASM
  71.         move.w  X,d0
  72.         add.w   Y,d0
  73.         add.w   Z,d0
  74.         move.w  d0,@result
  75.   END;
  76. end;
  77.  
  78.  
  79. <2>Labels
  80. Labels declared in a Pascal label declaration can be used and/or defined
  81. in an ASM statement. But because assembly coding usually makes a lot of
  82. labels you can also make local labels in the ASM statement. 
  83.  
  84. Local labels do not have to be declared in a label declaration but gets
  85. known first time used. They are declared by writing an at-sign (@) as the
  86. first character. 
  87.  
  88. <2>ASSEMBLER procedure and functions
  89. If the the ASM END statement is the only statement in a procedure
  90. (or function) the procedure can be declared as an ASSEMBLER procedure.
  91. This removes the need for the BEGIN END block. The The Add3 function
  92. can now be written as:
  93.  
  94. Function Add3(X, Y, Z: Integer): Integer; ASSEMBLER;
  95. ASM
  96.         move.w  X,d0
  97.         add.w   Y,d0
  98.         add.w   Z,d0
  99.         move.w  d0,@result
  100. END;
  101.  
  102. It looks more clean. But beside the obvious savings, the compiler also
  103. speeds up your code because of some optimization: Value parameters are
  104. never copied to local area. This saves code and time. But you must take
  105. care yourself because you are not allowed to change these value variables. 
  106.  
  107. In the following example the variable P is a value parameter. As can be
  108. seen in the appendix 'Inside HighSpeed' section 'Value Parameters' only
  109. the address of a string is passed to the procedure. Because of the
  110. ASSEMBLER directive you only get the address of the original string.
  111. Without the ASSEMBLER directive you would have written LEA P,A0 instead. 
  112.  
  113. Type C_Str=PACKED array[0..255] of char;
  114. Procedure PasToCStr(P: String; var C: C_Str ); ASSEMBLER;
  115. ASM  MOVE.L   P,A0       {Address of the Pascal string}
  116.      MOVE.L   C,A1       {Address of the C string}
  117.      MOVEQ    #0,D0
  118.      MOVE.B   (A0)+,D0   {String length}
  119.      BRA      @L2
  120. @L1: MOVE.B   (A0)+,(A1)+
  121. @L2: DBRA     D0,@L1
  122.      CLR.B    (A1)       {Terminate the C string}
  123. END;
  124.  
  125.  
  126. <2>Assembler directives
  127. The only directive known is DC, Define Constant. It takes the three
  128. sizes .B, .W and .L. 
  129. DC.B blocks does always make an even number of bytes. 
  130.  
  131. Examples:
  132.   ASM
  133.         DC.B    11,'Hello World' {Pascal string}
  134.         DC.B    'Hello World',0  {C string}
  135.         DC.B    1,2,3+4+5
  136.         DC.W    7,9,13
  137.         DC.L    1
  138.   END;
  139.  
  140.  
  141. <2>Expressions
  142. It is important to notice that expressions does not always act the same
  143. way in assembly as in Pascal. 
  144.  
  145. Assume:
  146.   Const
  147.     X=4;
  148.     Y=7;
  149.   Var
  150.     M,N,O: Integer;
  151.     A: Array[0..99] of Integer;
  152.  
  153. We want to code the following in assembly:
  154.  
  155.   M:=X+Y;
  156.   M:=N+X;
  157.   M:=A[3];
  158.  
  159. The right way:
  160.  
  161.   ASM
  162.     MOVE.W   #X+Y,M      {M:=X+Y}
  163.     MOVE.W   N,D0        {M:=N+X}
  164.     ADD.W    #Y,D0
  165.     MOVE.W   D0,M
  166.     MOVE.W   A+2*3,M     {M:=A[3]. 2 because Integer}
  167.   END;
  168.  
  169. The wrong way:
  170.  
  171.   ASM
  172.     MOVE.W   X+Y,M       {M:=X+Y}
  173.     MOVE.W   N+X,M       {M:=N+X}
  174.     MOVE.W   A,D0        {M:=A[3]}
  175.     ADD.W    #3*2,D0
  176.     MOVE.W   D0,M
  177.   END;
  178.  
  179.  
  180. Registers
  181.  
  182. These are the CPU registers known by the assembler:
  183.  
  184. Data registers:      D0, D1, D2, D3, D4, D5, D6, D7,
  185. Data registers:      A0, A1, A2, A3, A4, A5, A6, A7, SP
  186. Special registers:   USP, PC, CCR, SR
  187.  
  188. The @result variable represents the position on the stack of the returned
  189. result. Remember that @result can either be the position of the result or
  190. a pointer to the result. Look in the appendix 'Inside HighSpeed' section
  191. 'Function Results' for more information.
  192.  
  193.  
  194. Addressing modes
  195. The following is the 68000 CPU's addressing modes:
  196.  
  197. Dn       Data register
  198. An       Address register direct
  199. (An)     Address register indirect
  200. (An)+    Address register indirect w/postincrement
  201. -(An)    Address register indirect w/predecrement
  202. d(An)    Address register indirect w/disp
  203. d(An,Rn) Address register indirect w/disp and index
  204. XXXX     Absolute short
  205. XXXXXXXX Absolute long
  206. d(PC)    Program counter indirect w/disp
  207. d(PC,Rn) Program counter indirect w/disp and index
  208. #XXXX    Immediate data
  209.  
  210. The Rn index field can be Dn, An, Dn.S, An.S where S is W or L for word
  211. or long. 
  212. The displacement on the two formats with index must be written. If zero
  213. then write a zero.
  214.  
  215.  
  216. Operators
  217. The following is the defined operators for use in expressions:
  218.  
  219. Highest precedence:
  220.  
  221. +    Unary plus. Does nothing
  222. -    Unary minus. Returns the negated value
  223. !    Unary negation. Return the bitwise not value
  224.  
  225. Second highest precedence:
  226.  
  227. *    Multiplication
  228. /    Integer division
  229. %    Integer remainder
  230. &    Bitwise and
  231. <<   Logical shift left
  232. >>   Logical shift right
  233.  
  234. Lowest precedence:
  235.  
  236. +    Addition
  237. -    Subtraction
  238. |    Bitwise or
  239. ^    Bitwise xor 
  240.  
  241.  
  242. Limitations
  243. Jumps with BRA, BSR etc can only be done using word offsets. BRA.B or
  244. BRA.S is not allowed. 
  245.  
  246. The only way of getting an address in the code is by using LEA or PEA
  247. (or by jumping to it/calling it).
  248.   ASM
  249.     LEA    @MyData,a0   {Ok}
  250.     PEA    @MyData      {Ok}
  251.     MOVE.W @MyData,d0   {Wrong!}
  252.   @MyData: DC.W 1,2,3,4,5
  253.   END;
  254.  
  255. The addressing mode (An,Rn.S) and (PC,Rn.S) must be prefixed by an
  256. expression. it is not allowed to write PEA (A0,D0). Instead write
  257. PEA 0(A0,D0).
  258.