c-z80.texi 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. @c Copyright (C) 2011-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 Z80-Dependent
  7. @chapter Z80 Dependent Features
  8. @end ifset
  9. @ifclear GENERIC
  10. @node Machine Dependencies
  11. @chapter Z80 Dependent Features
  12. @end ifclear
  13. @cindex Z80 support
  14. @menu
  15. * Z80 Options:: Options
  16. * Z80 Syntax:: Syntax
  17. * Z80 Floating Point:: Floating Point
  18. * Z80 Directives:: Z80 Machine Directives
  19. * Z80 Opcodes:: Opcodes
  20. @end menu
  21. @node Z80 Options
  22. @section Command-line Options
  23. @cindex Z80 options
  24. @cindex options for Z80
  25. @c man begin OPTIONS
  26. @table @gcctabopt
  27. @cindex @code{-march=} command-line option, Z80
  28. @item -march=@var{CPU}[-@var{EXT}@dots{}][+@var{EXT}@dots{}]
  29. This option specifies the target processor. The assembler will issue
  30. an error message if an attempt is made to assemble an instruction which
  31. will not execute on the target processor. The following processor names
  32. are recognized:
  33. @code{z80},
  34. @code{z180},
  35. @code{ez80},
  36. @code{gbz80},
  37. @code{z80n},
  38. @code{r800}.
  39. In addition to the basic instruction set, the assembler can be told to
  40. accept some extention mnemonics. For example,
  41. @code{-march=z180+sli+infc} extends @var{z180} with @var{SLI} instructions and
  42. @var{IN F,(C)}. The following extentions are currently supported:
  43. @code{full} (all known instructions),
  44. @code{adl} (ADL CPU mode by default, eZ80 only),
  45. @code{sli} (instruction known as @var{SLI}, @var{SLL} or @var{SL1}),
  46. @code{xyhl} (instructions with halves of index registers: @var{IXL}, @var{IXH},
  47. @var{IYL}, @var{IYH}),
  48. @code{xdcb} (instructions like @var{RotOp (II+d),R} and @var{BitOp n,(II+d),R}),
  49. @code{infc} (instruction @var{IN F,(C)} or @var{IN (C)}),
  50. @code{outc0} (instruction @var{OUT (C),0}).
  51. Note that rather than extending a basic instruction set, the extention
  52. mnemonics starting with @code{-} revoke the respective functionality:
  53. @code{-march=z80-full+xyhl} first removes all default extentions and adds
  54. support for index registers halves only.
  55. If this option is not specified then @code{-march=z80+xyhl+infc} is assumed.
  56. @cindex @code{-local-prefix} command-line option, Z80
  57. @item -local-prefix=@var{prefix}
  58. Mark all labels with specified prefix as local. But such label can be
  59. marked global explicitly in the code. This option do not change default
  60. local label prefix @code{.L}, it is just adds new one.
  61. @cindex @code{-colonless} command-line option, Z80
  62. @item -colonless
  63. Accept colonless labels. All symbols at line begin are treated as labels.
  64. @cindex @code{-sdcc} command-line option, Z80
  65. @item -sdcc
  66. Accept assembler code produced by SDCC.
  67. @cindex @code{-fp-s} command-line option, Z80
  68. @item -fp-s=@var{FORMAT}
  69. Single precision floating point numbers format. Default: ieee754 (32 bit).
  70. @cindex @code{-fp-d} command-line option, Z80
  71. @item -fp-d=@var{FORMAT}
  72. Double precision floating point numbers format. Default: ieee754 (64 bit).
  73. @end table
  74. @c man end
  75. Floating point numbers formats.
  76. @table @option
  77. @item @code{ieee754}
  78. Single or double precision IEEE754 compatible format.
  79. @item @code{half}
  80. Half precision IEEE754 compatible format (16 bits).
  81. @item @code{single}
  82. Single precision IEEE754 compatible format (32 bits).
  83. @item @code{double}
  84. Double precision IEEE754 compatible format (64 bits).
  85. @item @code{zeda32}
  86. 32 bit floating point format from z80float library by Zeda.
  87. @item @code{math48}
  88. 48 bit floating point format from Math48 package by Anders Hejlsberg.
  89. @end table
  90. @cindex Z80 Syntax
  91. @node Z80 Syntax
  92. @section Syntax
  93. The assembler syntax closely follows the 'Z80 family CPU User Manual' by
  94. Zilog.
  95. In expressions a single @samp{=} may be used as ``is equal to''
  96. comparison operator.
  97. Suffices can be used to indicate the radix of integer constants;
  98. @samp{H} or @samp{h} for hexadecimal, @samp{D} or @samp{d} for decimal,
  99. @samp{Q}, @samp{O}, @samp{q} or @samp{o} for octal, and @samp{B} for
  100. binary.
  101. The suffix @samp{b} denotes a backreference to local label.
  102. @menu
  103. * Z80-Chars:: Special Characters
  104. * Z80-Regs:: Register Names
  105. * Z80-Case:: Case Sensitivity
  106. * Z80-Labels:: Labels
  107. @end menu
  108. @node Z80-Chars
  109. @subsection Special Characters
  110. @cindex line comment character, Z80
  111. @cindex Z80 line comment character
  112. The semicolon @samp{;} is the line comment character;
  113. If a @samp{#} appears as the first character of a line then the whole
  114. line is treated as a comment, but in this case the line could also be
  115. a logical line number directive (@pxref{Comments}) or a preprocessor
  116. control command (@pxref{Preprocessing}).
  117. @cindex line separator, Z80
  118. @cindex statement separator, Z80
  119. @cindex Z80 line separator
  120. The Z80 assembler does not support a line separator character.
  121. @cindex location counter, Z80
  122. @cindex hexadecimal prefix, Z80
  123. @cindex Z80 $
  124. The dollar sign @samp{$} can be used as a prefix for hexadecimal numbers
  125. and as a symbol denoting the current location counter.
  126. @cindex character escapes, Z80
  127. @cindex Z80, \
  128. A backslash @samp{\} is an ordinary character for the Z80 assembler.
  129. @cindex character constant, Z80
  130. @cindex single quote, Z80
  131. @cindex Z80 '
  132. The single quote @samp{'} must be followed by a closing quote. If there
  133. is one character in between, it is a character constant, otherwise it is
  134. a string constant.
  135. @node Z80-Regs
  136. @subsection Register Names
  137. @cindex Z80 registers
  138. @cindex register names, Z80
  139. The registers are referred to with the letters assigned to them by
  140. Zilog. In addition @command{@value{AS}} recognizes @samp{ixl} and
  141. @samp{ixh} as the least and most significant octet in @samp{ix}, and
  142. similarly @samp{iyl} and @samp{iyh} as parts of @samp{iy}.
  143. @c The @samp{'} in @samp{ex af,af'} may be omitted.
  144. @node Z80-Case
  145. @subsection Case Sensitivity
  146. @cindex Z80, case sensitivity
  147. @cindex case sensitivity, Z80
  148. Upper and lower case are equivalent in register names, opcodes,
  149. condition codes and assembler directives.
  150. The case of letters is significant in labels and symbol names. The case
  151. is also important to distinguish the suffix @samp{b} for a backward reference
  152. to a local label from the suffix @samp{B} for a number in binary notation.
  153. @node Z80-Labels
  154. @subsection Labels
  155. @cindex labels, Z80
  156. @cindex Z80 labels
  157. Labels started by @code{.L} acts as local labels. You may specify custom local
  158. label prefix by @code{-local-prefix} command-line option.
  159. Dollar, forward and backward local labels are supported. By default, all labels
  160. are followed by colon.
  161. Legacy code with colonless labels can be built with @code{-colonless}
  162. command-line option specified. In this case all tokens at line begin are treated
  163. as labels.
  164. @node Z80 Floating Point
  165. @section Floating Point
  166. @cindex floating point, Z80
  167. @cindex Z80 floating point
  168. Floating-point numbers of following types are supported:
  169. @table @option
  170. @item @code{ieee754}
  171. Supported half, single and double precision IEEE754 compatible numbers.
  172. @item @code{zeda32}
  173. 32 bit floating point numbers from z80float library by Zeda.
  174. @item @code{math48}
  175. 48 bit floating point numbers from Math48 package by Anders Hejlsberg.
  176. @end table
  177. @node Z80 Directives
  178. @section Z80 Assembler Directives
  179. @cindex Z80-only directives
  180. @command{@value{AS}} for the Z80 supports some additional directives for
  181. compatibility with other assemblers.
  182. These are the additional directives in @code{@value{AS}} for the Z80:
  183. @table @code
  184. @item @code{.assume ADL = @var{expression}}
  185. @cindex @code{.assume} directive, Z80
  186. Set ADL status for eZ80. Non-zero value enable compilation in ADL mode else
  187. used Z80 mode. ADL and Z80 mode produces incompatible object code. Mixing
  188. both of them within one binary may lead problems with disassembler.
  189. @item @code{db @var{expression}|@var{string}[,@var{expression}|@var{string}...]}
  190. @cindex @code{db} directive, Z80
  191. @itemx @code{defb @var{expression}|@var{string}[,@var{expression}|@var{string}...]}
  192. @cindex @code{defb} directive, Z80
  193. @itemx @code{defm @var{string}[,@var{string}...]}
  194. @cindex @code{defm} directive, Z80
  195. For each @var{string} the characters are copied to the object file, for
  196. each other @var{expression} the value is stored in one byte.
  197. A warning is issued in case of an overflow.
  198. Backslash symbol in the strings is generic symbol, it cannot be used as
  199. escape character. @xref{Ascii,,@code{.ascii}}.
  200. @item @code{dw @var{expression}[,@var{expression}...]}
  201. @cindex @code{dw} directive, Z80
  202. @itemx @code{defw @var{expression}[,@var{expression}...]}
  203. @cindex @code{defw} directive, Z80
  204. For each @var{expression} the value is stored in two bytes, ignoring
  205. overflow.
  206. @item @code{d24 @var{expression}[,@var{expression}...]}
  207. @cindex @code{d24} directive, Z80
  208. @itemx @code{def24 @var{expression}[,@var{expression}...]}
  209. @cindex @code{def24} directive, Z80
  210. For each @var{expression} the value is stored in three bytes, ignoring
  211. overflow.
  212. @item @code{d32 @var{expression}[,@var{expression}...]}
  213. @cindex @code{d32} directive, Z80
  214. @itemx @code{def32 @var{expression}[,@var{expression}...]}
  215. @cindex @code{def32} directive, Z80
  216. For each @var{expression} the value is stored in four bytes, ignoring
  217. overflow.
  218. @item @code{ds @var{count}[, @var{value}]}
  219. @cindex @code{ds} directive, Z80
  220. @itemx @code{defs @var{count}[, @var{value}]}
  221. @cindex @code{defs} directive, Z80
  222. @c Synonyms for @code{ds.b},
  223. @c which should have been described elsewhere
  224. Fill @var{count} bytes in the object file with @var{value}, if
  225. @var{value} is omitted it defaults to zero.
  226. @item @code{@var{symbol} defl @var{expression}}
  227. @cindex @code{defl} directive, Z80
  228. The @code{defl} directive is like @code{.set} but with different
  229. syntax. @xref{Set,,@code{.set}}.
  230. It set the value of @var{symbol} to @var{expression}. Symbols defined
  231. with @code{defl} are not protected from redefinition.
  232. @item @code{@var{symbol} equ @var{expression}}
  233. @cindex @code{equ} directive, Z80
  234. The @code{equ} directive is like @code{.equiv} but with different
  235. syntax. @xref{Equiv, ,@code{.equiv}}.
  236. It set the value of @var{symbol} to @var{expression}. It is an error
  237. if @var{symbol} is already defined. Symbols defined with @code{equ}
  238. are not protected from redefinition.
  239. @item @code{psect @var{name}}
  240. @cindex @code{psect} directive, Z80
  241. A synonym for @code{.section}, no second argument should be given.
  242. @xref{Section,,@code{.section}}.
  243. @item @code{xdef @var{symbol}}
  244. @cindex @code{xdef} directive, Z80
  245. A synonym for @code{.global}, make @var{symbol} is visible to linker.
  246. @xref{Global,,@code{.global}}.
  247. @item @code{xref @var{name}}
  248. @cindex @code{xref} directive, Z80
  249. A synonym for @code{.extern} (@ref{Extern,,@code{.extern}}).
  250. @ignore
  251. The following attributes will possibly be recognized in the future
  252. @table @code
  253. @item abs
  254. The section is to be absolute. @code{@value{AS}} will issue an error
  255. message because it can not produce an absolute section.
  256. @item global
  257. The section is to be concatenated with other sections of the same name
  258. by the linker, this is the default.
  259. @item local
  260. The section is not global. @code{@value{AS}} will issue a warning if
  261. object file format is not soff.
  262. @item ovrld
  263. The section is to be overlapped with other sections of the same name by
  264. the linker. @code{@value{AS}} will issue an error message
  265. because it can not mark a section as such.
  266. @item pure
  267. The section is marked as read only.
  268. @end table
  269. @end ignore
  270. @end table
  271. @node Z80 Opcodes
  272. @section Opcodes
  273. In line with common practice, Z80 mnemonics are used for the Z80,
  274. Z80N, Z180, eZ80, Ascii R800 and the GameBoy Z80.
  275. In many instructions it is possible to use one of the half index
  276. registers (@samp{ixl},@samp{ixh},@samp{iyl},@samp{iyh}) in stead of an
  277. 8-bit general purpose register. This yields instructions that are
  278. documented on the eZ80 and the R800, undocumented on the Z80 and
  279. unsupported on the Z180.
  280. Similarly @code{in f,(c)} is documented on the R800, undocumented on
  281. the Z80 and unsupported on the Z180 and the eZ80.
  282. The assembler also supports the following undocumented Z80-instructions,
  283. that have not been adopted in any other instruction set:
  284. @table @code
  285. @item out (c),0
  286. Sends zero to the port pointed to by register @code{C}.
  287. @item sli @var{m}
  288. Equivalent to @code{@var{m} = (@var{m}<<1)+1}, the operand @var{m} can
  289. be any operand that is valid for @samp{sla}. One can use @samp{sll} as a
  290. synonym for @samp{sli}.
  291. @item @var{op} (ix+@var{d}), @var{r}
  292. This is equivalent to
  293. @example
  294. ld @var{r}, (ix+@var{d})
  295. @var{op} @var{r}
  296. ld (ix+@var{d}), @var{r}
  297. @end example
  298. The operation @samp{@var{op}} may be any of @samp{res @var{b},},
  299. @samp{set @var{b},}, @samp{rl}, @samp{rlc}, @samp{rr}, @samp{rrc},
  300. @samp{sla}, @samp{sli}, @samp{sra} and @samp{srl}, and the register
  301. @samp{@var{r}} may be any of @samp{a}, @samp{b}, @samp{c}, @samp{d},
  302. @samp{e}, @samp{h} and @samp{l}.
  303. @item @var{op} (iy+@var{d}), @var{r}
  304. As above, but with @samp{iy} instead of @samp{ix}.
  305. @end table
  306. The web site at @uref{http://www.z80.info} is a good starting place to
  307. find more information on programming the Z80.
  308. You may enable or disable any of these instructions for any target CPU
  309. even this instruction is not supported by any real CPU of this type.
  310. Useful for custom CPU cores.