How it works

The Instruction operation "arithmetic" can be used to work on more complex arithmetic expressions than a single add or subtract, using common mathematical expression handling (also known as 'infix' notation.) Either floating point decimal numbers, or hexadecimal numbers may be used (prefix hexadecimal with 0x).

"Arithmetic" Examples

Example 1: Basic A simple expression

The example below shows how the 'name' attribute is used for variable substitution.

<instruction operation="arithmetic">
	<input value="(x+y)*3-2" />
	<input name="x" value="4" />
	<input name="y" value="3" />
</instruction>
19

Here is a list of operators that the arithemetic expression handler understands:

  1. * (multiply)
  2. + (add)
  3. - (subtract/unary minus)
  4. / (divide)
  5. \ (quotient)
  6. % (modulo)

Here is a list of functions that the arithemetic expression handler understands, that take 2 parameters:

  1. pow() power function
  2. max() maximum function
  3. min() minimum function
  4. xor() (bitwise exclusive or function)
  5. and() (bitwise and function)
  6. or() (bitwise or function)
<instruction operation="arithmetic" note="example using 2 parameter functions.">
	<input value="and(max(pow(x,y),pow(y,x)),0x33)" />
	<input name="x" value="4" />
	<input name="y" value="3" />
</instruction>
17

Here is a list of functions that the arithemetic expression handler understands, that take 1 parameter:

  1. not (bitwise not function)
  2. round (round to integer function)
  3. floor (nearest lower integer function)
  4. ceil (nearest upper integer function)
  5. abs (absolute function)
<instruction operation="arithmetic" note="example using 1 parameter functions.">
	<input value="not(ceil(x)+floor(y))" />
	<input name="x" value="4.133" />
	<input name="y" value="3.013" />
</instruction>
-9

Here is a list of functions that the arithemetic expression handler understands, that take 3 parameters:

  1. rol (rotate bits left function with wordsize)
  2. ror (rotate bits right function with wordsize)

Note that any bits outside of the word length are not touched!

<instruction operation="arithmetic" note="rotate 7 bits left on an 8 bit word.">
	<input value="rol(x,7,8)" />
	<input name="x" value="43" />
</instruction>
149

Note that below we are outputting the result in base 16, using the precision attribute.

<instruction precision="b16" operation="arithmetic" note="flip lowest bit using 2-bit word.">
	<input value="rol(x,1,2)" />
	<input name="x" value="0x55" />
</instruction>
56



Last Modified: Thu, 15 Jan 2015