A 256-bit Calculator

hippy

Ex-Staff (retired)
A 16-bit to 256-bit integer calculator for the 18M2.

Uses Download Serial In and Out for control and display. Supports decimal, hex and binary number entry,. Operations supported are clear, addition, subtraction, multiplication, division, modulus, and, or, exclusive-or, inversion, negation, unsigned and signed result display. Up to 78 decimal digit accuracy at 256-bits.

The calculator itself uses reverse polish notation (RPN) for entry but can be modified to act like a more traditional entry system. Results only displayed when "=" pressed as it can take a while to convert a binary number to a decimal text display. Could be adapted to use a keypad and LCD; 16 char LCD for 48-bit, 20 for 64-bit, 40 for 128-bit. Ultimately it's more for demonstrating algorithm use and capability rather than a practical application. There's no underflow or overflow handling, simply truncates and wraps round.

Instructions for use in the code but no comments on the various parts of the algorithm. Uses bPtr to create byte arrays for the numbers being manipulated. Uses binary maths rather than BCD. Some of the code for the calculator is convoluted to save code space; it Gosubs more times than Returns which is okay for a real PICAXE but will cause issues if simulating. Stack overflow is okay for a real PICAXE as long as there's no subsequent stack underflow.

To find the largest number supported use ...

> #
> 1-
> =
 

Attachments

Top