Skip to main content

FPU opcodes

The 32-bit Floating Point Unit add-on expands the Chombit instruction set with 28 new opcodes, including a new instruction ROUND:

OpcodeBytesCyclesFormExample
$4733MOVE F:_, F:_MOVE F:4, F:8
$51318CONVERT UNSIGNED I:_, F:_CONVERT UNSIGNED I:4, F:8
$52318CONVERT SIGNED I:_, F:_CONVERT SIGNED I:4, F:8
$53318CONVERT UNSIGNED F:_, B:_CONVERT UNSIGNED F:4, B:8
$54318CONVERT SIGNED F:_, B:_CONVERT SIGNED F:4, B:8
$55318CONVERT UNSIGNED F:_, P:_CONVERT UNSIGNED F:4, P:8
$56318CONVERT SIGNED F:_, P:_CONVERT SIGNED F:4, P:8
$57318CONVERT UNSIGNED F:_, I:_CONVERT UNSIGNED F:4, I:8
$58318CONVERT SIGNED F:_, I:_CONVERT SIGNED F:4, I:8
$5C34LOAD F:_, [I:_]LOAD F:4, [I:8]
$B944LOAD F:_, [I:_ + {S_BYTE}]LOAD F:4, [I:8 + 123]
$E854LOAD F:_, [I:_ + {S_PAIR}]LOAD F:4, [I:8 + 12345]
$6633STORE [I:_], F:_STORE [I:4], F:8
$C343STORE [I:_ + {S_BYTE}], F:_STORE [I:4 + 123], F:8
$F253STORE [I:_ + {S_PAIR}], F:_STORE [I:4 + 12345], F:8
$FD52PUSH FLOAT {FLOAT}PUSH FLOAT 1.2345
$2F23PUSH F:_PUSH F:4
$3323POP F:_POP F:4
$3A23NEGATE F:_NEGATE F:4
$8E321ADD F:_, F:_ADD F:4, F:8
$94321SUBTRACT F:_, F:_SUBTRACT F:4, F:8
$9C315COMPARE F:_, F:_COMPARE F:4, F:8
$A3324MULTIPLY F:_, F:_MULTIPLY F:4, F:8
$A8363DIVIDE F:_, F:_DIVIDE F:4, F:8
$A934ROUND CEIL F:_, F:_ROUND CEIL F:4, F:8
$AA34ROUND FLOOR F:_, F:_ROUND FLOOR F:4, F:8
$AB34ROUND TRUNC F:_, F:_ROUND TRUNC F:4, F:8
$AC34ROUND NEAREST F:_, F:_ROUND NEAREST F:4, F:8

CPU flags

Similar to their INT counterparts, the POP, PUSH, MOVE, LOAD, and STORE instructions do not affect the CPU condition flags. The other instructions set the flags as follows:

Condition flagOutput
zero (ZF)If the result is zero or negative zero, this flag is 1; otherwise it is 0.
negative (NF)If the result is less than zero, this flag is 1; otherwise it is 0. IEEE negative zero is equal to positive zero, so they have the same meaning for this flag.
overflow (OF)If the result is in the NaN or infinity number classes, this flag is 1; otherwise it is 0.
carry (CF)This flag is always 0.

ROUND instruction

This instruction implements the most common IEEE 754 rounding rules:

  • ROUND CEIL performs directed rounding towards positive infinity (also known as rounding up or ceiling).
  • ROUND FLOOR performs directed rounding towards negative infinity (also known as rounding down or floor).
  • ROUND TRUNC performs directed rounding towards zero (also known as truncation).
  • ROUND NEAREST performs "round to nearest, ties to even". It rounds to the nearest integer; if the number falls midway, it is rounded to the nearest value with an even least significant digit.

Cosmetic opcodes

Some of these opcodes process a 32-bit value without interpreting its value, therefore the same effect could be achieved using INT registers:

OpcodeBytesCyclesExampleEquivalent example
$4733MOVE F:4, F:8MOVE I:4, I:8
$5C34LOAD F:4, [I:8]LOAD I:4, [I:8]
$B944LOAD F:4, [I:8 + 123]LOAD I:4, [I:8 + 123]
$E854LOAD F:4, [I:8 + 12345]LOAD I:4, [I:8 + 12345]
$6633STORE [I:4], F:8STORE [I:4], I:8
$C343STORE [I:4 + 123], F:8STORE [I:4 + 123], I:8
$F253STORE [I:4 + 12345], F:8STORE [I:4 + 12345], I:8
$FD52PUSH FLOAT 1.2345PUSH INT $3F9E_0419
$2F23PUSH F:4PUSH I:4
$3323POP F:4POP I:4

The "cosmetic" form is provided to make disassemblies easier to read.