Big Number - sjsoftware/centurion-cpu6 GitHub Wiki
Big Number instructions
These instructions operate on variable byte length values.
| Byte 1 | Byte 2 | Byte 3 | Byte 4 - x | Byte x + 1 - y |
|--------------|-------------------|------------------|------------|----------------|
| | | 7 6 5 4 | 3 2 1 0 | 7654 | 3 2 | 1 0 | | |
| 4 6 | len1 | len2 | S M N | Op1 (src) | Op2 (dest) |
- S = Instruction Selector (0-9 are legal)
- M = Extended Addressing mode for operand 1 (0-3)
- N = Extended Addressing mode for operand 2 (0-3)
- len1 = length of operand 1 in bytes - 1, 0 is operand length 1, 1 is operand length 2 etc.
- len2 = length of operand 2 in bytes - 1, as for operand 1.
There are 10 instructions.
| Selector | Opcode | Description |
|---|---|---|
| 0 | A | Adds two big numbers. Dest = Dest + Src |
| 1 | S | Subtracts two big numbers. Dest = Dest - Src |
| 2 | C | Set flags based on subtraction Dest - Src |
| 3 | ZAD | Assigns a big number. Dest = Src (0 + Src, Zero Add) |
| 4 | ZSU | Negates a big number. Dest = -Src (0 - Src, Zero Subtract) |
| 5 | M | Multiplies two big numbers (signed). Dest = Dest x Src. Zero results where one operand is negative are unreliable |
| 6 | D | Divides two big numbers (signed) using a non-restoring binary division algorithm. Dest = Dest / Src. Remainder is not stored |
| 7 | DRM | Divides two big numbers (signed). Dest = Dest / Src. Remainder is written to address pointed to by A. Link flag is set for zero remainder |
| 8 | CTB | Base string to Big number. Base can be from 2 to 17. Operand 1 is src, Operand 2 is destination. Base in length field of Operand 1 (field holds Base - 2). Operand 1 length is provided in AL |
| 9 | CFB | Big number to Base string. Base can be from 2 to 17. Operand 1 is destination, Operand 2 is source. Base is length field of Operand 1 (field holds Base - 2). Operand 1 length is provided in AL. BL provides padding byte. AW holds address of result following operation. Result is formatted, @ in destination will be replaced by result. # in destination is padding marker, result will be zero filled until marker, from marker on result will be filled with padding byte. Other bytes in destination are left as is. |
CTB and CFB Length Byte
| Byte 2 |
|-------------------|
| 7 6 5 4 | 3 2 1 0 |
| Base | len2 |
- Base holds the conversion base - 2. i.e., Base 2 is stored as zero, Base 17 (!) is stored as F
- len2 is the length of operand 2 in bytes, minus 1. For CTB, this is the destination. For CFB, this is the source
- The length of operand 1 is passed in AL, minus 1. For CTB, this is the source string. For CFB, this is the destination string.