Documentation for calc-pi-x86-64-asm
Command Input Output Description
+ Xreg, Yreg Xreg Addition Xreg = Yreg + Xreg
Rotate stack Zreg → Yreg
Rotate stack Treg → Zreg
Set 0.0 → Treg
- Xreg, Yreg Xreg Subtract Xreg = Yreg - Xreg
Rotate stack Zreg → Yreg
Rotate stack Treg → Zreg
Set 0.0 → Treg
* Xreg, Yreg Xreg Multiply Xreg = Yreg * Xreg
Rotate stack Zreg → Yreg
Rotate stack Treg → Zreg
Set 0.0 → Treg
/ Xreg, Yreg Xreg Divide Xreg = Yreg / Xreg
Rotate stack Zreg → Yreg
Rotate stack Treg → Zreg
Set 0.0 → Treg
The value of Xreg must be non-zero.
chs Xreg Xreg Change sign of number in Xreg by performing a
2's Compliment subraction from zero.
clrall Clear All
Sets 0.0 into Xreg, Yreg, Zreg, Treg
Sets 0.0 into all registers Reg0 to Reg7
clrreg Clear all Registers
Sets 0.0 into ALL the registers Reg0 to Reg7
clrstk Clear Stack
Sets 0.0 into Xreg, Yreg, Zreg, Treg
clrx Clear X Register
Sets 0.0 into Xreg
The stack is not rotated.
enter XReg Yreg RPN Enter command
Move Zreg → Treg
Move Yreg → Zreg
Copy Xreg → Yreg

This is included for compatibility with scientific pocket calculators. The "Enter" text command duplicates Xreg into Yreg. This is different from the keyboard [Enter] key used to terminate number input.
fix Set output number format to Fixed Point
Choices are: fix, int, sci
int Set output number format to Integer
Choices are: fix, int, sci
load <f> Read Xreg from file.
Get filname <f> from input line
File extension ".num" is appended to filename
Example: load myfile
Data read from file myfile.num
With path: load ~/numbers/mynumber
Registers rotated up like number input.
log
logoff
The command 'log' starts a terminal log session. The filenames are sequential as follows: out/out001.txt, out/out002.txt, out/out003.txt ... the folder 'out' must exist in the working directory. Logging is stopped with the 'logoff' command.
normal Display Xreg, Yreg, Zreg, and Treg after input.
Output abbreviated to 50 digits
Preview modes: quiet, xonly, normal, verbose
This can cause time delay for base 10 conversion
print
print f

.
. f
Print Xreg to console output without formatting. The base-10 conversion mode is set independently using commands: fix, int, or sci. The period character "." is synonymous to "print".

Adding "f" to print command will format the text output stream in groups of 10 digits, with 100 digits per line, in blocks of 1000 digits. Formatting is independent of the base-10 conversion mode set with: fix, int, or sci. Use "help print" to see more options.
quiet Do not print any registers after input.
Preview modes: quiet, xonly, normal, verbose
rcl <reg> XReg Recall value from Register Reg0 to Reg7
Move Zreg → Treg
Move Yreg → Zreg
Move Xreg → Yreg
Copy Register to Xreg
Valid input: 0,1,2,3,4,5,6,7
rdown Rotate stack down R↓ (circular rotation)
Move Yreg → Xreg
Move Zreg → Yreg
Move Treg → Zreg
(Circular) Move previous Xreg → Treg
recip Xreg Xreg Compute Xreg = 1/Xreg reciprocal value
rup Rotate stack up R↑ (circular rotation)
Move Zreg → Treg
Move Yreg → Zreg
Move Xreg → Yreg
(circuar) Move previous Treg → Xreg
save <f> Save Xreg to file.
Filname <f> from input line
File extension ".num" is appended to filename
Example: save myfile
With path: load ~/numbers/mynumber
Generated file will be myfile.num
sci Set number format to Scientific Notation
Choices are: fix, int, sci
sigfigs
sigfigs v
sigfigs <a>

sf
sf v
sf <a>
Show or set number of significant digits. The command "sf" is synonymous to "sigfigs" Adding "v" to sigfigs or sf will show accuracy verbose mode, showing bytes and words. Adding an integer argument to sigfigs or sf will set the variable size. Example: "sf 1000" will set accuracy to 1000 digits. Use "help sf" to get more options to set variable size.
stack Print abbreviated values of Xreg, Yreg, Zreg, Treg
sto <reg> XReg Store value from Xreg to Reg0 to Reg7
Valid input: 0,1,2,3,4,5,6,7
Stack is not rotated.
vars Print abbreviated values of Xreg, Yreg, Zreg, Treg
and registers Reg0 through Reg7
verbose Display Xreg, Yreg, Zreg, and Treg after input.
Also print Reg0 through Reg7
Output abbreviated to 50 digits
Preview modes: quiet, xonly, normal, verbose
This can cause time delay for base 10 conversion
xonly Display only Xreg after input.
Output abbreviated to 50 digits
Preview modes: quiet, xonly, normal, verbose
This can cause time delay for base 10 conversion
xy Exchange Xreg and Yreg
RPN registers

RPN calculators can be recognized because RPN calculators do not have an equals sign [=] button. In place of the equals sign key is a large [Enter] key. You can read about RPN on Wikipedia here This type of calculator will add 1 + 2 + 3 to obtain the sum 6 with the following keystrokes:

"1 Enter 2 Enter 3 + +"

Scientific calculators like the HP-11C or HP-15C have always been my favorite. Anyone who has used such a scientific calculator should feel right at home with this type of calculator. This program works with a 4 register stack, X, Y, Z, and T. Similar to a scientific calculator, there are 8 storage registers number 0 to 7. There is a simple demonstration of these registers at the start of this program's tutorial here.

Numeric Input

The program will accept floating point input. At the "Op Code:" prompt, enter a numeric text string. Use the keyboard [Enter] key to terminate the input. The input be converted to a binary floating point. White space is ignored within the number.

Example syntax:
0
0.0
123
+123
-123
123.456
12e45
-12.34e-4
12.34E+2322
-12.34 E +232

For example:

Op Code: 123
Op Code: 456
Op Code; +

XREG  +579.000000000000000000000000000000000000000000000000
YREG   0.0
ZREG   0.0
TREG   0.0
Printing Numbers

Printing involves 3 concepts: base-10 conversion, text formatting, and significant digits.

Base-10 conversion:

All numbers are stored binary floating point format. In order to view the numbers in human understandable output, it is necessary to convert the binary numbers (base-2) to recognizable (base-10) format. For example, the number "123.0" or "+1.23 E+2" would be stored as binary floating point as (mantissa) E (exponent) with values "7B00000000000000 E 0000000000000007". The base-10 conversion can be set to 3 modes: fix, int or sci. Each would print as follows:

hex  7B00000000000000 0000000000000000 0000000000000000 0000000000000000 E 0000000000000007

int  +123
fix  +123.0000000000000000000000000000000000000000000000000000000000
sci  +1.230000000000000000000000000000000000000000000000000000000000 E+2

Text formatting:

The process of the base-10 conversion produces a continuous stream of ascii characters. Unformatted text will "wrap" to the next line when the screen width of the console terminal is reached. It is very difficult to work with unformatted numbers. Formatting requires adding ascii space characters and end of line characters. Formatting is configured by adding modifier characters to the end of the "print" or "." commands. The one you would use most would be "f" to request that text be formatted in group of 10 digits, 100 digits per line, in blocks of 1000 digits.

print     +3.141592653589793238462643383279502884197169399375105820974944
print f   +3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944

.         +3.141592653589793238462643383279502884197169399375105820974944
. f       +3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944

Significant digits:

In the case of any repetitive calculation that runs in a loop, each operation in the loop may experience round off errors. Over many loops, these cumulative errors can add up. Additionally, the variables are allocated in 64 bit words. The intended number of decimal digits may not match up to an even number of 64 bit words. To avoid this problem, extra bytes (or 64 bit words) are added to each variable to absorb these precision errors.

To illustrate, take the example of dividing 1/3 to produce and endless text string of 3's looking like "0.3333...". However at some point the number may inherit various accuracy errors and look something like "0.33333328342". In this case 6 digits were accurate followed by 5 random digits. The sigfigs or sf command will set the intended accuracy variable size and number of base-10 digits to print. Extra 64 bit words are allocated, called "guard words". Adding "e" followed by an integer to the sigfigs or sf command will allow extended digits to be included in the "print" or "." commands. Extended digits beyond the specified accuracy are shown in parentheses.

Example:
"sf 100" will set accuracy to 100 digits.
"sf e 100" will tell the program to print 100 "extended" digits.

Let's do the this and divide 1/3, then print 100 digits and 100 extra digits, 200 total. You can see the last 33 digits are random. Although the requested accuracy is 100 digits, in fact this calculation of 1/3 has an internal calculation accuracy of about 167 digits.

+0.333333333333333333333333333333333333333333333333333333333333333333333333333333
3333333333333333333333 (333333333333333333333333333333333333333333333333333333333
3333333333545311991655965504580924155798725)

A normal calculation to 100 digits would print 1/3 to the specified accuracy.

+0.333333333333333333333333333333333333333333333333333333333333333333333333333333
3333333333333333333333

To calculate and print pi to 1000 digits in fixed notation with 10 extended digits and print in formatted output (note period command to print), you would do the following:

Op Code: fix
Op Code: sf 1000
Op Code: sf e 10
Op Code: c.pi
Op Code: . f
Capturing output to a file

To capture text output to a disk file, first create a folder called "out" in the current working directory. Next use the "log" and "logoff" commands to start and stop a logging session. The output text capture files will be automatically named out/out001.txt, out/out002.txt, out/out003.txt ...

Display intermediate results on the stack

Each time a numeric command is requested from the keyboard, the program has capability to optionally show the stack registers, Xreg, Yreg, Zreg, and Treg. There are 4 options, "quiet", "xonly", "normal", and "verbose". The default is normal printing the stack. Verbose includes registers 0 to 7.

In cases where the exponent value is very large or very small, the program may require an excessive amount of time to perform base-10 conversions. In this case "quiet" is recommended.

Command: quiet

(Elapsed time: 0 Seconds 00:00:00) Op Code: 1

(Elapsed time: 0 Seconds 00:00:00) Op Code:

Command: xonly

(Elapsed time: 0 Seconds 00:00:00) Op Code: 1

XREG  +1.00000000000000000000000000000000000000000000000000 E+0

(Elapsed time: 0 Seconds 00:00:00) Op Code:

Command: normal (Default)

XREG  +1.00000000000000000000000000000000000000000000000000 E+0
YREG   0.0
ZREG   0.0
TREG   0.0

(Elapsed time: 0 Seconds 00:00:00) Op Code:

Command: verbose

(Elapsed time: 0 Seconds 00:00:00) Op Code: 1

XREG  +1.00000000000000000000000000000000000000000000000000 E+0
YREG   0.0
ZREG   0.0
TREG   0.0
REG0   0.0
REG1   0.0
REG2   0.0
REG3   0.0
REG4   0.0
REG5   0.0
REG6   0.0
REG7   0.0

(Elapsed time: 0 Seconds 00:00:00) Op Code: