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