include/elf/
[deliverable/binutils-gdb.git] / gas / doc / c-mmix.texi
CommitLineData
973eb340 1@c Copyright 2001, 2002 Free Software Foundation, Inc.
3c3bdf30
NC
2@c This is part of the GAS manual.
3@c For copying conditions, see the file as.texinfo.
4@c MMIX description by Hans-Peter Nilsson, hp@bitrange.com
5@ifset GENERIC
6@page
7@node MMIX-Dependent
8@chapter MMIX Dependent Features
9@end ifset
10@ifclear GENERIC
11@node Machine Dependencies
12@chapter MMIX Dependent Features
13@end ifclear
14
15@cindex MMIX support
16@menu
17* MMIX-Opts:: Command-line Options
18* MMIX-Expand:: Instruction expansion
19* MMIX-Syntax:: Syntax
20* MMIX-mmixal:: Differences to @code{mmixal} syntax and semantics
21@end menu
22
23@node MMIX-Opts
24@section Command-line Options
25
26@cindex options, MMIX
27@cindex MMIX options
28The MMIX version of @code{@value{AS}} has some machine-dependent options.
29
30@cindex @samp{--fixed-special-register-names} command line option, MMIX
31When @samp{--fixed-special-register-names} is specified, only the register
32names specified in @ref{MMIX-Regs} are recognized in the instructions
33@code{PUT} and @code{GET}.
34
35@cindex @samp{--globalize-symbols} command line option, MMIX
36You can use the @samp{--globalize-symbols} to make all symbols global.
37This option is useful when splitting up a @code{mmixal} program into
38several files.
39
40@cindex @samp{--gnu-syntax} command line option, MMIX
41The @samp{--gnu-syntax} turns off most syntax compatibility with
42@code{mmixal}. Its usability is currently doubtful.
43
44@cindex @samp{--relax} command line option, MMIX
45The @samp{--relax} option is not fully supported, but will eventually make
46the object file prepared for linker relaxation.
47
48@cindex @samp{--no-predefined-syms} command line option, MMIX
49If you want to avoid inadvertently calling a predefined symbol and would
50rather get an error, for example when using @code{@value{AS}} with a
51compiler or other machine-generated code, specify
52@samp{--no-predefined-syms}. This turns off built-in predefined
53definitions of all such symbols, including rounding-mode symbols, segment
54symbols, @samp{BIT} symbols, and @code{TRAP} symbols used in @code{mmix}
55``system calls''. It also turns off predefined special-register names,
56except when used in @code{PUT} and @code{GET} instructions.
57
58@cindex @samp{--no-expand} command line option, MMIX
59By default, some instructions are expanded to fit the size of the operand
60or an external symbol (@pxref{MMIX-Expand}). By passing
61@samp{--no-expand}, no such expansion will be done, instead causing errors
62at link time if the operand does not fit.
63
64@cindex @samp{--no-merge-gregs} command line option, MMIX
13f7ad58
HPN
65The @code{mmixal} documentation (@pxref{mmixsite}) specifies that global
66registers allocated with the @samp{GREG} directive (@pxref{MMIX-greg}) and
3c3bdf30
NC
67initialized to the same non-zero value, will refer to the same global
68register. This isn't strictly enforcable in @code{@value{AS}} since the
69final addresses aren't known until link-time, but it will do an effort
70unless the @samp{--no-merge-gregs} option is specified. (Register merging
71isn't yet implemented in @code{@value{LD}}.)
72
73@cindex @samp{-x} command line option, MMIX
74@code{@value{AS}} will warn every time it expands an instruction to fit an
75operand unless the option @samp{-x} is specified. It is believed that
76this behaviour is more useful than just mimicking @code{mmixal}'s
77behaviour, in which instructions are only expanded if the @samp{-x} option
78is specified, and assembly fails otherwise, when an instruction needs to
79be expanded. It needs to be kept in mind that @code{mmixal} is both an
80assembler and linker, while @code{@value{AS}} will expand instructions
81that at link stage can be contracted. (Though linker relaxation isn't yet
973eb340
HPN
82implemented in @code{@value{LD}}.) The option @samp{-x} also imples
83@samp{--linker-allocated-gregs}.
84
85@cindex @samp{--linker-allocated-gregs} command line option, MMIX
86Usually a two-operand-expression (@pxref{GREG-base}) without a matching
87@samp{GREG} directive is treated as an error by @code{@value{AS}}. When
88the option @samp{--linker-allocated-gregs} is in effect, they are instead
89passed through to the linker, which will allocate as many global registers
90as is needed.
3c3bdf30
NC
91
92@node MMIX-Expand
93@section Instruction expansion
94
95@cindex instruction expansion, MMIX
96When @code{@value{AS}} encounters an instruction with an operand that is
97either not known or does not fit the operand size of the instruction,
98@code{@value{AS}} (and @code{@value{LD}}) will expand the instruction into
99a sequence of instructions semantically equivalent to the operand fitting
100the instruction. Expansion will take place for the following
101instructions:
102
103@table @asis
104@item @samp{GETA}
105Expands to a sequence of four instructions: @code{SETL}, @code{INCML},
106@code{INCMH} and @code{INCH}. The operand must be a multiple of four.
107@item Conditional branches
108A branch instruction is turned into a branch with the complemented
109condition and prediction bit over five instructions; four instructions
110setting @code{$255} to the operand value, which like with @code{GETA} must
111be a multiple of four, and a final @code{GO $255,$255,0}.
112@item @samp{PUSHJ}
113Similar to expansion for conditional branches; four instructions set
114@code{$255} to the operand value, followed by a @code{PUSHGO $255,$255,0}.
115@item @samp{JMP}
116Similar to conditional branches and @code{PUSHJ}. The final instruction
117is @code{GO $255,$255,0}.
118@end table
119
120The linker @code{@value{LD}} is expected to shrink these expansions for
121code assembled with @samp{--relax} (though not currently implemented).
122
123@node MMIX-Syntax
124@section Syntax
125
126The assembly syntax is supposed to be upward compatible with that
127described in Sections 1.3 and 1.4 of @samp{The Art of Computer
128Programming, Volume 1}. Draft versions of those chapters as well as other
129MMIX information is located at
13f7ad58 130@anchor{mmixsite}@url{http://www-cs-faculty.stanford.edu/~knuth/mmix-news.html}.
3c3bdf30
NC
131Most code examples from the mmixal package located there should work
132unmodified when assembled and linked as single files, with a few
133noteworthy exceptions (@pxref{MMIX-mmixal}).
134
135Before an instruction is emitted, the current location is aligned to the
136next four-byte boundary. If a label is defined at the beginning of the
137line, its value will be the aligned value.
138
139In addition to the traditional hex-prefix @samp{0x}, a hexadecimal number
140can also be specified by the prefix character @samp{#}.
141
142After all operands to an MMIX instruction or directive have been
143specified, the rest of the line is ignored, treated as a comment.
144
145@menu
146* MMIX-Chars:: Special Characters
147* MMIX-Symbols:: Symbols
148* MMIX-Regs:: Register Names
149* MMIX-Pseudos:: Assembler Directives
150@end menu
151
152@node MMIX-Chars
153@subsection Special Characters
154@cindex line comment characters, MMIX
155@cindex MMIX line comment characters
156
157The characters @samp{*} and @samp{#} are line comment characters; each
158start a comment at the beginning of a line, but only at the beginning of a
159line. A @samp{#} prefixes a hexadecimal number if found elsewhere on a
160line.
161
162Two other characters, @samp{%} and @samp{!}, each start a comment anywhere
163on the line. Thus you can't use the @samp{modulus} and @samp{not}
164operators in expressions normally associated with these two characters.
165
166A @samp{;} is a line separator, treated as a new-line, so separate
167instructions can be specified on a single line.
168
169@node MMIX-Symbols
170@subsection Symbols
171The character @samp{:} is permitted in identifiers. There are two
172exceptions to it being treated as any other symbol character: if a symbol
173begins with @samp{:}, it means that the symbol is in the global namespace
174and that the current prefix should not be prepended to that symbol
13f7ad58 175(@pxref{MMIX-prefix}). The @samp{:} is then not considered part of the
3c3bdf30
NC
176symbol. For a symbol in the label position (first on a line), a @samp{:}
177at the end of a symbol is silently stripped off. A label is permitted,
178but not required, to be followed by a @samp{:}, as with many other
179assembly formats.
180
181The character @samp{@@} in an expression, is a synonym for @samp{.}, the
182current location.
183
184In addition to the common forward and backward local symbol formats
185(@pxref{Symbol Names}), they can be specified with upper-case @samp{B} and
186@samp{F}, as in @samp{8B} and @samp{9F}. A local label defined for the
187current position is written with a @samp{H} appended to the number:
188@smallexample
1893H LDB $0,$1,2
190@end smallexample
191This and traditional local-label formats cannot be mixed: a label must be
192defined and referred to using the same format.
193
194There's a minor caveat: just as for the ordinary local symbols, the local
195symbols are translated into ordinary symbols using control characters are
196to hide the ordinal number of the symbol. Unfortunately, these symbols
197are not translated back in error messages. Thus you may see confusing
198error messages when local symbols are used. Control characters
199@samp{\003} (control-C) and @samp{\004} (control-D) are used for the
200MMIX-specific local-symbol syntax.
201
202The symbol @samp{Main} is handled specially; it is always global.
203
204By defining the symbols @samp{__.MMIX.start..text} and
205@samp{__.MMIX.start..data}, the address of respectively the @samp{.text}
206and @samp{.data} segments of the final program can be defined, though when
207linking more than one object file, the code or data in the object file
208containing the symbol is not guaranteed to be start at that position; just
13f7ad58 209the final executable. @xref{MMIX-loc}.
3c3bdf30
NC
210
211@node MMIX-Regs
212@subsection Register names
213@cindex register names, MMIX
214@cindex MMIX register names
215
216Local and global registers are specified as @samp{$0} to @samp{$255}.
217The recognized special register names are @samp{rJ}, @samp{rA}, @samp{rB},
218@samp{rC}, @samp{rD}, @samp{rE}, @samp{rF}, @samp{rG}, @samp{rH},
219@samp{rI}, @samp{rK}, @samp{rL}, @samp{rM}, @samp{rN}, @samp{rO},
220@samp{rP}, @samp{rQ}, @samp{rR}, @samp{rS}, @samp{rT}, @samp{rU},
221@samp{rV}, @samp{rW}, @samp{rX}, @samp{rY}, @samp{rZ}, @samp{rBB},
222@samp{rTT}, @samp{rWW}, @samp{rXX}, @samp{rYY} and @samp{rZZ}. A leading
223@samp{:} is optional for special register names.
224
225Local and global symbols can be equated to register names and used in
226place of ordinary registers.
227
228Similarly for special registers, local and global symbols can be used.
229Also, symbols equated from numbers and constant expressions are allowed in
230place of a special register, except when either of the options
231@code{--no-predefined-syms} and @code{--fixed-special-register-names} are
232specified. Then only the special register names above are allowed for the
233instructions having a special register operand; @code{GET} and @code{PUT}.
234
235@node MMIX-Pseudos
236@subsection Assembler Directives
237@cindex assembler directives, MMIX
238@cindex pseudo-ops, MMIX
239@cindex MMIX assembler directives
240@cindex MMIX pseudo-ops
241
242@table @code
243@item LOC
244@cindex assembler directive LOC, MMIX
245@cindex pseudo-op LOC, MMIX
246@cindex MMIX assembler directive LOC
247@cindex MMIX pseudo-op LOC
248
13f7ad58 249@anchor{MMIX-loc}
3c3bdf30
NC
250The @code{LOC} directive sets the current location to the value of the
251operand field, which may include changing sections. If the operand is a
252constant, the section is set to either @code{.data} if the value is
253@code{0x2000000000000000} or larger, else it is set to @code{.text}.
254Within a section, the current location may only be changed to
255monotonically higher addresses. A LOC expression must be a previously
256defined symbol or a ``pure'' constant.
257
258An example, which sets the label @var{prev} to the current location, and
259updates the current location to eight bytes forward:
260@smallexample
261prev LOC @@+8
262@end smallexample
263
264When a LOC has a constant as its operand, a symbol
265@code{__.MMIX.start..text} or @code{__.MMIX.start..data} is defined
266depending on the address as mentioned above. Each such symbol is
267interpreted as special by the linker, locating the section at that
268address. Note that if multiple files are linked, the first object file
269with that section will be mapped to that address (not necessarily the file
270with the LOC definition).
271
272@item LOCAL
273@cindex assembler directive LOCAL, MMIX
274@cindex pseudo-op LOCAL, MMIX
275@cindex MMIX assembler directive LOCAL
276@cindex MMIX pseudo-op LOCAL
277
13f7ad58 278@anchor{MMIX-local}
3c3bdf30
NC
279Example:
280@smallexample
281 LOCAL external_symbol
282 LOCAL 42
283 .local asymbol
284@end smallexample
285
286This directive-operation generates a link-time assertion that the operand
287does not correspond to a global register. The operand is an expression
288that at link-time resolves to a register symbol or a number. A number is
289treated as the register having that number. There is one restriction on
290the use of this directive: the pseudo-directive must be placed in a
291section with contents, code or data.
292
293@item IS
294@cindex assembler directive IS, MMIX
295@cindex pseudo-op IS, MMIX
296@cindex MMIX assembler directive IS
297@cindex MMIX pseudo-op IS
298
13f7ad58 299@anchor{MMIX-is}
3c3bdf30
NC
300The @code{IS} directive:
301@smallexample
302asymbol IS an_expression
303@end smallexample
304sets the symbol @samp{asymbol} to @samp{an_expression}. A symbol may not
305be set more than once using this directive. Local labels may be set using
306this directive, for example:
307@smallexample
3085H IS @@+4
309@end smallexample
310
311@item GREG
312@cindex assembler directive GREG, MMIX
313@cindex pseudo-op GREG, MMIX
314@cindex MMIX assembler directive GREG
315@cindex MMIX pseudo-op GREG
316
13f7ad58 317@anchor{MMIX-greg}
3c3bdf30
NC
318This directive reserves a global register, gives it an initial value and
319optionally gives it a symbolic name. Some examples:
320
321@smallexample
322areg GREG
323breg GREG data_value
324 GREG data_buffer
325 .greg creg, another_data_value
326@end smallexample
327
328The symbolic register name can be used in place of a (non-special)
329register. If a value isn't provided, it defaults to zero. Unless the
330option @samp{--no-merge-gregs} is specified, non-zero registers allocated
331with this directive may be eliminated by @code{@value{AS}}; another
332register with the same value used in its place.
333Any of the instructions
334@samp{CSWAP},
335@samp{GO},
336@samp{LDA},
337@samp{LDBU},
338@samp{LDB},
339@samp{LDHT},
340@samp{LDOU},
341@samp{LDO},
342@samp{LDSF},
343@samp{LDTU},
344@samp{LDT},
345@samp{LDUNC},
346@samp{LDVTS},
347@samp{LDWU},
348@samp{LDW},
349@samp{PREGO},
350@samp{PRELD},
351@samp{PREST},
352@samp{PUSHGO},
353@samp{STBU},
354@samp{STB},
355@samp{STCO},
356@samp{STHT},
357@samp{STOU},
358@samp{STSF},
359@samp{STTU},
360@samp{STT},
361@samp{STUNC},
362@samp{SYNCD},
363@samp{SYNCID},
13f7ad58 364can have a value nearby @anchor{GREG-base}an initial value in place of its
3c3bdf30
NC
365second and third operands. Here, ``nearby'' is defined as within the
366range 0@dots{}255 from the initial value of such an allocated register.
367
368@smallexample
369buffer1 BYTE 0,0,0,0,0
370buffer2 BYTE 0,0,0,0,0
371 @dots{}
372 GREG buffer1
373 LDOU $42,buffer2
374@end smallexample
375In the example above, the @samp{Y} field of the @code{LDOUI} instruction
376(LDOU with a constant Z) will be replaced with the global register
377allocated for @samp{buffer1}, and the @samp{Z} field will have the value
3785, the offset from @samp{buffer1} to @samp{buffer2}. The result is
379equivalent to this code:
380@smallexample
381buffer1 BYTE 0,0,0,0,0
382buffer2 BYTE 0,0,0,0,0
383 @dots{}
384tmpreg GREG buffer1
385 LDOU $42,tmpreg,(buffer2-buffer1)
386@end smallexample
387
388Global registers allocated with this directive are allocated in order
389higher-to-lower within a file. Other than that, the exact order of
390register allocation and elimination is undefined. For example, the order
391is undefined when more than one file with such directives are linked
973eb340
HPN
392together. With the options @samp{-x} and @samp{--linker-allocated-gregs},
393@samp{GREG} directives for two-operand cases like the one mentioned above
394can be omitted. Sufficient global registers will then be allocated by the
395linker.
3c3bdf30
NC
396
397@item BYTE
398@cindex assembler directive BYTE, MMIX
399@cindex pseudo-op BYTE, MMIX
400@cindex MMIX assembler directive BYTE
401@cindex MMIX pseudo-op BYTE
402
13f7ad58 403@anchor{MMIX-byte}
3c3bdf30
NC
404The @samp{BYTE} directive takes a series of operands separated by a comma.
405If an operand is a string (@pxref{Strings}), each character of that string
406is emitted as a byte. Other operands must be constant expressions without
407forward references, in the range 0@dots{}255. If you need operands having
408expressions with forward references, use @samp{.byte} (@pxref{Byte}). An
409operand can be omitted, defaulting to a zero value.
410
411@item WYDE
412@itemx TETRA
413@itemx OCTA
414@cindex assembler directive WYDE, MMIX
415@cindex pseudo-op WYDE, MMIX
416@cindex MMIX assembler directive WYDE
417@cindex MMIX pseudo-op WYDE
418@cindex assembler directive TETRA, MMIX
419@cindex pseudo-op TETRA, MMIX
420@cindex MMIX assembler directive TETRA
421@cindex MMIX pseudo-op TETRA
422@cindex assembler directive OCTA, MMIX
423@cindex pseudo-op OCTA, MMIX
424@cindex MMIX assembler directive OCTA
425@cindex MMIX pseudo-op OCTA
426
13f7ad58 427@anchor{MMIX-constants}
3c3bdf30
NC
428The directives @samp{WYDE}, @samp{TETRA} and @samp{OCTA} emit constants of
429two, four and eight bytes size respectively. Before anything else happens
430for the directive, the current location is aligned to the respective
431constant-size bondary. If a label is defined at the beginning of the
432line, its value will be that after the alignment. A single operand can be
433omitted, defaulting to a zero value emitted for the directive. Operands
434can be expressed as strings (@pxref{Strings}), in which case each
435character in the string is emitted as a separate constant of the size
436indicated by the directive.
437
438@item PREFIX
439@cindex assembler directive PREFIX, MMIX
440@cindex pseudo-op PREFIX, MMIX
441@cindex MMIX assembler directive PREFIX
442@cindex MMIX pseudo-op PREFIX
443
13f7ad58 444@anchor{MMIX-prefix}
3c3bdf30
NC
445The @samp{PREFIX} directive sets a symbol name prefix to be prepended to
446all symbols (except local symbols, @pxref{MMIX-Symbols}), that are not
447prefixed with @samp{:}, until the next @samp{PREFIX} directive. Such
448prefixes accumulate. For example,
449@smallexample
450 PREFIX a
451 PREFIX b
452c IS 0
453@end smallexample
454defines a symbol @samp{abc} with the value 0.
455
456@item BSPEC
457@itemx ESPEC
458@cindex assembler directive BSPEC, MMIX
459@cindex pseudo-op BSPEC, MMIX
460@cindex MMIX assembler directive BSPEC
461@cindex MMIX pseudo-op BSPEC
462@cindex assembler directive ESPEC, MMIX
463@cindex pseudo-op ESPEC, MMIX
464@cindex MMIX assembler directive ESPEC
465@cindex MMIX pseudo-op ESPEC
466
13f7ad58 467@anchor{MMIX-spec}
3c3bdf30
NC
468A pair of @samp{BSPEC} and @samp{ESPEC} directives delimit a section of
469special contents (without specified semantics). Example:
470@smallexample
471 BSPEC 42
472 TETRA 1,2,3
473 ESPEC
474@end smallexample
475The single operand to @samp{BSPEC} must be number in the range
4760@dots{}255. The @samp{BSPEC} number 80 is used by the GNU binutils
477implementation.
478@end table
479
480@node MMIX-mmixal
481@section Differences to @code{mmixal}
482@cindex mmixal differences
483@cindex differences, mmixal
484
485The binutils @code{@value{AS}} and @code{@value{LD}} combination has a few
13f7ad58 486differences in function compared to @code{mmixal} (@pxref{mmixsite}).
3c3bdf30
NC
487
488The replacement of a symbol with a GREG-allocated register
13f7ad58 489(@pxref{GREG-base}) is not handled the exactly same way in
3c3bdf30
NC
490@code{@value{AS}} as in @code{mmixal}. This is apparent in the
491@code{mmixal} example file @code{inout.mms}, where different registers
492with different offsets, eventually yielding the same address, are used in
493the first instruction. This type of difference should however not affect
494the function of any program unless it has specific assumptions about the
495allocated register number.
496
497Line numbers (in the @samp{mmo} object format) are currently not
498supported.
499
500Expression operator precedence is not that of mmixal: operator precedence
501is that of the C programming language. It's recommended to use
502parentheses to explicitly specify wanted operator precedence whenever more
503than one type of operators are used.
504
505The serialize unary operator @code{&}, the fractional division operator
506@samp{//}, the logical not operator @code{!} and the modulus operator
507@samp{%} are not available.
508
509Symbols are not global by default, unless the option
510@samp{--globalize-symbols} is passed. Use the @samp{.global} directive to
511globalize symbols (@pxref{Global}).
512
513Operand syntax is a bit stricter with @code{@value{AS}} than
514@code{mmixal}. For example, you can't say @code{addu 1,2,3}, instead you
515must write @code{addu $1,$2,3}.
516
517You can't LOC to a lower address than those already visited
518(i.e. ``backwards'').
519
520A LOC directive must come before any emitted code.
521
522Predefined symbols are visible as file-local symbols after use. (In the
523ELF file, that is---the linked mmo file has no notion of a file-local
524symbol.)
525
526Some mapping of constant expressions to sections in LOC expressions is
527attempted, but that functionality is easily confused and should be avoided
528unless compatibility with @code{mmixal} is required. A LOC expression to
529@samp{0x2000000000000000} or higher, maps to the @samp{.data} section and
13f7ad58 530lower addresses map to the @samp{.text} section (@pxref{MMIX-loc}).
3c3bdf30
NC
531
532The code and data areas are each contiguous. Sparse programs with
533far-away LOC directives will take up the same amount of space as a
534contiguous program with zeros filled in the gaps between the LOC
535directives. If you need sparse programs, you might try and get the wanted
536effect with a linker script and splitting up the code parts into sections
537(@pxref{Section}). Assembly code for this, to be compatible with
538@code{mmixal}, would look something like:
539@smallexample
540 .if 0
541 LOC away_expression
542 .else
543 .section away,"ax"
544 .fi
545@end smallexample
546@code{@value{AS}} will not execute the LOC directive and @code{mmixal}
547ignores the lines with @code{.}. This construct can be used generally to
548help compatibility.
549
550Symbols can't be defined twice--not even to the same value.
551
552Instruction mnemonics are recognized case-insensitive, though the
553@samp{IS} and @samp{GREG} pseudo-operations must be specified in
554upper-case characters.
555
556There's no unicode support.
557
973eb340
HPN
558The following is a list of programs in @samp{mmix.tar.gz}, available at
559@url{http://www-cs-faculty.stanford.edu/~knuth/mmix-news.html}, last
560checked with the version dated 2001-08-25 (md5sum
561c393470cfc86fac040487d22d2bf0172) that assemble with @code{mmixal} but do
562not assemble with @code{@value{AS}}:
3c3bdf30
NC
563
564@table @code
565@item silly.mms
566LOC to a previous address.
567@item sim.mms
568Redefines symbol @samp{Done}.
569@item test.mms
570Uses the serial operator @samp{&}.
571@end table
This page took 0.07138 seconds and 4 git commands to generate.