⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gasp.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<H2><A NAME="SEC5" HREF="gasp_toc.html#TOC5">Repetitive sections of assembly</A></H2><P>Two preprocessor directives allow you to repeatedly issue copies of thesame block of assembly code.</P><DL COMPACT><DT><CODE>.AREPEAT <VAR>aexp</VAR></CODE><DD><A NAME="IDX39"></A><DT><CODE>.AENDR</CODE><DD><A NAME="IDX40"></A>If you simply need to repeat the same block of assembly over and over afixed number of times, sandwich one instance of the repeated blockbetween <CODE>.AREPEAT</CODE> and <CODE>.AENDR</CODE>.  Specify the number ofcopies as <VAR>aexp</VAR> (which must be an absolute expression).  Forexample, this repeats two assembly statements three times in succession:<PRE>        .AREPEAT        3        rotcl   r2        div1    r0,r1        .AENDR</PRE><DT><CODE>.AWHILE <VAR>expra</VAR> <VAR>cmp</VAR> <VAR>exprb</VAR></CODE><DD><A NAME="IDX41"></A><DT><CODE>.AENDW</CODE><DD><A NAME="IDX42"></A><DT><CODE>.AWHILE <VAR>stra</VAR> <VAR>cmp</VAR> <VAR>strb</VAR></CODE><DD><A NAME="IDX43"></A><DT><CODE>.AENDW</CODE><DD><A NAME="IDX44"></A>To repeat a block of assembly depending on a conditional test, ratherthan repeating it for a specific number of times, use <CODE>.AWHILE</CODE>.<CODE>.AENDW</CODE> marks the end of the repeated block.  The conditionalcomparison works exactly the same way as for <CODE>.AIF</CODE>, with the samecomparison operators (see section <A HREF="gasp.html#SEC4">Conditional assembly</A>).Since the terms of the comparison must be absolute expression,<CODE>.AWHILE</CODE> is primarily useful within macros.  See section <A HREF="gasp.html#SEC7">Defining your own directives</A>.</DL><P><A NAME="IDX45"></A><A NAME="IDX46"></A>You can use the <CODE>.EXITM</CODE> preprocessor directive to break out ofloops early (as well as to break out of macros).  See section <A HREF="gasp.html#SEC7">Defining your own directives</A>.</P><H2><A NAME="SEC6" HREF="gasp_toc.html#TOC6">Preprocessor variables</A></H2><P>You can use variables in GASP to represent strings, registers, orthe results of expressions.</P><P>You must distinguish two kinds of variables: <OL><LI>Variables defined with <CODE>.EQU</CODE> or <CODE>.ASSIGN</CODE>.  To evaluate thiskind of variable in your assembly output, simply mention its name.  Forexample, these two lines define and use a variable <SAMP>`eg'</SAMP>:<PRE>eg     .EQU   FLIP-64       ...       mov.l  eg,r0</PRE><EM>Do not use</EM> this kind of variable in conditional expressions orwhile loops; GASP only evaluates these variables when writingassembly output.<LI>Variables for use during preprocessing.  You can define thesewith <CODE>.ASSIGNC</CODE> or <CODE>.ASSIGNA</CODE>.  To evaluate thiskind of variable, write <SAMP>`\&#38;'</SAMP> before the variable name; for example,<PRE>opcit  .ASSIGNA  47       ...       .AWHILE  \&#38;opcit GT 0       ...       .AENDW</PRE>GASP treats macro arguments almost the same way, but to evaluatethem you use the prefix <SAMP>`\'</SAMP> rather than <SAMP>`\&#38;'</SAMP>.See section <A HREF="gasp.html#SEC7">Defining your own directives</A>.</OL><DL COMPACT><DT><CODE><VAR>pvar</VAR> .EQU <VAR>expr</VAR></CODE><DD><A NAME="IDX47"></A>Assign preprocessor variable <VAR>pvar</VAR> the value of the expression<VAR>expr</VAR>.  There are no restrictions on redefinition; use <SAMP>`.EQU'</SAMP>with the same <VAR>pvar</VAR> as often as you find it convenient.<DT><CODE><VAR>pvar</VAR> .ASSIGN <VAR>expr</VAR></CODE><DD><A NAME="IDX48"></A>Almost the same as <CODE>.EQU</CODE>, save that you may not redefine<VAR>pvar</VAR> using <CODE>.ASSIGN</CODE> once it has a value.<DT><CODE><VAR>pvar</VAR> .ASSIGNA <VAR>aexpr</VAR></CODE><DD><A NAME="IDX49"></A>Define a variable with a numeric value, for use during preprocessing.<VAR>aexpr</VAR> must be an absolute expression.  You can redefine variableswith <CODE>.ASSIGNA</CODE> at any time.<DT><CODE><VAR>pvar</VAR> .ASSIGNC "<VAR>str</VAR>"</CODE><DD><A NAME="IDX50"></A>Define a variable with a string value, for use during preprocessing.You can redefine variables with <CODE>.ASSIGNC</CODE> at any time.<DT><CODE><VAR>pvar</VAR> .REG (<VAR>register</VAR>)</CODE><DD><A NAME="IDX51"></A>Use <CODE>.REG</CODE> to define a variable that represents a register.  Inparticular, <VAR>register</VAR> is <EM>not evaluated</EM> as an expression.You may use <CODE>.REG</CODE> at will to redefine register variables.</DL><P>All these directives accept the variable name in the "label" position,that is at the left margin.  You may specify a colon after the variablename if you wish; the first example above could have started <SAMP>`eg:'</SAMP>with the same effect.</P><H2><A NAME="SEC7" HREF="gasp_toc.html#TOC7">Defining your own directives</A></H2><P>The commands <CODE>.MACRO</CODE> and <CODE>.ENDM</CODE> allow you to define macrosthat generate assembly output.  You can use these macros with a syntaxsimilar to built-in GASP or assembler directives.  For example,this definition specifies a macro <CODE>SUM</CODE> that adds together a range ofconsecutive registers:</P><PRE>        .MACRO  SUM FROM=0, TO=9        ! \FROM \TO        mov     r\FROM,r10COUNT   .ASSIGNA        \FROM+1        .AWHILE \&#38;COUNT LE \TO        add     r\&#38;COUNT,r10COUNT   .ASSIGNA        \&#38;COUNT+1        .AENDW        .ENDM</PRE><P>With that definition, <SAMP>`SUM 0,5'</SAMP> generates this assembly output:</P><PRE>        ! 0 5        mov     r0,r10        add     r1,r10        add     r2,r10        add     r3,r10        add     r4,r10        add     r5,r10</PRE><DL COMPACT><DT><CODE>.MACRO <VAR>macname</VAR></CODE><DD><A NAME="IDX52"></A><DT><CODE>.MACRO <VAR>macname</VAR> <VAR>macargs</VAR> ...</CODE><DD><A NAME="IDX53"></A>Begin the definition of a macro called <VAR>macname</VAR>.  If your macrodefinition requires arguments, specify their names after the macro name,separated by commas or spaces.  You can supply a default value for anymacro argument by following the name with <SAMP>`=<VAR>deflt</VAR>'</SAMP>.  Forexample, these are all valid <CODE>.MACRO</CODE> statements:<DL COMPACT><DT><CODE>.MACRO COMM</CODE><DD>Begin the definition of a macro called <CODE>COMM</CODE>, which takes noarguments.<DT><CODE>.MACRO PLUS1 P, P1</CODE><DD><DT><CODE>.MACRO PLUS1 P P1</CODE><DD>Either statement begins the definition of a macro called <CODE>PLUS1</CODE>,which takes two arguments; within the macro definition, write<SAMP>`\P'</SAMP> or <SAMP>`\P1'</SAMP> to evaluate the arguments.<DT><CODE>.MACRO RESERVE_STR P1=0 P2</CODE><DD>Begin the definition of a macro called <CODE>RESERVE_STR</CODE>, with twoarguments.  The first argument has a default value, but not the second.After the definition is complete, you can call the macro either as<SAMP>`RESERVE_STR <VAR>a</VAR>,<VAR>b</VAR>'</SAMP> (with <SAMP>`\P1'</SAMP> evaluating to<VAR>a</VAR> and <SAMP>`\P2'</SAMP> evaluating to <VAR>b</VAR>), or as <SAMP>`RESERVE_STR,<VAR>b</VAR>'</SAMP> (with <SAMP>`\P1'</SAMP> evaluating as the default, in this case<SAMP>`0'</SAMP>, and <SAMP>`\P2'</SAMP> evaluating to <VAR>b</VAR>).</DL>When you call a macro, you can specify the argument values either byposition, or by keyword.  For example, <SAMP>`SUM 9,17'</SAMP> is equivalent to<SAMP>`SUM TO=17, FROM=9'</SAMP>.  Macro arguments are preprocessor variablessimilar to the variables you define with <SAMP>`.ASSIGNA'</SAMP> or<SAMP>`.ASSIGNC'</SAMP>; in particular, you can use them in conditionals or forloop control.  (The only difference is the prefix you write to evaluatethe variable: for a macro argument, write <SAMP>`\<VAR>argname</VAR>'</SAMP>, but fora preprocessor variable, write <SAMP>`\&#38;<VAR>varname</VAR>'</SAMP>.)<DT><CODE><VAR>name</VAR> .MACRO</CODE><DD><A NAME="IDX54"></A><DT><CODE><VAR>name</VAR> .MACRO ( <VAR>macargs</VAR> ... )</CODE><DD><A NAME="IDX55"></A>An alternative form of introducing a macro definition: specify the macroname in the label position, and the arguments (if any) betweenparentheses after the name.  Defaulting rules and usage work the sameway as for the other macro definition syntax.<DT><CODE>.ENDM</CODE><DD><A NAME="IDX56"></A>Mark the end of a macro definition.<DT><CODE>.EXITM</CODE><DD><A NAME="IDX57"></A>Exit early from the current macro definition, <CODE>.AREPEAT</CODE> loop, or<CODE>.AWHILE</CODE> loop.<A NAME="IDX58"></A><A NAME="IDX59"></A><DT><CODE>\@</CODE><DD><A NAME="IDX60"></A>GASP maintains a counter of how many macros it hasexecuted in this pseudo-variable; you can copy that number to youroutput with <SAMP>`\@'</SAMP>, but <EM>only within a macro definition</EM>.<DT><CODE>LOCAL <VAR>name</VAR> [ , ... ]</CODE><DD><A NAME="IDX61"></A><EM>Warning: <CODE>LOCAL</CODE> is only available if you select "alternatemacro syntax" with <SAMP>`-a'</SAMP> or <SAMP>`--alternate'</SAMP>.</EM>  See section <A HREF="gasp.html#SEC19">Alternate macro syntax</A>.Generate a string replacement for each of the <VAR>name</VAR> arguments, andreplace any instances of <VAR>name</VAR> in each macro expansion.  Thereplacement string is unique in the assembly, and different for eachseparate macro expansion.  <CODE>LOCAL</CODE> allows you to write macros thatdefine symbols, without fear of conflict between separate macro expansions.</DL><H2><A NAME="SEC8" HREF="gasp_toc.html#TOC8">Data output</A></H2><P>In assembly code, you often need to specify working areas of memory;depending on the application, you may want to initialize such memory ornot.  GASP provides preprocessor directives to help you avoidrepetitive coding for both purposes.</P><P>You can use labels as usual to mark the data areas.</P><H3><A NAME="SEC9" HREF="gasp_toc.html#TOC9">Initialized data</A></H3><P>These are the GASP directives for initialized data, and the standardGNU assembler directives they expand to:</P><DL COMPACT><DT><CODE>.DATA <VAR>expr</VAR>, <VAR>expr</VAR>, ...</CODE><DD><A NAME="IDX62"></A><DT><CODE>.DATA.B <VAR>expr</VAR>, <VAR>expr</VAR>, ...</CODE><DD><A NAME="IDX63"></A><DT><CODE>.DATA.W <VAR>expr</VAR>, <VAR>expr</VAR>, ...</CODE><DD><A NAME="IDX64"></A><DT><CODE>.DATA.L <VAR>expr</VAR>, <VAR>expr</VAR>, ...</CODE><DD><A NAME="IDX65"></A>Evaluate arithmetic expressions <VAR>expr</VAR>, and emit the corresponding<CODE>as</CODE> directive (labelled with <VAR>lab</VAR>).  The unqualified<CODE>.DATA</CODE> emits <SAMP>`.long'</SAMP>; <CODE>.DATA.B</CODE> emits <SAMP>`.byte'</SAMP>;<CODE>.DATA.W</CODE> emits <SAMP>`.short'</SAMP>; and <CODE>.DATA.L</CODE> emits<SAMP>`.long'</SAMP>.For example, <SAMP>`foo .DATA 1,2,3'</SAMP> emits <SAMP>`foo: .long 1,2,3'</SAMP>.<DT><CODE>.DATAB <VAR>repeat</VAR>, <VAR>expr</VAR></CODE><DD><A NAME="IDX66"></A><DT><CODE>.DATAB.B <VAR>repeat</VAR>, <VAR>expr</VAR></CODE><DD><A NAME="IDX67"></A><DT><CODE>.DATAB.W <VAR>repeat</VAR>, <VAR>expr</VAR></CODE><DD><A NAME="IDX68"></A><DT><CODE>.DATAB.L <VAR>repeat</VAR>, <VAR>expr</VAR></CODE><DD><A NAME="IDX69"></A>Make <CODE>as</CODE> emit <VAR>repeat</VAR> copies of the value of the expression<VAR>expr</VAR> (using the <CODE>as</CODE> directive <CODE>.fill</CODE>).<SAMP>`.DATAB.B'</SAMP> repeats one-byte values; <SAMP>`.DATAB.W'</SAMP> repeatstwo-byte values; and <SAMP>`.DATAB.L'</SAMP> repeats four-byte values.<SAMP>`.DATAB'</SAMP> without a suffix repeats four-byte values, just like<SAMP>`.DATAB.L'</SAMP>.<VAR>repeat</VAR> must be an absolute expression with a positive value.<DT><CODE>.SDATA "<VAR>str</VAR>" ...</CODE><DD><A NAME="IDX70"></A>String data.  Emits a concatenation of bytes, precisely as you specifythem (in particular, <EM>nothing is added to mark the end</EM> of thestring).  See section <A HREF="gasp.html#SEC15">String and numeric constants</A>, for detailsabout how to write strings.  <CODE>.SDATA</CODE> concatenates multiplearguments, making it easy to switch between string representations.  Youcan use commas to separate the individual arguments for clarity, if youchoose.<DT><CODE>.SDATAB <VAR>repeat</VAR>, "<VAR>str</VAR>" ...</CODE><DD><A NAME="IDX71"></A>Repeated string data.  The first argument specifies how many copies ofthe string to emit; the remaining arguments specify the string, in thesame way as the arguments to <CODE>.SDATA</CODE>.<DT><CODE>.SDATAZ "<VAR>str</VAR>" ...</CODE><DD><A NAME="IDX72"></A>Zero-terminated string data.  Just like <CODE>.SDATA</CODE>, except that<CODE>.SDATAZ</CODE> writes a zero byte at the end of the string.<DT><CODE>.SDATAC "<VAR>str</VAR>" ...</CODE><DD><A NAME="IDX73"></A>Count-prefixed string data.  Just like <CODE>.SDATA</CODE>, except thatGASP precedes the string with a leading one-byte count.  Forexample, <SAMP>`.SDATAC "HI"'</SAMP> generates <SAMP>`.byte 2,72,73'</SAMP>.  Since thecount field is only one byte, you can only use <CODE>.SDATAC</CODE> forstrings less than 256 bytes in length.</DL>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -