I am not sure whether this is the right place to ask this question, but since it involves programming and code, hopefully this is the right place.
I have tried to post on Programmers and Computer Science SE, but they redirected me to this site.
The question is about how can I write a register machine code/program that computes the Fibonacci number. The syntax of the code is actually really simple.
(Below are just for reference only, sorry for the long post)
(For more explanation see the book on Formal Logic: Its Scope And Limits by Richard Carl Jeffrey)
According to Wikipedia a register machine is a generic class of abstract machines used in a manner similar to a Turing machine. A (processor) register is a small amount of storage available as part of a CPU or other digital processor.
We can simplify the problem by modelling the registers as empty buckets, and we can let marbles or rocks to be put into the register ("bucket"). The rule is to add or remove marbles from the bucket to perform computations.
The rules are:
1. A register machine uses of a finite number of buckets, and an unending supply of marbles.
2. Each bucket can be individually identified. The marbles need not be distinguishable.
3. A register machine program is a finite set of instructions:
- To add marble to a bucket (and then to go on to the next instruction).
- Or to take a marble away from a bucket (and to go on to one next
instruction if you can, or another one, if you can’t).
4. The program can be written in a flowchart or in a list of instructions.
Here is an example of a register machine program that performs addition.
Let A, B, C be buckets.
1. (-B; 2,4) means take away one marble from bucket B, go to instruction 2 if can, or 4 if cannot
2. (+A; 3) means add one marble to bucket A, then go to instruction 3
3. (+C; 1) means add one marble to bucket C, then go to instruction 1
4. (-C; 5