c-z80.texi 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. @c Copyright (C) 2011-2015 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 Options
  23. @cindex Z80 options
  24. @cindex options for Z80
  25. The Zilog Z80 and Ascii R800 version of @code{@value{AS}} have a few machine
  26. dependent options.
  27. @table @option
  28. @cindex @code{-z80} command line option, Z80
  29. @item -z80
  30. Produce code for the Z80 processor. There are additional options to
  31. request warnings and error messages for undocumented instructions.
  32. @item -ignore-undocumented-instructions
  33. @itemx -Wnud
  34. Silently assemble undocumented Z80-instructions that have been adopted
  35. as documented R800-instructions.
  36. @item -ignore-unportable-instructions
  37. @itemx -Wnup
  38. Silently assemble all undocumented Z80-instructions.
  39. @item -warn-undocumented-instructions
  40. @itemx -Wud
  41. Issue warnings for undocumented Z80-instructions that work on R800, do
  42. not assemble other undocumented instructions without warning.
  43. @item -warn-unportable-instructions
  44. @itemx -Wup
  45. Issue warnings for other undocumented Z80-instructions, do not treat any
  46. undocumented instructions as errors.
  47. @item -forbid-undocumented-instructions
  48. @itemx -Fud
  49. Treat all undocumented z80-instructions as errors.
  50. @item -forbid-unportable-instructions
  51. @itemx -Fup
  52. Treat undocumented z80-instructions that do not work on R800 as errors.
  53. @cindex @code{-r800} command line option, Z80
  54. @item -r800
  55. Produce code for the R800 processor. The assembler does not support
  56. undocumented instructions for the R800.
  57. In line with common practice, @code{@value{AS}} uses Z80 instruction names
  58. for the R800 processor, as far as they exist.
  59. @end table
  60. @cindex Z80 Syntax
  61. @node Z80 Syntax
  62. @section Syntax
  63. The assembler syntax closely follows the 'Z80 family CPU User Manual' by
  64. Zilog.
  65. In expressions a single @samp{=} may be used as ``is equal to''
  66. comparison operator.
  67. Suffices can be used to indicate the radix of integer constants;
  68. @samp{H} or @samp{h} for hexadecimal, @samp{D} or @samp{d} for decimal,
  69. @samp{Q}, @samp{O}, @samp{q} or @samp{o} for octal, and @samp{B} for
  70. binary.
  71. The suffix @samp{b} denotes a backreference to local label.
  72. @menu
  73. * Z80-Chars:: Special Characters
  74. * Z80-Regs:: Register Names
  75. * Z80-Case:: Case Sensitivity
  76. @end menu
  77. @node Z80-Chars
  78. @subsection Special Characters
  79. @cindex line comment character, Z80
  80. @cindex Z80 line comment character
  81. The semicolon @samp{;} is the line comment character;
  82. If a @samp{#} appears as the first character of a line then the whole
  83. line is treated as a comment, but in this case the line could also be
  84. a logical line number directive (@pxref{Comments}) or a preprocessor
  85. control command (@pxref{Preprocessing}).
  86. @cindex line separator, Z80
  87. @cindex statement separator, Z80
  88. @cindex Z80 line separator
  89. The Z80 assembler does not support a line separator character.
  90. @cindex location counter, Z80
  91. @cindex hexadecimal prefix, Z80
  92. @cindex Z80 $
  93. The dollar sign @samp{$} can be used as a prefix for hexadecimal numbers
  94. and as a symbol denoting the current location counter.
  95. @cindex character escapes, Z80
  96. @cindex Z80, \
  97. A backslash @samp{\} is an ordinary character for the Z80 assembler.
  98. @cindex character constant, Z80
  99. @cindex single quote, Z80
  100. @cindex Z80 '
  101. The single quote @samp{'} must be followed by a closing quote. If there
  102. is one character in between, it is a character constant, otherwise it is
  103. a string constant.
  104. @node Z80-Regs
  105. @subsection Register Names
  106. @cindex Z80 registers
  107. @cindex register names, Z80
  108. The registers are referred to with the letters assigned to them by
  109. Zilog. In addition @command{@value{AS}} recognizes @samp{ixl} and
  110. @samp{ixh} as the least and most significant octet in @samp{ix}, and
  111. similarly @samp{iyl} and @samp{iyh} as parts of @samp{iy}.
  112. @c The @samp{'} in @samp{ex af,af'} may be omitted.
  113. @node Z80-Case
  114. @subsection Case Sensitivity
  115. @cindex Z80, case sensitivity
  116. @cindex case sensitivity, Z80
  117. Upper and lower case are equivalent in register names, opcodes,
  118. condition codes and assembler directives.
  119. The case of letters is significant in labels and symbol names. The case
  120. is also important to distinguish the suffix @samp{b} for a backward reference
  121. to a local label from the suffix @samp{B} for a number in binary notation.
  122. @node Z80 Floating Point
  123. @section Floating Point
  124. @cindex floating point, Z80
  125. @cindex Z80 floating point
  126. Floating-point numbers are not supported.
  127. @node Z80 Directives
  128. @section Z80 Assembler Directives
  129. @command{@value{AS}} for the Z80 supports some additional directives for
  130. compatibility with other assemblers.
  131. @cindex Z80-only directives
  132. These are the additional directives in @code{@value{AS}} for the Z80:
  133. @table @code
  134. @item db @var{expression}|@var{string}[,@var{expression}|@var{string}...]
  135. @itemx defb @var{expression}|@var{string}[,@var{expression}|@var{string}...]
  136. For each @var{string} the characters are copied to the object file, for
  137. each other @var{expression} the value is stored in one byte.
  138. A warning is issued in case of an overflow.
  139. @item dw @var{expression}[,@var{expression}...]
  140. @itemx defw @var{expression}[,@var{expression}...]
  141. For each @var{expression} the value is stored in two bytes, ignoring
  142. overflow.
  143. @item d24 @var{expression}[,@var{expression}...]
  144. @itemx def24 @var{expression}[,@var{expression}...]
  145. For each @var{expression} the value is stored in three bytes, ignoring
  146. overflow.
  147. @item d32 @var{expression}[,@var{expression}...]
  148. @itemx def32 @var{expression}[,@var{expression}...]
  149. For each @var{expression} the value is stored in four bytes, ignoring
  150. overflow.
  151. @item ds @var{count}[, @var{value}]
  152. @itemx defs @var{count}[, @var{value}]
  153. @c Synonyms for @code{ds.b},
  154. @c which should have been described elsewhere
  155. Fill @var{count} bytes in the object file with @var{value}, if
  156. @var{value} is omitted it defaults to zero.
  157. @item @var{symbol} equ @var{expression}
  158. @itemx @var{symbol} defl @var{expression}
  159. These directives set the value of @var{symbol} to @var{expression}. If
  160. @code{equ} is used, it is an error if @var{symbol} is already defined.
  161. Symbols defined with @code{equ} are not protected from redefinition.
  162. @item set
  163. This is a normal instruction on Z80, and not an assembler directive.
  164. @item psect @var{name}
  165. A synonym for @xref{Section}, no second argument should be given.
  166. @ignore
  167. The following attributes will possibly be recognized in the future
  168. @table @code
  169. @item abs
  170. The section is to be absolute. @code{@value{AS}} will issue an error
  171. message because it can not produce an absolute section.
  172. @item global
  173. The section is to be concatenated with other sections of the same name
  174. by the linker, this is the default.
  175. @item local
  176. The section is not global. @code{@value{AS}} will issue a warning if
  177. object file format is not soff.
  178. @item ovrld
  179. The section is to be overlapped with other sections of the same name by
  180. the linker. @code{@value{AS}} will issue an error message
  181. because it can not mark a section as such.
  182. @item pure
  183. The section is marked as read only.
  184. @end table
  185. @end ignore
  186. @end table
  187. @node Z80 Opcodes
  188. @section Opcodes
  189. In line with common practice, Z80 mnemonics are used for both the Z80 and
  190. the R800.
  191. In many instructions it is possible to use one of the half index
  192. registers (@samp{ixl},@samp{ixh},@samp{iyl},@samp{iyh}) in stead of an
  193. 8-bit general purpose register. This yields instructions that are
  194. documented on the R800 and undocumented on the Z80.
  195. Similarly @code{in f,(c)} is documented on the R800 and undocumented on
  196. the Z80.
  197. The assembler also supports the following undocumented Z80-instructions,
  198. that have not been adopted in the R800 instruction set:
  199. @table @code
  200. @item out (c),0
  201. Sends zero to the port pointed to by register c.
  202. @item sli @var{m}
  203. Equivalent to @code{@var{m} = (@var{m}<<1)+1}, the operand @var{m} can
  204. be any operand that is valid for @samp{sla}. One can use @samp{sll} as a
  205. synonym for @samp{sli}.
  206. @item @var{op} (ix+@var{d}), @var{r}
  207. This is equivalent to
  208. @example
  209. ld @var{r}, (ix+@var{d})
  210. @var{opc} @var{r}
  211. ld (ix+@var{d}), @var{r}
  212. @end example
  213. The operation @samp{@var{opc}} may be any of @samp{res @var{b},},
  214. @samp{set @var{b},}, @samp{rl}, @samp{rlc}, @samp{rr}, @samp{rrc},
  215. @samp{sla}, @samp{sli}, @samp{sra} and @samp{srl}, and the register
  216. @samp{@var{r}} may be any of @samp{a}, @samp{b}, @samp{c}, @samp{d},
  217. @samp{e}, @samp{h} and @samp{l}.
  218. @item @var{opc} (iy+@var{d}), @var{r}
  219. As above, but with @samp{iy} instead of @samp{ix}.
  220. @end table
  221. The web site at @uref{http://www.z80.info} is a good starting place to
  222. find more information on programming the Z80.