coobird.net icon

projects.coobird.net

projects.coobird.net - Pitacalc

Pitacalc - Part 2: Fun with registers

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.

Pitacalc - Setting registers 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 accumulator. After executing any instruction, the value stored in the accumulator is returned. This is unaffected by the setting of register r0, hence the accumulator 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:

Pitacalc - 42

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.

< Previous (Pitacalc Part 1)
Next (Pitacalc Part 3) >
Back to Pitacalc index