ca65-9.html

来自「cc65 的编译器文档」· HTML 代码 · 共 535 行 · 第 1/2 页

HTML
535
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.20"> <TITLE>ca65 Users Guide: Pseudo functions</TITLE> <LINK HREF="ca65-10.html" REL=next> <LINK HREF="ca65-8.html" REL=previous> <LINK HREF="ca65.html#toc9" REL=contents></HEAD><BODY><A HREF="ca65-10.html">Next</A><A HREF="ca65-8.html">Previous</A><A HREF="ca65.html#toc9">Contents</A><HR><H2><A NAME="pseudo-functions"></A> <A NAME="s9">9.</A> <A HREF="ca65.html#toc9">Pseudo functions</A></H2><P>Pseudo functions expect their arguments in parenthesis, and they have a result,either a string or an expression.</P><H2><A NAME=".BANKBYTE"></A> <A NAME="ss9.1">9.1</A> <A HREF="ca65.html#toc9.1"><CODE>.BANKBYTE</CODE></A></H2><P>The function returns the bank byte (that is, bits 16-23) of its argument.It works identical to the '^' operator.</P><P>See: <CODE><A HREF="#.HIBYTE">.HIBYTE</A></CODE>,<CODE><A HREF="#.LOBYTE">.LOBYTE</A></CODE></P><H2><A NAME=".BLANK"></A> <A NAME="ss9.2">9.2</A> <A HREF="ca65.html#toc9.2"><CODE>.BLANK</CODE></A></H2><P>Builtin function. The function evaluates its argument in braces andyields "false" if the argument is non blank (there is an argument), and"true" if there is no argument. As an example, the <CODE>.IFBLANK</CODE> statementmay be replaced by</P><P><BLOCKQUOTE><CODE><PRE>        .if     .blank(arg)  </PRE></CODE></BLOCKQUOTE></P><H2><A NAME=".CONCAT"></A> <A NAME="ss9.3">9.3</A> <A HREF="ca65.html#toc9.3"><CODE>.CONCAT</CODE></A></H2><P>Builtin string function. The function allows to concatenate a list of stringconstants separated by commas. The result is a string constant that is theconcatentation of all arguments. This function is most useful in macros andwhen used together with the <CODE>.STRING</CODE> builtin function. The function maybe used in any case where a string constant is expected.</P><P>Example:</P><P><BLOCKQUOTE><CODE><PRE>        .include        .concat ("myheader", ".", "inc")  </PRE></CODE></BLOCKQUOTE></P><P>This is the same as the command</P><P><BLOCKQUOTE><CODE><PRE>        .include        "myheader.inc"  </PRE></CODE></BLOCKQUOTE></P><H2><A NAME=".CONST"></A> <A NAME="ss9.4">9.4</A> <A HREF="ca65.html#toc9.4"><CODE>.CONST</CODE></A></H2><P>Builtin function. The function evaluates its argument in braces andyields "true" if the argument is a constant expression (that is, anexpression that yields a constant value at assembly time) and "false"otherwise. As an example, the .IFCONST statement may be replaced by</P><P><BLOCKQUOTE><CODE><PRE>        .if     .const(a + 3)  </PRE></CODE></BLOCKQUOTE></P><H2><A NAME=".HIBYTE"></A> <A NAME="ss9.5">9.5</A> <A HREF="ca65.html#toc9.5"><CODE>.HIBYTE</CODE></A></H2><P>The function returns the high byte (that is, bits 8-15) of its argument.It works identical to the '>' operator.</P><P>See: <CODE><A HREF="#.LOBYTE">.LOBYTE</A></CODE>,<CODE><A HREF="#.BANKBYTE">.BANKBYTE</A></CODE></P><H2><A NAME=".HIWORD"></A> <A NAME="ss9.6">9.6</A> <A HREF="ca65.html#toc9.6"><CODE>.HIWORD</CODE></A></H2><P>The function returns the high word (that is, bits 16-31) of its argument.</P><P>See: <CODE><A HREF="#.LOWORD">.LOWORD</A></CODE></P><H2><A NAME=".LEFT"></A> <A NAME="ss9.7">9.7</A> <A HREF="ca65.html#toc9.7"><CODE>.LEFT</CODE></A></H2><P>Builtin function. Extracts the left part of a given token list.</P><P>Syntax:</P><P><BLOCKQUOTE><CODE><PRE>        .LEFT (&lt;int expr&gt;, &lt;token list&gt;)  </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>Example:</P><P>To check in a macro if the given argument has a '#' as first token(immidiate addressing mode), use something like this:</P><P><BLOCKQUOTE><CODE><PRE>        .macro  ldax    arg                ...                .if (.match (.left (1, arg), #))                ; ldax called with immidiate operand                ...                .endif                ...        .endmacro  </PRE></CODE></BLOCKQUOTE></P><P>See also the <CODE><A HREF="#.MID">.MID</A></CODE> and <CODE><A HREF="#.RIGHT">.RIGHT</A></CODE> builtin functions.</P><H2><A NAME=".LOBYTE"></A> <A NAME="ss9.8">9.8</A> <A HREF="ca65.html#toc9.8"><CODE>.LOBYTE</CODE></A></H2><P>The function returns the low byte (that is, bits 0-7) of its argument.It works identical to the '&lt;' operator.</P><P>See: <CODE><A HREF="#.HIBYTE">.HIBYTE</A></CODE>,<CODE><A HREF="#.BANKBYTE">.BANKBYTE</A></CODE></P><H2><A NAME=".LOWORD"></A> <A NAME="ss9.9">9.9</A> <A HREF="ca65.html#toc9.9"><CODE>.LOWORD</CODE></A></H2><P>The function returns the low word (that is, bits 0-15) of its argument.</P><P>See: <CODE><A HREF="#.HIWORD">.HIWORD</A></CODE></P><H2><A NAME=".MATCH"></A> <A NAME="ss9.10">9.10</A> <A HREF="ca65.html#toc9.10"><CODE>.MATCH</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>        .MATCH(&lt;token list #1&gt;, &lt;token list #2&gt;)  </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>Please note that the function does only compare tokens, not tokenattributes. So any number is equal to any other number, regardless of theactual value. The same is true for strings. If you need to compare tokens<EM>and</EM> token attributes, use the <CODE><A HREF="#.XMATCH">.XMATCH</A></CODE> function.</P><P>Example:</P><P>Assume the macro <CODE>ASR</CODE>, that will shift right the accumulator by one,while honoring the sign bit. The builtin processor instructions will allowan optional "A" for accu addressing for instructions like <CODE>ROL</CODE> and<CODE>ROR</CODE>. We will use the <CODE><A HREF="#.MATCH">.MATCH</A></CODE> functionto check for this and print and error for invalid calls.</P><P><BLOCKQUOTE><CODE><PRE>        .macro  asr     arg                .if (.not .blank(arg)) .and (.not .match (arg, a))                .error "Syntax error"                .endif                cmp     #$80            ; Bit 7 into carry                lsr     a               ; Shift carry into bit 7        .endmacro  </PRE></CODE></BLOCKQUOTE></P><P>The macro will only accept no arguments, or one argument that must be thereserved keyword "A".</P><P>See: <CODE><A HREF="#.XMATCH">.XMATCH</A></CODE></P><H2><A NAME=".MID"></A> <A NAME="ss9.11">9.11</A> <A HREF="ca65.html#toc9.11"><CODE>.MID</CODE></A></H2><P>Builtin function. Takes a starting index, a count and a token list asarguments. Will return part of the token list.</P><P>Syntax:</P><P><BLOCKQUOTE><CODE><PRE>        .MID (&lt;int expr&gt;, &lt;int expr&gt;, &lt;token list&gt;)  </PRE></CODE></BLOCKQUOTE></P><P>The first integer expression gives the starting token in the list (thefirst token has index 0). The second integer expression gives the numberof tokens to extract from the token list. The third argument is thetoken list itself.</P><P>Example:</P><P>To check in a macro if the given argument has a '<CODE>#</CODE>' as first token(immidiate addressing mode), use something like this:</P><P><BLOCKQUOTE><CODE><PRE>        .macro  ldax    arg                ...

⌨️ 快捷键说明

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