Pitacalc has its own section under the Projects at coobird.net!
Additional updates may or may not be posted on this blog.
Pitacalc has its own section under the Projects at coobird.net!
Additional updates may or may not be posted on this blog.
As mentioned in the previous post, Pitacalc is able to adjust the number of registers the calculator uses. This register bank resizing feature can be performed by using the rrb instruction.
As one can see above, using the reg command, there are ten registers by default. By typing in rrb 5 to perform a register resize, the subsequent reg command shows there are five registers. The rrb 12 and the following reg shows 12 registers. It is possible have anywhere from 1 to 100 registers with Pitacalc.
More features have been added since the last post. The current build, 309, contains new features such as color mode for the console and output in HTML format.
Pitacalc is not a particularly useful tool that has many uses, but it does demonstrate how a computer performs calculations at the low level. Using Pitacalc is similar to programming a computer to do calculations in assembly language. Although actual computers don’t work exactly like Pitacalc, having to enter instructions to perform calculations are similar.
There are certain aspects that regular calculators do not have that Pitacalc does. For example, Pitacalc has multiple registers which can be used to store values. These values can be set by using an appropriately named set instruction.
By typing specifying the register when performing the set instruction, one can set a value of the register. For example, to set the register r0 to the value 10, type
set r0 10 and press enter. As can be seen on the right, the line after the set instruction is a 0. This zero is the value stored in the accumilator. After executing any instruction, the value stored in the accumilator is returned. This is unaffected by the setting of register r0, hence the accumilator stays zero.
To check that register r0 was set to 10, we can use the reg instruction to show all the registers and their stored values. We can see that r0 is indeed set to 10. Another way to check the value of a specific register, just type in the name of the register. Here, typing in r0 gives us the value 10.
Pitacalc also allows renaming of registers. Any practical reasons? Perhaps the following image may illustrate one use:
Here, the registers which had the default name of r0 through r6 were renamed to words. In this aspect, the registers work a little bit like variables in computer programming.
Renaming a register is performed by the ren instruction. By typing the register name to change followed by a new name, a register can be renamed. For example, in the above example, register r6 was renamed to Everything. The instruction executed to perform the rename was ren r6 Everything.
Are ten registers not enough? No need to worry. Unlike a real world calculator, it’s possible to increase the number of registers with Pitacalc, up to 100. (Even this is an artificial limit that can be changed with minor changes in the program.) We’ll get into resizing the register bank next time.
Pitacalc is a command line interface calculator program. It’s works like a regular calculator by performing arithmetic operations and having an accumilator that keeps the running total. It also has several registers that can be used to temporarily store values.
For those who are interested, the calculator is a Win32 console application, so it should run on Windows 95 and higher. Maybe even NT 4; not that I’ve tried.
Arithmetic operations are performed by typing in instructions. For example, to set the accumilator to 100, one would type in
set 100. To add 200 to that value, one would type in add 200. The result of 300 shows up on the line following the add 200 line.
Although the example only shows adding one value to the accumilator, it is possible to add more than one value at a time to the accumilator. For example, by typing sub 100 200, the result of 0 will be returned.
Basically I was writing this calculator as practice programming in C. After programming in Java fairly exclusively for the past year or so, I thought it was time to brush up on some good ol’ C. Having to juggle around pointers between functions and calling malloc at every corner was loads of fun. (Please note the sarcasm in the previous sentence.)
Just to add useless features, the program accepts “scripts” of instructions to execute. Conversely, the output of the program can be dumped into an external file. I can’t think of any real use for this feature. Pitacalc has many features that really don’t have any real purpose.
Over the next few posts, I will introduce the great features (yes, that’s an overstatement) of Pitacalc. The current version 0.0.1 build 257. I’ll be adding more features (yes!) so the current version in the future will probably not be build 257.