Abacus Computer
Abacus Computer is an abacus language.
The instructions are in memory.
Instruction
The one instruction is ADD A <- B.
A is a pointer to a number.
B is too.
Pointers
- 0 is mapped to the IP.
- Most others are just pointers to numbers.
- The max is mapped to the input.
- Usually "The max" is -1.
The Use of Abacus For Serious Computation
This section of this document aims to properly describe the capabilities of the Abacus Computer. To do this various concepts must first be covered.
Registers
Consider that when a program is loaded, nothing of the machines state can be labelled foreknowledge outside the instructions which lay within memory. To circumvent this we will propose the following registers, whose exact addresses are not entirely relevant to this discussion. They are as so:
- R0 -- contains zero
- R1 -- contains one
- RN -- contains negative one
- RS -- scratch register, should be restored to zero for ease of use
Booleans
A boolean for the case of Abacus Computer programs are simply a value which prior to a specific section of a procedure is guaranteed to be either in the false state (0) or the true state (1). This assumption proves vital for future endeavors.
If Statements
One may emulate a sort of if condition by simply adding to IP. We do this by first adding to our condition (i.e R0) itself some number of times (the number of times will determine the size of the if body), and then add it to IP. If it were false (as R0 is) we will simply continue execution into the code which follows, otherwise we shall add to the current IP 2^n (provided our condition is boolean) where n is the number of times we add our condition to itself. This essentially provides an if statement where the body is the number of instructions 2^n - 1 as before described where condition to entry is the condition being false.
The NOT Operation
The not operation is simple, take some boolean A and return its opposite. So that false becomes true and true becomes false. This, in Abacus is a rather lengthy process.
To begin, we check if A is false (we use the symbol A in code to refer to the address which A references).
ADD A <- A ADD A <- A ADD IP <- A
Then within our 3 instruction if statement we set A to one and RS to one (and follow with a NOP):
ADD A <- R1 ADD RS <- R1 ADD IP <- R0
Consider both A and RS are zero when entering this if statement. Following this we check if RS is false, and allow for a blocksize of seven:
ADD RS <- RS ADD RS <- RS ADD RS <- RS ADD IP <- RS
And in said if statement (remember, blocks are encountered when the value is false and not true) we set A to false and RS to 8 (so that whether or not A was originally false, RS will be 8).
ADD A <- RN ADD A <- RN
(note that A is now two)
ADD RS <- A ADD A <- RN ADD A <- RN ADD RS <- RS ADD RS <- RS
Then we set RS to zero by subtracting one eight times:
ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN
In total we get:
NOT A: ADD A <- A ADD A <- A ADD IP <- A ADD A <- R1 ADD RS <- R1 ADD IP <- R0 ADD RS <- RS ADD RS <- RS ADD RS <- RS ADD IP <- RS ADD A <- RN ADD A <- RN ADD RS <- A ADD A <- RN ADD A <- RN ADD RS <- RS ADD RS <- RS ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN ADD RS <- RN
Note that the values for R0, R1, RS and RN all need to be initialized and replaced in the code, as well as the address for A before any inversion may occur.