c-s12z.texi 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. @c Copyright (C) 2018-2022 Free Software Foundation, Inc.
  2. @c This is part of the GAS manual.
  3. @c For copying conditions, see the file as.texinfo.
  4. @ifset GENERIC
  5. @page
  6. @node S12Z-Dependent
  7. @chapter S12Z Dependent Features
  8. @end ifset
  9. @ifclear GENERIC
  10. @node Machine Dependencies
  11. @chapter S12Z Dependent Features
  12. @end ifclear
  13. The Freescale S12Z version of @code{@value{AS}} has a few machine
  14. dependent features.
  15. @cindex S12Z support
  16. @menu
  17. * S12Z Options:: S12Z Options
  18. * S12Z Syntax:: Syntax
  19. @end menu
  20. @node S12Z Options
  21. @section S12Z Options
  22. @cindex options, S12Z
  23. @cindex S12Z options
  24. The S12Z version of @code{@value{AS}} recognizes the following options:
  25. @table @samp
  26. @item -mreg-prefix=@var{prefix}
  27. @cindex @samp{-mreg-prefix=@var{prefix}} option, reg-prefix
  28. You can use the @samp{-mreg-prefix=@var{pfx}} option to indicate
  29. that the assembler should expect all register names to be prefixed with the
  30. string @var{pfx}.
  31. For an explanation of what this means and why it might be needed,
  32. see @ref{S12Z Register Notation}.
  33. @item -mdollar-hex
  34. @cindex @samp{-mdollar-hex} option, dollar-hex
  35. @cindex hexadecimal prefix, S12Z
  36. The @samp{-mdollar-hex} option affects the way that literal hexadecimal constants
  37. are represented. When this option is specified, the assembler will consider
  38. the @samp{$} character as the start of a hexadecimal integer constant. Without
  39. this option, the standard value of @samp{0x} is expected.
  40. If you use this option, then you cannot have symbol names starting with @samp{$}.
  41. @samp{-mdollar-hex} is implied if the @samp{--traditional-format}
  42. (@pxref{traditional-format}) is used.
  43. @end table
  44. @node S12Z Syntax
  45. @section Syntax
  46. @menu
  47. * S12Z Syntax Overview:: General description
  48. * S12Z Addressing Modes:: Operands and their semantics
  49. * S12Z Register Notation:: How to refer to registers
  50. @end menu
  51. @cindex S12Z syntax
  52. @cindex syntax, S12Z
  53. @node S12Z Syntax Overview
  54. @subsection Overview
  55. In the S12Z syntax, the instruction name comes first and it may
  56. be followed by one, or by several operands.
  57. In most cases the maximum number of operands is three.
  58. Operands are separated by a comma (@samp{,}).
  59. A comma however does not act as a separator if it appears within parentheses
  60. (@samp{()}) or within square brackets (@samp{[]}).
  61. @code{@value{AS}} will complain if too many, too few or inappropriate operands
  62. are specified for a given instruction.
  63. Some instructions accept and (in certain situations require) a suffix
  64. indicating the size of the operand.
  65. The suffix is separated from the instruction name by a period (@samp{.})
  66. and may be one of @samp{b}, @samp{w}, @samp{p} or @samp{l} indicating
  67. `byte' (a single byte), `word' (2 bytes), `pointer' (3 bytes) or `long' (4 bytes)
  68. respectively.
  69. Example:
  70. @smallexample
  71. bset.b 0xA98, #5
  72. mov.b #6, 0x2409
  73. ld d0, #4
  74. mov.l (d0, x), 0x2409
  75. inc d0
  76. cmp d0, #12
  77. blt *-4
  78. lea x, 0x2409
  79. st y, (1, x)
  80. @end smallexample
  81. @cindex line comment character, S12Z
  82. The presence of a @samp{;} character anywhere
  83. on a line indicates the start of a comment that extends to the end of
  84. that line.
  85. A @samp{*} or a @samp{#} character at the start of a line also
  86. introduces a line comment, but these characters do not work elsewhere
  87. on the line. If the first character of the line is a @samp{#} then as
  88. well as starting a comment, the line could also be logical line number
  89. directive (@pxref{Comments}) or a preprocessor control command
  90. (@pxref{Preprocessing}).
  91. @cindex line separator, S12Z
  92. @cindex statement separator, S12Z
  93. @cindex S12Z line separator
  94. The S12Z assembler does not currently support a line separator
  95. character.
  96. @node S12Z Addressing Modes
  97. @subsection Addressing Modes
  98. @cindex S12Z addressing modes
  99. @cindex addressing modes, S12Z
  100. The following addressing modes are understood for the S12Z.
  101. @table @dfn
  102. @item Immediate
  103. @samp{#@var{number}}
  104. @item Immediate Bit Field
  105. @samp{#@var{width}:@var{offset}}
  106. Bit field instructions in the immediate mode require the width and offset to
  107. be specified.
  108. The @var{width} parameter specifies the number of bits in the field.
  109. It should be a number in the range [1,32].
  110. @var{Offset} determines the position within the field where the operation
  111. should start.
  112. It should be a number in the range [0,31].
  113. @item Relative
  114. @samp{*@var{symbol}}, or @samp{*[+-]@var{digits}}
  115. Program counter relative addresses have a width of 15 bits.
  116. Thus, they must be within the range [-32768, 32767].
  117. @item Register
  118. @samp{@var{reg}}
  119. @cindex register names, S12Z
  120. Some instructions accept a register as an operand.
  121. In general, @var{reg} may be a
  122. data register (@samp{D0}, @samp{D1} @dots{} @samp{D7}),
  123. the @samp{X} register or the @samp{Y} register.
  124. A few instructions accept as an argument the stack pointer
  125. register (@samp{S}), and/or the program counter (@samp{P}).
  126. Some very special instructions accept arguments which refer to the
  127. condition code register. For these arguments the syntax is
  128. @samp{CCR}, @samp{CCH} or @samp{CCL} which refer to the complete
  129. condition code register, the condition code register high byte
  130. and the condition code register low byte respectively.
  131. @item Absolute Direct
  132. @samp{@var{symbol}}, or @samp{@var{digits}}
  133. @item Absolute Indirect
  134. @samp{[@var{symbol}}, or @samp{@var{digits}]}
  135. @item Constant Offset Indexed
  136. @samp{(@var{number},@var{reg})}
  137. @var{Reg} may be either @samp{X}, @samp{Y}, @samp{S} or
  138. @samp{P} or one of the data registers @samp{D0}, @samp{D1} @dots{}
  139. @samp{D7}.
  140. If any of the registers @samp{D2} @dots{} @samp{D5} are specified, then the
  141. register value is treated as a signed value.
  142. Otherwise it is treated as unsigned.
  143. @var{Number} may be any integer in the range [-8388608,8388607].
  144. @item Offset Indexed Indirect
  145. @samp{[@var{number},@var{reg}]}
  146. @var{Reg} may be either @samp{X}, @samp{Y}, @samp{S} or
  147. @samp{P}.
  148. @var{Number} may be any integer in the range [-8388608,8388607].
  149. @item Auto Pre-Increment/Pre-Decrement/Post-Increment/Post-Decrement
  150. @samp{-@var{reg}},
  151. @samp{+@var{reg}},
  152. @samp{@var{reg}-} or
  153. @samp{@var{reg}+}
  154. This addressing mode is typically used to access a value at an address,
  155. and simultaneously to increment/decrement the register pointing to that
  156. address.
  157. Thus @var{reg} may be any of the 24 bit registers @samp{X}, @samp{Y}, or
  158. @samp{S}.
  159. Pre-increment and post-decrement are not available for
  160. register @samp{S} (only post-increment and pre-decrement are available).
  161. @item Register Offset Direct
  162. @samp{(@var{data-reg},@var{reg})}
  163. @var{Reg} can be either @samp{X}, @samp{Y}, or @samp{S}.
  164. @var{Data-reg}
  165. must be one of the data registers @samp{D0}, @samp{D1} @dots{} @samp{D7}.
  166. If any of the registers @samp{D2} @dots{} @samp{D5} are specified, then
  167. the register value is treated as a signed value.
  168. Otherwise it is treated as unsigned.
  169. @item Register Offset Indirect
  170. @samp{[@var{data-reg},@var{reg}]}
  171. @var{Reg} can be either @samp{X} or @samp{Y}.
  172. @var{Data-reg}
  173. must be one of the data registers @samp{D0}, @samp{D1} @dots{} @samp{D7}.
  174. If any of the registers @samp{D2} @dots{} @samp{D5} are specified, then
  175. the register value is treated as a signed value.
  176. Otherwise it is treated as unsigned.
  177. @end table
  178. For example:
  179. @smallexample
  180. trap #197 ;; Immediate mode
  181. bra *+49 ;; Relative mode
  182. bra .L0 ;; ditto
  183. jmp 0xFE0034 ;; Absolute direct mode
  184. jmp [0xFD0012] ;; Absolute indirect mode
  185. inc.b (4,x) ;; Constant offset indexed mode
  186. jsr (45, d0) ;; ditto
  187. dec.w [4,y] ;; Constant offset indexed indirect mode
  188. clr.p (-s) ;; Pre-decrement mode
  189. neg.l (d0, s) ;; Register offset direct mode
  190. com.b [d1, x] ;; Register offset indirect mode
  191. psh cch ;; Register mode
  192. @end smallexample
  193. @node S12Z Register Notation
  194. @subsection Register Notation
  195. @cindex register notation, S12Z
  196. Without a register prefix (@pxref{S12Z Options}), S12Z assembler code is expected in the traditional
  197. format like this:
  198. @smallexample
  199. lea s, (-2,s)
  200. st d2, (0,s)
  201. ld x, symbol
  202. tfr d2, d6
  203. cmp d6, #1532
  204. @end smallexample
  205. @noindent
  206. However, if @code{@value{AS}} is started with (for example) @samp{-mreg-prefix=%}
  207. then all register names must be prefixed with @samp{%} as follows:
  208. @smallexample
  209. lea %s, (-2,%s)
  210. st %d2, (0,%s)
  211. ld %x, symbol
  212. tfr %d2, %d6
  213. cmp %d6, #1532
  214. @end smallexample
  215. The register prefix feature is intended to be used by compilers
  216. to avoid ambiguity between symbols and register names.
  217. Consider the following assembler instruction:
  218. @smallexample
  219. st d0, d1
  220. @end smallexample
  221. @noindent
  222. The destination operand of this instruction could either refer to the register
  223. @samp{D1}, or it could refer to the symbol named ``d1''.
  224. If the latter is intended then @code{@value{AS}} must be invoked with
  225. @samp{-mreg-prefix=@var{pfx}} and the code written as
  226. @smallexample
  227. st @var{pfx}d0, d1
  228. @end smallexample
  229. @noindent
  230. where @var{pfx} is the chosen register prefix.
  231. For this reason, compiler back-ends should choose a register prefix which
  232. cannot be confused with a symbol name.