ca65-4.html
来自「cc65 的编译器文档」· HTML 代码 · 共 169 行
HTML
169 行
<!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: Expressions</TITLE> <LINK HREF="ca65-5.html" REL=next> <LINK HREF="ca65-3.html" REL=previous> <LINK HREF="ca65.html#toc4" REL=contents></HEAD><BODY><A HREF="ca65-5.html">Next</A><A HREF="ca65-3.html">Previous</A><A HREF="ca65.html#toc4">Contents</A><HR><H2><A NAME="s4">4.</A> <A HREF="ca65.html#toc4">Expressions</A></H2><H2><A NAME="ss4.1">4.1</A> <A HREF="ca65.html#toc4.1">Expression evaluation</A></H2><P>All expressions are evaluated with (at least) 32 bit precision. Anexpression may contain constant values and any combination of internal andexternal symbols. Expressions that cannot be evaluated at assembly timeare stored inside the object file for evaluation by the linker.Expressions referencing imported symbols must always be evaluated by thelinker.</P><H2><A NAME="ss4.2">4.2</A> <A HREF="ca65.html#toc4.2">Size of an expression result</A></H2><P>Sometimes, the assembler must know about the size of the value that is theresult of an expression. This is usually the case, if a decision has to bemade, to generate a zero page or an absolute memory references. In thiscase, the assembler has to make some assumptions about the result of anexpression:</P><P><UL><LI> If the result of an expression is constant, the actual value ischecked to see if it's a byte sized expression or not.</LI><LI> If the expression is explicitly casted to a byte sized expression byone of the '>', '<' or '^' operators, it is a byte expression.</LI><LI> If this is not the case, and the expression contains a symbol,explicitly declared as zero page symbol (by one of the .importzp or.exportzp instructions), then the whole expression is assumed to bebyte sized.</LI><LI> If the expression contains symbols that are not defined, and thesesymbols are local symbols, the enclosing scopes are searched for asymbol with the same name. If one exists and this symbol is defined,it's attributes are used to determine the result size.</LI><LI> In all other cases the expression is assumed to be word sized.</LI></UL></P><P>Note: If the assembler is not able to evaluate the expression at assemblytime, the linker will evaluate it and check for range errors as soon asthe result is known.</P><H2><A NAME="ss4.3">4.3</A> <A HREF="ca65.html#toc4.3">Boolean expressions</A></H2><P>In the context of a boolean expression, any non zero value is evaluated astrue, any other value to false. The result of a boolean expression is 1 ifit's true, and zero if it's false. There are boolean operators with extremlow precedence with version 2.x (where x > 0). The <CODE>.AND</CODE> and <CODE>.OR</CODE>operators are shortcut operators. That is, if the result of the expression isalready known, after evaluating the left hand side, the right hand side isnot evaluated.</P><H2><A NAME="ss4.4">4.4</A> <A HREF="ca65.html#toc4.4">Constant expressions</A></H2><P>Sometimes an expression must evaluate to a constant without looking at anyfurther input. One such example is the <CODE><A HREF="ca65-10.html#.IF">.IF</A></CODE> commandthat decides if parts of the code are assembled or not. An expression used inthe <CODE>.IF</CODE> command cannot reference a symbol defined later, because thedecision about the <CODE>.IF</CODE> must be made at the point when it is read. If theexpression used in such a context contains only constant numerical values,there is no problem. When unresolvable symbols are involved it may get harderfor the assembler to determine if the expression is actually constant, and itis even possible to create expressions that aren't recognized as constant.Simplifying the expressions will often help.</P><P>In cases where the result of the expression is not needed immediately, theassembler will delay evaluation until all input is read, at which point allsymbols are known. So using arbitrary complex constant expressions is noproblem in most cases.</P><H2><A NAME="operators"></A> <A NAME="ss4.5">4.5</A> <A HREF="ca65.html#toc4.5">Available operators</A></H2><P>Available operators sorted by precedence:</P><P><BLOCKQUOTE><CODE><PRE> Op Description Precedence ------------------------------------------------------------------- Builtin string functions 0 Builtin pseudo variables 1 Builtin pseudo functions 1 + Unary plus 1 - Unary minus 1 ~ Unary bitwise not 1 .BITNOT Unary bitwise not 1 < Low byte operator 1 > High byte operator 1 ^ Bank byte operator 1 * Multiplication 2 / Division 2 .MOD Modulo operation 2 & Bitwise and 2 .BITAND Bitwise and 2 ^ Bitwise xor 2 .BITXOR Bitwise xor 2 << Shift left operator 2 .SHL Shift left operator 2 >> Shift right operator .SHR Shift right operator 2 + Binary plus 3 - Binary minus 3 | Binary or 3 .BITOR Binary or 3 = Compare operation (equal) 4 <> Compare operation (not equal) 4 < Compare operation (less) 4 > Compare operation (greater) 4 <= Compare operation (less or equal) 4 >= Compare operation (greater or equal) 4 && Boolean and 5 .AND Boolean and 5 .XOR Boolean xor 5 || Boolean or 6 .OR Boolean or 6 ! Boolean not 7 .NOT Boolean not 7</PRE></CODE></BLOCKQUOTE></P><P>To force a specific order of evaluation, braces may be used as usual.</P><HR><A HREF="ca65-5.html">Next</A><A HREF="ca65-3.html">Previous</A><A HREF="ca65.html#toc4">Contents</A></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?