shithub: rgbds

ref: 95cd960b3b11554c27c7b2952b08fc43f02cb5cf
dir: /doc/asm/expr_int.htm/

View raw version
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>xAsm Integer/Boolean expressions</title>
        <link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>Integer and Boolean expressions</h1>
<p>An expression can be composed of many things. Expressions are always evaluated using signed 32-bit math.</p>
<p>The most basic expression is just a single number.</p>
<h2>Numeric Formats</h2>
<p>xAsm has a number of numeric formats.</p>
<ul>
	<li>Hexadecimal: $0123456789ABCDEF. Case-insensitive
	<li>Decimal: 0123456789
	<li>Octal: &01234567
	<li>Binary: %01
	<li>Fixedpoint (16.16): 01234.56789
	<li>Character constant: "ABYZ"
	<li>Gameboy graphics: `0123
</ul>
<p>The last one, Gameboy graphics, is quite interesting and useful. The values are actually pixel values and it converts the “chunky” data to “planar” data as used in the Gameboy.</p>
<pre>DW   `01012323</pre>
<p>Admittedly an expression with just a single number is quite boring. To spice things up a bit there’s a few operators you can use to perform calculations between numbers.</p>
<h2>Operators</h2>
<p>A great number of operators you can use in expressions are available (listed in order of precedence):</p>
<table>
	<caption>Operators</caption>
<thead>
<tr>
	<th scope="col">Operator</th>
	<th scope="col">Meaning</th>
</tr>
</thead>
<tr>
	<td>( )</td>
	<td>Precedence override</td>
</tr>
<tr>
	<td>FUNC()</td>
	<td>Functioncall</td>
</tr>
<tr>
	<td>~ + -</td>
	<td>Unary not/plus/minus</td>
</tr>
<tr>
	<td>* / %</td>
	<td>Multiply/divide/modulo</td>
</tr>
<tr>
	<td>&lt;&lt; &gt;&gt;</td>
	<td>Shift left/right</td>
</tr>
<tr>
	<td>&amp; | ^</td>
	<td>Binary and/or/xor</td>
</tr>
<tr>
	<td>+ -</td>
	<td>Add/subtract</td>
</tr>
<tr>
	<td>!= == &lt;= &gt;= &lt; &gt;</td>
	<td>Boolean comparison</td>
</tr>
<tr>
	<td>&amp;&amp; ||</td>
	<td>Boolean and/or</td>
</tr>
<tr>
	<td>!</td>
	<td>Unary Boolean not</td>
</tr>
</table>     

<p>The result of the boolean operators is zero if when FALSE and non-zero when TRUE. Thus it is legal to use an integer as the condition for <a href="if.htm">IF</a> blocks. You can use symbols instead of numbers in your expression if you wish.</p>

<p>An expression is said to be constant when it doesn't change its value during linking. This basically means that you can't use labels in those expressions. The instructions in the macro-language all require expressions that are constant.</p>
<h1>See also:</h1>
<ul>
	<li><a href="symbols.htm">Symbols</a>
	<li><a href="expr_fix.htm">Fixed-point expressions and functions</a>
	<li><a href="expr_str.htm">String expressions, functions and formatting</a>
	<li><a href="miscfunc.htm">Other functions</a>
</ul>

<hr>
<p>Last updated 21 June 1997 by <a href="mailto:[email protected]">Carsten Sorensen</a></p>
</body>
</html>