I wanted to write a simple programmer's calculator program for quick use while programming/disassembling (look, disassembling is complicated and all five other monitors are already spoken for), but I didn't think there's an existing eZ80 bigint library, so I spent today writing one. It's got a full suite of already-optimized assembly routines:
Screen shot of test program:
n1 = 0x12345678901234567890123456789012
n2 = 0x11111111111111111111111111111111
n3 = 0x123456789ABCDEF0123456789ABCDEF0
n4 = 0x1DEADBEEF4C0FFEE
prod = 0xDEADBEEF times 0x41COFFEE
I'm also wondering about the API. The worst offender is that I've typed BigInt_t as just uint8_t instead of a proper struct or array. I did it that way so that I could do literals in C89, but I'd rather have a more type-safe stuct definition. The size of a BigInt is currently fixed at compile time, but I imagine that if people are interested in a proper library for use with the C SDK, it would be nice to have the size be a runtime option. The convention for this library is that every routine except multiply and divide overwrites one of its arguments with the output, which is slightly smaller and slightly faster; however, I'm wondering if people would prefer a three-argument system where the output is written somewhere else.
Feel free to send a PR with suggested code changes.
- set var to zero, one, or negative one (used for initializing temps in other routines);
- addition and subtraction;
- increment and decrement;
- get sign and negate;
- test for zero, non-zero, and compare;
- left-shift, right-shift, with optional bit to shift in;
- bit-wise and, or, not, xor, and nand;
- and get/set bit.
Screen shot of test program:
n1 = 0x12345678901234567890123456789012
n2 = 0x11111111111111111111111111111111
n3 = 0x123456789ABCDEF0123456789ABCDEF0
n4 = 0x1DEADBEEF4C0FFEE
prod = 0xDEADBEEF times 0x41COFFEE
I'm also wondering about the API. The worst offender is that I've typed BigInt_t as just uint8_t instead of a proper struct or array. I did it that way so that I could do literals in C89, but I'd rather have a more type-safe stuct definition. The size of a BigInt is currently fixed at compile time, but I imagine that if people are interested in a proper library for use with the C SDK, it would be nice to have the size be a runtime option. The convention for this library is that every routine except multiply and divide overwrites one of its arguments with the output, which is slightly smaller and slightly faster; however, I'm wondering if people would prefer a three-argument system where the output is written somewhere else.
Feel free to send a PR with suggested code changes.