* stack.c (return_command): Pop dummy frame if we just returned from
[deliverable/binutils-gdb.git] / gas / doc / gasp.texi
CommitLineData
252b5132
RH
1\input texinfo @c -*- Texinfo -*-
2@setfilename gasp.info
3@c
4@c This file documents the assembly preprocessor "GASP"
5@c
6@c Copyright (c) 1994 Free Software Foundation, Inc.
7@c
8@c This text may be freely distributed under the terms of the GNU
9@c General Public License.
10
11@ifinfo
12@format
13START-INFO-DIR-ENTRY
14* gasp: (gasp). The GNU Assembler Preprocessor
15END-INFO-DIR-ENTRY
16@end format
17@end ifinfo
18
19@syncodeindex ky cp
20@syncodeindex fn cp
21
22@finalout
23@setchapternewpage odd
24@settitle GASP
25@titlepage
26@c FIXME boring title
27@title GASP, an assembly preprocessor
28@subtitle for GASP version 1
29@sp 1
30@subtitle March 1994
31@author Roland Pesch
32@page
33
34@tex
35{\parskip=0pt \hfill Cygnus Support\par
36}
37@end tex
38
39@vskip 0pt plus 1filll
40Copyright @copyright{} 1994, 1995 Free Software Foundation, Inc.
41
42Permission is granted to make and distribute verbatim copies of
43this manual provided the copyright notice and this permission notice
44are preserved on all copies.
45
46Permission is granted to copy and distribute modified versions of this
47manual under the conditions for verbatim copying, provided also that
48the entire resulting derived work is distributed under the terms of a
49permission notice identical to this one.
50
51Permission is granted to copy and distribute translations of this manual
52into another language, under the above conditions for modified versions.
53@end titlepage
54
55@ifinfo
56Copyright @copyright{} 1994, 1995 Free Software Foundation, Inc.
57
58Permission is granted to make and distribute verbatim copies of
59this manual provided the copyright notice and this permission notice
60are preserved on all copies.
61
62@ignore
63Permission is granted to process this file through TeX and print the
64results, provided the printed document carries a copying permission
65notice identical to this one except for the removal of this paragraph
66(this paragraph not being relevant to the printed manual).
67@end ignore
68
69Permission is granted to copy and distribute modified versions of this
70manual under the conditions for verbatim copying, provided also that
71the entire resulting derived work is distributed under the terms of a
72permission notice identical to this one.
73
74Permission is granted to copy and distribute translations of this manual
75into another language, under the above conditions for modified versions.
76
77@node Top
78@top GASP
79
80GASP is a preprocessor for assembly programs.
81
82This file describes version 1 of GASP.
83
84Steve Chamberlain wrote GASP; Roland Pesch wrote this manual.
85
86@menu
87* Overview:: What is GASP?
88* Invoking GASP:: Command line options.
89* Commands:: Preprocessor commands.
90* Index:: Index.
91@end menu
92@end ifinfo
93
94@node Overview
95@chapter What is GASP?
96
97The primary purpose of the @sc{gnu} assembler is to assemble the output of
98other programs---notably compilers. When you have to hand-code
99specialized routines in assembly, that means the @sc{gnu} assembler is
100an unfriendly processor: it has no directives for macros, conditionals,
101or many other conveniences that you might expect.
102
103In some cases you can simply use the C preprocessor, or a generalized
104preprocessor like @sc{m4}; but this can be awkward, since none of these
105things are designed with assembly in mind.
106
107@sc{gasp} fills this need. It is expressly designed to provide the
108facilities you need with hand-coded assembly code. Implementing it as a
109preprocessor, rather than part of the assembler, allows the maximum
110flexibility: you can use it with hand-coded assembly, without paying a
111penalty of added complexity in the assembler you use for compiler
112output.
113
114Here is a small example to give the flavor of @sc{gasp}. This input to
115@sc{gasp}
116
117@cartouche
118@example
119 .MACRO saveregs from=8 to=14
120count .ASSIGNA \from
121 ! save r\from..r\to
122 .AWHILE \&count LE \to
123 mov r\&count,@@-sp
124count .ASSIGNA \&count + 1
125 .AENDW
126 .ENDM
127
128 saveregs from=12
129
130bar: mov #H'dead+10,r0
131foo .SDATAC "hello"<10>
132 .END
133@end example
134@end cartouche
135
136@noindent
137generates this assembly program:
138
139@cartouche
140@example
141 ! save r12..r14
142 mov r12,@@-sp
143 mov r13,@@-sp
144 mov r14,@@-sp
145
146bar: mov #57005+10,r0
147foo: .byte 6,104,101,108,108,111,10
148@end example
149@end cartouche
150
151@node Invoking GASP
152@chapter Command Line Options
153
154@c FIXME! Or is there a simpler way, calling from GAS option?
155The simplest way to use @sc{gasp} is to run it as a filter and assemble
156its output. In Unix and its ilk, you can do this, for example:
157
158@c FIXME! GASP filename suffix convention?
159@example
160$ gasp prog.asm | as -o prog.o
161@end example
162
163Naturally, there are also a few command-line options to allow you to
164request variations on this basic theme. Here is the full set of
165possibilities for the @sc{gasp} command line.
166
167@example
168gasp [ -a | --alternate ]
169 [ -c @var{char} | --commentchar @var{char} ]
170 [ -d | --debug ] [ -h | --help ] [ -M | --mri ]
171 [ -o @var{outfile} | --output @var{outfile} ]
172 [ -p | --print ] [ -s | --copysource ]
173 [ -u | --unreasonable ] [ -v | --version ]
174 @var{infile} @dots{}
175@end example
176
177@ftable @code
178@item @var{infile} @dots{}
179@c FIXME! Why not stdin as default infile?
180The input file names. You must specify at least one input file; if you
181specify more, @sc{gasp} preprocesses them all, concatenating the output
182in the order you list the @var{infile} arguments.
183
184Mark the end of each input file with the preprocessor command
185@code{.END}. @xref{Other Commands,, Miscellaneous commands}.
186
187@item -a
188@itemx --alternate
189Use alternative macro syntax. @xref{Alternate,, Alternate macro
190syntax}, for a discussion of how this syntax differs from the default
191@sc{gasp} syntax.
192
193@cindex comment character, changing
194@cindex semicolon, as comment
195@cindex exclamation mark, as comment
196@cindex shriek, as comment
197@cindex bang, as comment
198@cindex @code{!} default comment char
199@cindex @code{;} as comment char
200@item -c '@var{char}'
201@itemx --commentchar '@var{char}'
202Use @var{char} as the comment character. The default comment character
203is @samp{!}. For example, to use a semicolon as the comment character,
204specify @w{@samp{-c ';'}} on the @sc{gasp} command line. Since
205assembler command characters often have special significance to command
206shells, it is a good idea to quote or escape @var{char} when you specify
207a comment character.
208
209For the sake of simplicity, all examples in this manual use the default
210comment character @samp{!}.
211
212@item -d
213@itemx --debug
214Show debugging statistics. In this version of @sc{gasp}, this option
215produces statistics about the string buffers that @sc{gasp} allocates
216internally. For each defined buffersize @var{s}, @sc{gasp} shows the
217number of strings @var{n} that it allocated, with a line like this:
218
219@example
220strings size @var{s} : @var{n}
221@end example
222
223@noindent
224@sc{gasp} displays these statistics on the standard error stream, when
225done preprocessing.
226
227@item -h
228@itemx --help
229Display a summary of the @sc{gasp} command line options.
230
231@item -M
232@itemx --mri
233Use MRI compatibility mode. Using this option causes @sc{gasp} to
234accept the syntax and pseudo-ops used by the Microtec Research
235@code{ASM68K} assembler.
236
237@item -o @var{outfile}
238@itemx --output @var{outfile}
239Write the output in a file called @var{outfile}. If you do not use the
240@samp{-o} option, @sc{gasp} writes its output on the standard output
241stream.
242
243@item -p
244@itemx --print
245Print line numbers. @sc{gasp} obeys this option @emph{only} if you also
246specify @samp{-s} to copy source lines to its output. With @samp{-s
247-p}, @sc{gasp} displays the line number of each source line copied
248(immediately after the comment character at the beginning of the line).
249
250@item -s
251@itemx --copysource
252Copy the source lines to the output file. Use this option
253to see the effect of each preprocessor line on the @sc{gasp} output.
254@sc{gasp} places a comment character (@samp{!} by default) at
255the beginning of each source line it copies, so that you can use this
256option and still assemble the result.
257
258@item -u
259@itemx --unreasonable
260Bypass ``unreasonable expansion'' limit. Since you can define @sc{gasp}
261macros inside other macro definitions, the preprocessor normally
262includes a sanity check. If your program requires more than 1,000
263nested expansions, @sc{gasp} normally exits with an error message. Use
264this option to turn off this check, allowing unlimited nested
265expansions.
266
267@item -v
268@itemx --version
269Display the @sc{gasp} version number.
270@end ftable
271
272@node Commands
273@chapter Preprocessor Commands
274
275@sc{gasp} commands have a straightforward syntax that fits in well with
276assembly conventions. In general, a command extends for a line, and may
277have up to three fields: an optional label, the command itself, and
278optional arguments to the command. You can write commands in upper or
279lower case, though this manual shows them in upper case. @xref{Syntax
280Details,, Details of the GASP syntax}, for more information.
281
282@menu
283* Conditionals::
284* Loops::
285* Variables::
286* Macros::
287* Data::
288* Listings::
289* Other Commands::
290* Syntax Details::
291* Alternate::
292@end menu
293
294@node Conditionals
295@section Conditional assembly
296
297The conditional-assembly directives allow you to include or exclude
298portions of an assembly depending on how a pair of expressions, or a
299pair of strings, compare.
300
301The overall structure of conditionals is familiar from many other
302contexts. @code{.AIF} marks the start of a conditional, and precedes
303assembly for the case when the condition is true. An optional
304@code{.AELSE} precedes assembly for the converse case, and an
305@code{.AENDI} marks the end of the condition.
306
307@c FIXME! Why doesn't -u turn off this check?
308You may nest conditionals up to a depth of 100; @sc{gasp} rejects
309nesting beyond that, because it may indicate a bug in your macro
310structure.
311
312@c FIXME! Why isn't there something like cpp's -D option? Conditionals
313@c would be much more useful if there were.
314Conditionals are primarily useful inside macro definitions, where you
315often need different effects depending on argument values.
316@xref{Macros,, Defining your own directives}, for details about defining
317macros.
318
319@ftable @code
320@item .AIF @var{expra} @var{cmp} @var{exprb}
321@itemx .AIF "@var{stra}" @var{cmp} "@var{strb}"
322
323The governing condition goes on the same line as the @code{.AIF}
324preprocessor command. You may compare either two strings, or two
325expressions.
326
327When you compare strings, only two conditional @var{cmp} comparison
328operators are available: @samp{EQ} (true if @var{stra} and @var{strb}
329are identical), and @samp{NE} (the opposite).
330
331When you compare two expressions, @emph{both expressions must be
332absolute} (@pxref{Expressions,, Arithmetic expressions in GASP}). You
333can use these @var{cmp} comparison operators with expressions:
334
335@ftable @code
336@item EQ
337Are @var{expra} and @var{exprb} equal? (For strings, are @var{stra} and
338@var{strb} identical?)
339
340@item NE
341Are @var{expra} and @var{exprb} different? (For strings, are @var{stra}
342and @var{strb} different?
343
344@item LT
345Is @var{expra} less than @var{exprb}? (Not allowed for strings.)
346
347@item LE
348Is @var{expra} less than or equal to @var{exprb}? (Not allowed for strings.)
349
350@item GT
351Is @var{expra} greater than @var{exprb}? (Not allowed for strings.)
352
353@item GE
354Is @var{expra} greater than or equal to @var{exprb}? (Not allowed for
355strings.)
356@end ftable
357
358@item .AELSE
359Marks the start of assembly code to be included if the condition fails.
360Optional, and only allowed within a conditional (between @code{.AIF} and
361@code{.AENDI}).
362
363@item .AENDI
364Marks the end of a conditional assembly.
365@end ftable
366
367@node Loops
368@section Repetitive sections of assembly
369
370Two preprocessor directives allow you to repeatedly issue copies of the
371same block of assembly code.
372
373@ftable @code
374@item .AREPEAT @var{aexp}
375@itemx .AENDR
376If you simply need to repeat the same block of assembly over and over a
377fixed number of times, sandwich one instance of the repeated block
378between @code{.AREPEAT} and @code{.AENDR}. Specify the number of
379copies as @var{aexp} (which must be an absolute expression). For
380example, this repeats two assembly statements three times in succession:
381
382@cartouche
383@example
384 .AREPEAT 3
385 rotcl r2
386 div1 r0,r1
387 .AENDR
388@end example
389@end cartouche
390
391@item .AWHILE @var{expra} @var{cmp} @var{exprb}
392@itemx .AENDW
393@itemx .AWHILE @var{stra} @var{cmp} @var{strb}
394@itemx .AENDW
395To repeat a block of assembly depending on a conditional test, rather
396than repeating it for a specific number of times, use @code{.AWHILE}.
397@code{.AENDW} marks the end of the repeated block. The conditional
398comparison works exactly the same way as for @code{.AIF}, with the same
399comparison operators (@pxref{Conditionals,, Conditional assembly}).
400
401Since the terms of the comparison must be absolute expression,
402@code{.AWHILE} is primarily useful within macros. @xref{Macros,,
403Defining your own directives}.
404@end ftable
405
406@cindex loops, breaking out of
407@cindex breaking out of loops
408You can use the @code{.EXITM} preprocessor directive to break out of
409loops early (as well as to break out of macros). @xref{Macros,,
410Defining your own directives}.
411
412@node Variables
413@section Preprocessor variables
414
415You can use variables in @sc{gasp} to represent strings, registers, or
416the results of expressions.
417
418You must distinguish two kinds of variables:
419@enumerate
420@item
421Variables defined with @code{.EQU} or @code{.ASSIGN}. To evaluate this
422kind of variable in your assembly output, simply mention its name. For
423example, these two lines define and use a variable @samp{eg}:
424
425@cartouche
426@example
427eg .EQU FLIP-64
428 @dots{}
429 mov.l eg,r0
430@end example
431@end cartouche
432
433@emph{Do not use} this kind of variable in conditional expressions or
434while loops; @sc{gasp} only evaluates these variables when writing
435assembly output.
436
437@item
438Variables for use during preprocessing. You can define these
439with @code{.ASSIGNC} or @code{.ASSIGNA}. To evaluate this
440kind of variable, write @samp{\&} before the variable name; for example,
441
442@cartouche
443@example
444opcit .ASSIGNA 47
445 @dots{}
446 .AWHILE \&opcit GT 0
447 @dots{}
448 .AENDW
449@end example
450@end cartouche
451
452@sc{gasp} treats macro arguments almost the same way, but to evaluate
453them you use the prefix @samp{\} rather than @samp{\&}.
454@xref{Macros,, Defining your own directives}.
455@end enumerate
456
457@ftable @code
458@item @var{pvar} .EQU @var{expr}
459@c FIXME! Anything to beware of re GAS directive of same name?
460Assign preprocessor variable @var{pvar} the value of the expression
461@var{expr}. There are no restrictions on redefinition; use @samp{.EQU}
462with the same @var{pvar} as often as you find it convenient.
463
464@item @var{pvar} .ASSIGN @var{expr}
465Almost the same as @code{.EQU}, save that you may not redefine
466@var{pvar} using @code{.ASSIGN} once it has a value.
467@c FIXME!! Supposed to work this way, apparently, but on 9feb94 works
468@c just like .EQU
469
470@item @var{pvar} .ASSIGNA @var{aexpr}
471Define a variable with a numeric value, for use during preprocessing.
472@var{aexpr} must be an absolute expression. You can redefine variables
473with @code{.ASSIGNA} at any time.
474
475@item @var{pvar} .ASSIGNC "@var{str}"
476Define a variable with a string value, for use during preprocessing.
477You can redefine variables with @code{.ASSIGNC} at any time.
478
479@item @var{pvar} .REG (@var{register})
480Use @code{.REG} to define a variable that represents a register. In
481particular, @var{register} is @emph{not evaluated} as an expression.
482You may use @code{.REG} at will to redefine register variables.
483@end ftable
484
485All these directives accept the variable name in the ``label'' position,
486that is at the left margin. You may specify a colon after the variable
487name if you wish; the first example above could have started @samp{eg:}
488with the same effect.
489
490@c pagebreak makes for better aesthetics---ensures macro and expansion together
491@page
492@node Macros
493@section Defining your own directives
494
495The commands @code{.MACRO} and @code{.ENDM} allow you to define macros
496that generate assembly output. You can use these macros with a syntax
497similar to built-in @sc{gasp} or assembler directives. For example,
498this definition specifies a macro @code{SUM} that adds together a range of
499consecutive registers:
500
501@cartouche
502@example
503 .MACRO SUM FROM=0, TO=9
504 ! \FROM \TO
505 mov r\FROM,r10
506COUNT .ASSIGNA \FROM+1
507 .AWHILE \&COUNT LE \TO
508 add r\&COUNT,r10
509COUNT .ASSIGNA \&COUNT+1
510 .AENDW
511 .ENDM
512@end example
513@end cartouche
514
515@noindent
516With that definition, @samp{SUM 0,5} generates this assembly output:
517
518@cartouche
519@example
520 ! 0 5
521 mov r0,r10
522 add r1,r10
523 add r2,r10
524 add r3,r10
525 add r4,r10
526 add r5,r10
527@end example
528@end cartouche
529
530@ftable @code
531@item .MACRO @var{macname}
532@itemx .MACRO @var{macname} @var{macargs} @dots{}
533Begin the definition of a macro called @var{macname}. If your macro
534definition requires arguments, specify their names after the macro name,
535separated by commas or spaces. You can supply a default value for any
536macro argument by following the name with @samp{=@var{deflt}}. For
537example, these are all valid @code{.MACRO} statements:
538
539@table @code
540@item .MACRO COMM
541Begin the definition of a macro called @code{COMM}, which takes no
542arguments.
543
544@item .MACRO PLUS1 P, P1
545@itemx .MACRO PLUS1 P P1
546Either statement begins the definition of a macro called @code{PLUS1},
547which takes two arguments; within the macro definition, write
548@samp{\P} or @samp{\P1} to evaluate the arguments.
549
550@item .MACRO RESERVE_STR P1=0 P2
551Begin the definition of a macro called @code{RESERVE_STR}, with two
552arguments. The first argument has a default value, but not the second.
553After the definition is complete, you can call the macro either as
554@samp{RESERVE_STR @var{a},@var{b}} (with @samp{\P1} evaluating to
555@var{a} and @samp{\P2} evaluating to @var{b}), or as @samp{RESERVE_STR
556,@var{b}} (with @samp{\P1} evaluating as the default, in this case
557@samp{0}, and @samp{\P2} evaluating to @var{b}).
558@end table
559
560When you call a macro, you can specify the argument values either by
561position, or by keyword. For example, @samp{SUM 9,17} is equivalent to
562@samp{SUM TO=17, FROM=9}. Macro arguments are preprocessor variables
563similar to the variables you define with @samp{.ASSIGNA} or
564@samp{.ASSIGNC}; in particular, you can use them in conditionals or for
565loop control. (The only difference is the prefix you write to evaluate
566the variable: for a macro argument, write @samp{\@var{argname}}, but for
567a preprocessor variable, write @samp{\&@var{varname}}.)
568
569@item @var{name} .MACRO
570@itemx @var{name} .MACRO ( @var{macargs} @dots{} )
571@c FIXME check: I think no error _and_ no args recognized if I use form
572@c NAME .MACRO ARG ARG
573An alternative form of introducing a macro definition: specify the macro
574name in the label position, and the arguments (if any) between
575parentheses after the name. Defaulting rules and usage work the same
576way as for the other macro definition syntax.
577
578@item .ENDM
579Mark the end of a macro definition.
580
581@item .EXITM
582Exit early from the current macro definition, @code{.AREPEAT} loop, or
583@code{.AWHILE} loop.
584
585@cindex number of macros executed
586@cindex macros, count executed
587@item \@@
588@sc{gasp} maintains a counter of how many macros it has
589executed in this pseudo-variable; you can copy that number to your
590output with @samp{\@@}, but @emph{only within a macro definition}.
591
592@item LOCAL @var{name} [ , @dots{} ]
593@emph{Warning: @code{LOCAL} is only available if you select ``alternate
594macro syntax'' with @samp{-a} or @samp{--alternate}.} @xref{Alternate,,
595Alternate macro syntax}.
596
597Generate a string replacement for each of the @var{name} arguments, and
598replace any instances of @var{name} in each macro expansion. The
599replacement string is unique in the assembly, and different for each
600separate macro expansion. @code{LOCAL} allows you to write macros that
601define symbols, without fear of conflict between separate macro expansions.
602@end ftable
603
604@node Data
605@section Data output
606
607In assembly code, you often need to specify working areas of memory;
608depending on the application, you may want to initialize such memory or
609not. @sc{gasp} provides preprocessor directives to help you avoid
610repetitive coding for both purposes.
611
612You can use labels as usual to mark the data areas.
613
614@menu
615* Initialized::
616* Uninitialized::
617@end menu
618
619@node Initialized
620@subsection Initialized data
621
622These are the @sc{gasp} directives for initialized data, and the standard
623@sc{gnu} assembler directives they expand to:
624
625@ftable @code
626@item .DATA @var{expr}, @var{expr}, @dots{}
627@itemx .DATA.B @var{expr}, @var{expr}, @dots{}
628@itemx .DATA.W @var{expr}, @var{expr}, @dots{}
629@itemx .DATA.L @var{expr}, @var{expr}, @dots{}
630Evaluate arithmetic expressions @var{expr}, and emit the corresponding
631@code{as} directive (labelled with @var{lab}). The unqualified
632@code{.DATA} emits @samp{.long}; @code{.DATA.B} emits @samp{.byte};
633@code{.DATA.W} emits @samp{.short}; and @code{.DATA.L} emits
634@samp{.long}.
635
636For example, @samp{foo .DATA 1,2,3} emits @samp{foo: .long 1,2,3}.
637
638@item .DATAB @var{repeat}, @var{expr}
639@itemx .DATAB.B @var{repeat}, @var{expr}
640@itemx .DATAB.W @var{repeat}, @var{expr}
641@itemx .DATAB.L @var{repeat}, @var{expr}
642@c FIXME! Looks like gasp accepts and ignores args after 2nd.
643Make @code{as} emit @var{repeat} copies of the value of the expression
644@var{expr} (using the @code{as} directive @code{.fill}).
645@samp{.DATAB.B} repeats one-byte values; @samp{.DATAB.W} repeats
646two-byte values; and @samp{.DATAB.L} repeats four-byte values.
647@samp{.DATAB} without a suffix repeats four-byte values, just like
648@samp{.DATAB.L}.
649
650@c FIXME! Allowing zero might be useful for edge conditions in macros.
651@var{repeat} must be an absolute expression with a positive value.
652
653@item .SDATA "@var{str}" @dots{}
654String data. Emits a concatenation of bytes, precisely as you specify
655them (in particular, @emph{nothing is added to mark the end} of the
656string). @xref{Constants,, String and numeric constants}, for details
657about how to write strings. @code{.SDATA} concatenates multiple
658arguments, making it easy to switch between string representations. You
659can use commas to separate the individual arguments for clarity, if you
660choose.
661
662@item .SDATAB @var{repeat}, "@var{str}" @dots{}
663Repeated string data. The first argument specifies how many copies of
664the string to emit; the remaining arguments specify the string, in the
665same way as the arguments to @code{.SDATA}.
666
667@item .SDATAZ "@var{str}" @dots{}
668Zero-terminated string data. Just like @code{.SDATA}, except that
669@code{.SDATAZ} writes a zero byte at the end of the string.
670
671@item .SDATAC "@var{str}" @dots{}
672Count-prefixed string data. Just like @code{.SDATA}, except that
673@sc{gasp} precedes the string with a leading one-byte count. For
674example, @samp{.SDATAC "HI"} generates @samp{.byte 2,72,73}. Since the
675count field is only one byte, you can only use @code{.SDATAC} for
676strings less than 256 bytes in length.
677@end ftable
678
679@node Uninitialized
680@subsection Uninitialized data
681
682@c FIXME! .space different on some platforms, notably HPPA. Config?
683Use the @code{.RES}, @code{.SRES}, @code{.SRESC}, and @code{.SRESZ}
684directives to reserve memory and leave it uninitialized. @sc{gasp}
685resolves these directives to appropriate calls of the @sc{gnu}
686@code{as} @code{.space} directive.
687
688@ftable @code
689@item .RES @var{count}
690@itemx .RES.B @var{count}
691@itemx .RES.W @var{count}
692@itemx .RES.L @var{count}
693Reserve room for @var{count} uninitialized elements of data. The
694suffix specifies the size of each element: @code{.RES.B} reserves
695@var{count} bytes, @code{.RES.W} reserves @var{count} pairs of bytes,
696and @code{.RES.L} reserves @var{count} quartets. @code{.RES} without a
697suffix is equivalent to @code{.RES.L}.
698
699@item .SRES @var{count}
700@itemx .SRES.B @var{count}
701@itemx .SRES.W @var{count}
702@itemx .SRES.L @var{count}
703@c FIXME! This is boring. Shouldn't it at least have a different
704@c default size? (e.g. the "S" suggests "string", for which .B
705@c would be more appropriate)
706@code{.SRES} is a synonym for @samp{.RES}.
707
708@item .SRESC @var{count}
709@itemx .SRESC.B @var{count}
710@itemx .SRESC.W @var{count}
711@itemx .SRESC.L @var{count}
712Like @code{.SRES}, but reserves space for @code{@var{count}+1} elements.
713
714@item .SRESZ @var{count}
715@itemx .SRESZ.B @var{count}
716@itemx .SRESZ.W @var{count}
717@itemx .SRESZ.L @var{count}
718Like @code{.SRES}, but reserves space for @code{@var{count}+1} elements.
719@end ftable
720
721@node Listings
722@section Assembly listing control
723
724The @sc{gasp} listing-control directives correspond to
725related @sc{gnu} @code{as} directives.
726
727@ftable @code
728@item .PRINT LIST
729@itemx .PRINT NOLIST
730Print control. This directive emits the @sc{gnu} @code{as} directive
731@code{.list} or @code{.nolist}, according to its argument. @xref{List,,
732@code{.list}, as.info, Using as}, for details on how these directives
733interact.
734
735@item .FORM LIN=@var{ln}
736@itemx .FORM COL=@var{cols}
737@itemx .FORM LIN=@var{ln} COL=@var{cols}
738Specify the page size for assembly listings: @var{ln} represents the
739number of lines, and @var{cols} the number of columns. You may specify
740either page dimension independently, or both together. If you do not
741specify the number of lines, @sc{gasp} assumes 60 lines; if you do not
742specify the number of columns, @sc{gasp} assumes 132 columns.
743(Any values you may have specified in previous instances of @code{.FORM}
744do @emph{not} carry over as defaults.) Emits the @code{.psize}
745assembler directive.
746
747@item .HEADING @var{string}
748Specify @var{string} as the title of your assembly listings. Emits
749@samp{.title "@var{string}"}.
750
751@item .PAGE
752Force a new page in assembly listings. Emits @samp{.eject}.
753@end ftable
754
755@node Other Commands
756@section Miscellaneous commands
757
758@ftable @code
759@item .ALTERNATE
760Use the alternate macro syntax henceforth in the assembly.
761@xref{Alternate,, Alternate macro syntax}.
762
763@item .ORG
764@c FIXME! This is very strange, since _GAS_ understands .org
765This command is recognized, but not yet implemented. @sc{gasp}
766generates an error message for programs that use @code{.ORG}.
767
768@item .RADIX @var{s}
769@c FIXME no test cases in testsuite/gasp
770@sc{gasp} understands numbers in any of base two, eight, ten, or
771sixteen. You can encode the base explicitly in any numeric constant
772(@pxref{Constants,, String and numeric constants}). If you write
773numbers without an explicit indication of the base, the most recent
774@samp{.RADIX @var{s}} command determines how they are interpreted.
775@var{s} is a single letter, one of the following:
776
777@table @code
778@item .RADIX B
779Base 2.
780
781@item .RADIX Q
782Base 8.
783
784@item .RADIX D
785Base 10. This is the original default radix.
786
787@item .RADIX H
788Base 16.
789@end table
790
791You may specify the argument @var{s} in lower case (any of @samp{bqdh})
792with the same effects.
793
794@item .EXPORT @var{name}
795@itemx .GLOBAL @var{name}
796@c FIXME! No test cases in testsuite/gasp
797Declare @var{name} global (emits @samp{.global @var{name}}). The two
798directives are synonymous.
799
800@item .PROGRAM
801No effect: @sc{gasp} accepts this directive, and silently ignores it.
802
803@item .END
804Mark end of each preprocessor file. @sc{gasp} issues a warning if it
805reaches end of file without seeing this command.
806
807@item .INCLUDE "@var{str}"
808Preprocess the file named by @var{str}, as if its contents appeared
809where the @code{.INCLUDE} directive does. @sc{gasp} imposes a maximum
810limit of 30 stacked include files, as a sanity check.
811@c FIXME! Why is include depth not affected by -u?
812
813@item .ALIGN @var{size}
814@c FIXME! Why is this not utterly pointless?
815Evaluate the absolute expression @var{size}, and emit the assembly
816instruction @samp{.align @var{size}} using the result.
817@end ftable
818
819@node Syntax Details
820@section Details of the GASP syntax
821
822Since @sc{gasp} is meant to work with assembly code, its statement
823syntax has no surprises for the assembly programmer.
824
825@cindex whitespace
826@emph{Whitespace} (blanks or tabs; @emph{not} newline) is partially
827significant, in that it delimits up to three fields in a line. The
828amount of whitespace does not matter; you may line up fields in separate
829lines if you wish, but @sc{gasp} does not require that.
830
831@cindex fields of @sc{gasp} source line
832@cindex label field
833The @emph{first field}, an optional @dfn{label}, must be flush left in a
834line (with no leading whitespace) if it appears at all. You may use a
835colon after the label if you wish; @sc{gasp} neither requires the colon
836nor objects to it (but will not include it as part of the label name).
837
838@cindex directive field
839The @emph{second field}, which must appear after some whitespace,
840contains a @sc{gasp} or assembly @dfn{directive}.
841
842@cindex argument fields
843Any @emph{further fields} on a line are @dfn{arguments} to the
844directive; you can separate them from one another using either commas or
845whitespace.
846
847@menu
848* Markers::
849* Constants::
850* Symbols::
851* Expressions::
852* String Builtins::
853@end menu
854
855@node Markers
856@subsection Special syntactic markers
857
858@sc{gasp} recognizes a few special markers: to delimit comments, to
859continue a statement on the next line, to separate symbols from other
860characters, and to copy text to the output literally. (One other
861special marker, @samp{\@@}, works only within macro definitions;
862@pxref{Macros,, Defining your own directives}.)
863
864@cindex comments
865The trailing part of any @sc{gasp} source line may be a @dfn{comment}.
866A comment begins with the first unquoted comment character (@samp{!} by
867default), or an escaped or doubled comment character (@samp{\!} or
868@samp{!!} by default), and extends to the end of a line. You can
869specify what comment character to use with the @samp{-c} option
870(@pxref{Invoking GASP,, Command Line Options}). The two kinds of
871comment markers lead to slightly different treatment:
872
873@table @code
874@item !
875A single, un-escaped comment character generates an assembly comment in
876the @sc{gasp} output. @sc{gasp} evaluates any preprocessor variables
877(macro arguments, or variables defined with @code{.ASSIGNA} or
878@code{.ASSIGNC}) present. For example, a macro that begins like this
879
880@example
881 .MACRO SUM FROM=0, TO=9
882 ! \FROM \TO
883@end example
884
885@noindent
886issues as the first line of output a comment that records the
887values you used to call the macro.
888
889@c comments, preprocessor-only
890@c preprocessor-only comments
891@c GASP-only comments
892@item \!
893@itemx !!
894Either an escaped comment character, or a double comment character,
895marks a @sc{gasp} source comment. @sc{gasp} does not copy such comments
896to the assembly output.
897@end table
898
899@cindex continuation character
900@kindex +
901To @emph{continue a statement} on the next line of the file, begin the
902second line with the character @samp{+}.
903
904@cindex literal copy to output
905@cindex copying literally to output
906@cindex preprocessing, avoiding
907@cindex avoiding preprocessing
908Occasionally you may want to prevent @sc{gasp} from preprocessing some
909particular bit of text. To @emph{copy literally} from the @sc{gasp}
910source to its output, place @samp{\(} before the string to copy, and
911@samp{)} at the end. For example, write @samp{\(\!)} if you need the
912characters @samp{\!} in your assembly output.
913
914@cindex symbol separator
915@cindex text, separating from symbols
916@cindex symbols, separating from text
917To @emph{separate a preprocessor variable} from text to appear
918immediately after its value, write a single quote (@code{'}). For
919example, @samp{.SDATA "\P'1"} writes a string built by concatenating the
920value of @code{P} and the digit @samp{1}. (You cannot achieve this by
921writing just @samp{\P1}, since @samp{P1} is itself a valid name for a
922preprocessor variable.)
923
924@node Constants
925@subsection String and numeric constants
926
927There are two ways of writing @dfn{string constants} in @sc{gasp}: as
928literal text, and by numeric byte value. Specify a string literal
929between double quotes (@code{"@var{str}"}). Specify an individual
930numeric byte value as an absolute expression between angle brackets
931(@code{<@var{expr}>}. Directives that output strings allow you to
932specify any number of either kind of value, in whatever order is
933convenient, and concatenate the result. (Alternate syntax mode
934introduces a number of alternative string notations; @pxref{Alternate,,
935Alternate macro syntax}.)
936
937@c Details of numeric notation, e.g. base prefixes
938You can write @dfn{numeric constants} either in a specific base, or in
939whatever base is currently selected (either 10, or selected by the most
940recent @code{.RADIX}).
941
942To write a number in a @emph{specific base}, use the pattern
943@code{@var{s}'@var{ddd}}: a base specifier character @var{s}, followed
944by a single quote followed by digits @var{ddd}. The base specifier
945character matches those you can specify with @code{.RADIX}: @samp{B} for
946base 2, @samp{Q} for base 8, @samp{D} for base 10, and @samp{H} for base
94716. (You can write this character in lower case if you prefer.)
948
949@c FIXME! What are rules for recognizing number in deflt base? Whatever
950@c is left over after parsing other things??
951
952@node Symbols
953@subsection Symbols
954
955@sc{gasp} recognizes symbol names that start with any alphabetic character,
956@samp{_}, or @samp{$}, and continue with any of the same characters or
957with digits. Label names follow the same rules.
958
959@node Expressions
960@subsection Arithmetic expressions in GASP
961
962@cindex absolute expressions
963@cindex relocatable expressions
964There are two kinds of expressions, depending on their result:
965@dfn{absolute} expressions, which resolve to a constant (that is, they
966do not involve any values unknown to @sc{gasp}), and @dfn{relocatable}
967expressions, which must reduce to the form
968
969@example
970@var{addsym}+@var{const}-@var{subsym}
971@end example
972
973@noindent
974where @var{addsym} and @var{subsym} are assembly symbols of unknown
975value, and @var{const} is a constant.
976
977Arithmetic for @sc{gasp} expressions follows very similar rules to C.
978You can use parentheses to change precedence; otherwise, arithmetic
979primitives have decreasing precedence in the order of the following
980list.
981
982@enumerate
983@item
984Single-argument @code{+} (identity), @code{-} (arithmetic opposite), or
985@code{~} (bitwise negation). @emph{The argument must be an absolute
986expression.}
987
988@item
989@code{*} (multiplication) and @code{/} (division). @emph{Both arguments
990must be absolute expressions.}
991
992@item
993@code{+} (addition) and @code{-} (subtraction). @emph{At least one argument
994must be absolute.}
995@c FIXME! Actually, subtraction doesn't check for this.
996
997@item
998@code{&} (bitwise and). @emph{Both arguments must be absolute.}
999
1000@item
1001@c FIXME! I agree ~ is a better notation than ^ for xor, but is the
1002@c improvement worth differing from C?
1003@code{|} (bitwise or) and @code{~} (bitwise exclusive or; @code{^} in
1004C). @emph{Both arguments must be absolute.}
1005@end enumerate
1006
1007@node String Builtins
1008@subsection String primitives
1009
1010You can use these primitives to manipulate strings (in the argument
1011field of @sc{gasp} statements):
1012
1013@ftable @code
1014@item .LEN("@var{str}")
1015Calculate the length of string @code{"@var{str}"}, as an absolute
1016expression. For example, @samp{.RES.B .LEN("sample")} reserves six
1017bytes of memory.
1018
1019@item .INSTR("@var{string}", "@var{seg}", @var{ix})
1020Search for the first occurrence of @var{seg} after position @var{ix} of
1021@var{string}. For example, @samp{.INSTR("ABCDEFG", "CDE", 0)} evaluates
1022to the absolute result @code{2}.
1023
1024The result is @code{-1} if @var{seg} does not occur in @var{string}
1025after position @var{ix}.
1026
1027@item .SUBSTR("@var{string}",@var{start},@var{len})
1028The substring of @var{string} beginning at byte number @var{start} and
1029extending for @var{len} bytes.
1030@end ftable
1031
1032@node Alternate
1033@section Alternate macro syntax
1034
1035If you specify @samp{-a} or @samp{--alternate} on the @sc{gasp} command
1036line, the preprocessor uses somewhat different syntax. This syntax is
1037reminiscent of the syntax of Phar Lap macro assembler, but it
1038is @emph{not} meant to be a full emulation of Phar Lap or similar
1039assemblers. In particular, @sc{gasp} does not support directives such
1040as @code{DB} and @code{IRP}, even in alternate syntax mode.
1041
1042In particular, @samp{-a} (or @samp{--alternate}) elicits these
1043differences:
1044
1045@table @emph
1046@item Preprocessor directives
1047You can use @sc{gasp} preprocessor directives without a leading @samp{.}
1048dot. For example, you can write @samp{SDATA} with the same effect as
1049@samp{.SDATA}.
1050
1051@item LOCAL
1052One additional directive, @code{LOCAL}, is available. @xref{Macros,,
1053Defining your own directives}, for an explanation of how to use
1054@code{LOCAL}.
1055
1056@need 2000
1057@item String delimiters
1058You can write strings delimited in these other ways besides
1059@code{"@var{string}"}:
1060
1061@table @code
1062@item '@var{string}'
1063You can delimit strings with single-quote charaters.
1064
1065@item <@var{string}>
1066You can delimit strings with matching angle brackets.
1067@end table
1068
1069@item single-character string escape
1070To include any single character literally in a string (even if the
1071character would otherwise have some special meaning), you can prefix the
1072character with @samp{!} (an exclamation mark). For example, you can
1073write @samp{<4.3 !> 5.4!!>} to get the literal text @samp{4.3 > 5.4!}.
1074
1075@item Expression results as strings
1076You can write @samp{%@var{expr}} to evaluate the expression @var{expr}
1077and use the result as a string.
1078@end table
1079
1080@node Index
1081@unnumbered Index
1082
1083@printindex cp
1084
1085@contents
1086@bye
This page took 0.09741 seconds and 4 git commands to generate.