64-bit arithmetic
64-bit values occupy sixteen nibbles. Results use a dedicated memory buffer rather than the register result convention.
Representation
Type |
Nibbles |
Byte order |
|---|---|---|
|
16 |
Low nibble first |
|
16 |
Low nibble first, two’s complement |
A 64-bit variable costs sixteen nibbles of RAM. The compiler also reserves a result buffer and temporary slots while a 64-bit expression is evaluated.
Helpers
lib/wide.nbl provides the runtime helpers. The loader adds the module when a
program uses 64-bit arithmetic.
Helper |
Operation |
|---|---|
|
Unsigned multiply |
|
Unsigned divide |
|
Unsigned modulo |
|
Signed multiply |
|
Signed divide |
|
Signed modulo |
|
Unsigned decimal output |
|
Signed decimal output |
|
Hex output |
|
Binary output |
The print helpers are in lib/wide.nbl so programs that do not use 64-bit
values do not link them.
Behavior
Division by zero returns 0.
Signed division truncates toward zero.
Signed modulo takes the dividend’s sign.
The most-negative value divided by
-1wraps to itself.
Limits
64-bit multiply and divide are iterative and use several temporary slots. Use
them only where the range is required. The print helpers can exceed the
five-entry hardware call stack for some formats; verify stack depth with
--stack.