ca65-9.html
来自「cc65 的编译器文档」· HTML 代码 · 共 535 行 · 第 1/2 页
HTML
535 行
.if (.match (.mid (0, 1, arg), #)) ; ldax called with immidiate operand ... .endif ... .endmacro </PRE></CODE></BLOCKQUOTE></P><P>See also the <CODE><A HREF="#.LEFT">.LEFT</A></CODE> and <CODE><A HREF="#.RIGHT">.RIGHT</A></CODE> builtin functions.</P><H2><A NAME=".REFERENCED"></A> <A NAME="ss9.12">9.12</A> <A HREF="ca65.html#toc9.12"><CODE>.REF, .REFERENCED</CODE></A></H2><P>Builtin function. The function expects an identifier as argument in braces.The argument is evaluated, and the function yields "true" if the identifieris a symbol that has already been referenced somewhere in the source file upto the current position. Otherwise the function yields false. As an example,the <CODE><A HREF="ca65-10.html#.IFREF">.IFREF</A></CODE> statement may be replaced by</P><P><BLOCKQUOTE><CODE><PRE> .if .referenced(a) </PRE></CODE></BLOCKQUOTE></P><P>See: <CODE><A HREF="ca65-10.html#.DEFINED">.DEFINED</A></CODE></P><H2><A NAME=".RIGHT"></A> <A NAME="ss9.13">9.13</A> <A HREF="ca65.html#toc9.13"><CODE>.RIGHT</CODE></A></H2><P>Builtin function. Extracts the right part of a given token list.</P><P>Syntax:</P><P><BLOCKQUOTE><CODE><PRE> .RIGHT (<int expr>, <token list>) </PRE></CODE></BLOCKQUOTE></P><P>The first integer expression gives the number of tokens to extract fromthe token list. The second argument is the token list itself.</P><P>See also the <CODE><A HREF="#.LEFT">.LEFT</A></CODE> and <CODE><A HREF="#.MID">.MID</A></CODE> builtin functions.</P><H2><A NAME=".SIZEOF"></A> <A NAME="ss9.14">9.14</A> <A HREF="ca65.html#toc9.14"><CODE>.SIZEOF</CODE></A></H2><P><CODE>.SIZEOF</CODE> is a pseudo function that returns the size of its argument. Theargument can be a struct/union, a struct member, a procedure, or a label. Incase of a procedure or label, its size is defined by the amount of dataplaced in the segment where the label is relative to. If a line of codeswitches segments (for example in a macro) data placed in other segmentsdoes not count for the size.</P><P>Please note that a symbol or scope must exist, before it is used together with<CODE>.SIZEOF</CODE> (this may get relaxed later, but will always be true for scopes).A scope has preference over a symbol with the same name, so if the last partof a name represents both, a scope and a symbol, the scope is choosen over thesymbol.</P><P>After the following code:</P><P><BLOCKQUOTE><CODE><PRE> .struct Point ; Struct size = 4 xcoord .word xcoord .word .endstruct P: .tag Point ; Declare a point @P: .tag Point ; Declare another point .code .proc Code nop .proc Inner nop .endproc nop .endproc .proc Data .data ; Segment switch!!! .res 4 .endproc </PRE></CODE></BLOCKQUOTE></P><P><DL><DT><B><CODE>.sizeof(Point)</CODE></B><DD><P>will have the value 4, because this is the size of struct <CODE>Point</CODE>.</P><DT><B><CODE>.sizeof(Point::xcoord)</CODE></B><DD><P>will have the value 2, because this is the size of the member <CODE>xcoord</CODE>in struct <CODE>Point</CODE>.</P><DT><B><CODE>.sizeof(P)</CODE></B><DD><P>will have the value 4, this is the size of the data declared on the samesource line as the label <CODE>P</CODE>, which is in the same segment that <CODE>P</CODE>is relative to.</P><DT><B><CODE>.sizeof(@P)</CODE></B><DD><P>will have the value 4, see above. The example demonstrates that <CODE>.SIZEOF</CODE>does also work for cheap local symbols.</P><DT><B><CODE>.sizeof(Code)</CODE></B><DD><P>will have the value 3, since this is amount of data emitted into the codesegment, the segment that was active when <CODE>Code</CODE> was entered. Note thatthis value includes the amount of data emitted in child scopes (in thiscase <CODE>Code::Inner</CODE>).</P><DT><B><CODE>.sizeof(Code::Inner)</CODE></B><DD><P>will have the value 1 as expected.</P><DT><B><CODE>.sizeof(Data)</CODE></B><DD><P>will have the value 0. Data is emitted within the scope <CODE>Data</CODE>, but sincethe segment is switched after entry, this data is emitted into anothersegment.</P></DL></P><H2><A NAME=".STRAT"></A> <A NAME="ss9.15">9.15</A> <A HREF="ca65.html#toc9.15"><CODE>.STRAT</CODE></A></H2><P>Builtin function. The function accepts a string and an index asarguments and returns the value of the character at the given positionas an integer value. The index is zero based.</P><P>Example:</P><P><BLOCKQUOTE><CODE><PRE> .macro M Arg ; Check if the argument string starts with '#' .if (.strat (Arg, 0) = '#') ... .endif .endmacro </PRE></CODE></BLOCKQUOTE></P><H2><A NAME=".STRING"></A> <A NAME="ss9.16">9.16</A> <A HREF="ca65.html#toc9.16"><CODE>.STRING</CODE></A></H2><P>Builtin function. The function accepts an argument in braces and convertsthis argument into a string constant. The argument may be an identifier, ora constant numeric value.</P><P>Since you can use a string in the first place, the use of the function maynot be obvious. However, it is useful in macros, or more complex setups.</P><P>Example:</P><P><BLOCKQUOTE><CODE><PRE> ; Emulate other assemblers: .macro section name .segment .string(name) .endmacro </PRE></CODE></BLOCKQUOTE></P><H2><A NAME=".STRLEN"></A> <A NAME="ss9.17">9.17</A> <A HREF="ca65.html#toc9.17"><CODE>.STRLEN</CODE></A></H2><P>Builtin function. The function accepts a string argument in braces andeveluates to the length of the string.</P><P>Example:</P><P>The following macro encodes a string as a pascal style string witha leading length byte.</P><P><BLOCKQUOTE><CODE><PRE> .macro PString Arg .byte .strlen(Arg), Arg .endmacro </PRE></CODE></BLOCKQUOTE></P><H2><A NAME=".TCOUNT"></A> <A NAME="ss9.18">9.18</A> <A HREF="ca65.html#toc9.18"><CODE>.TCOUNT</CODE></A></H2><P>Builtin function. The function accepts a token list in braces. Thefunction result is the number of tokens given as argument.</P><P>Example:</P><P>The <CODE>ldax</CODE> macro accepts the '#' token to denote immidiate addressing (aswith the normal 6502 instructions). To translate it into two separate 8 bitload instructions, the '#' token has to get stripped from the argument:</P><P><BLOCKQUOTE><CODE><PRE> .macro ldax arg .if (.match (.mid (0, 1, arg), #)) ; ldax called with immidiate operand lda #<(.right (.tcount (arg)-1, arg)) ldx #>(.right (.tcount (arg)-1, arg)) .else ... .endif .endmacro </PRE></CODE></BLOCKQUOTE></P><H2><A NAME=".XMATCH"></A> <A NAME="ss9.19">9.19</A> <A HREF="ca65.html#toc9.19"><CODE>.XMATCH</CODE></A></H2><P>Builtin function. Matches two token lists against each other. This ismost useful within macros, since macros are not stored as strings, butas lists of tokens.</P><P>The syntax is</P><P><BLOCKQUOTE><CODE><PRE> .XMATCH(<token list #1>, <token list #2>) </PRE></CODE></BLOCKQUOTE></P><P>Both token list may contain arbitrary tokens with the exception of theterminator token (comma resp. right parenthesis) and</P><P><UL><LI>end-of-line</LI><LI>end-of-file</LI></UL></P><P>Often a macro parameter is used for any of the token lists.</P><P>The function compares tokens <EM>and</EM> token values. If you need a functionthat just compares the type of tokens, have a look at the <CODE><A HREF="#.MATCH">.MATCH</A></CODE> function.</P><P>See: <CODE><A HREF="#.MATCH">.MATCH</A></CODE></P><HR><A HREF="ca65-10.html">Next</A><A HREF="ca65-8.html">Previous</A><A HREF="ca65.html#toc9">Contents</A></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?