In "A New Kind of Science" Stephen Wolfram states that a computer can be built with only two commands:
Increment x
Decrement x, jump when x = 0
I spent some time thinking about this.
Imagine a hypothetical machine with three registers AX, BX, CX . Provide it with a register DX which serves only as the output buffer for any imaginary output device. Also provide it with a fourth register ZX which always equals zero.
Assumeing that dec can jump to a poistion specified by, say CX then I was able to derive the four basic operations of mathematics:
Add:
Subtract:
Multiply:
Divide:
I can't claim these are elegant algorthims.
Can anyone send me tighter code?
Defination:
inc a
dec a , b where b contains the address to jump to if a proves empty. I am also assumeing that the opcode functions as:
{
if a = 0 then goto b else
a = a - 1
}
So if a contains 1, then 1 will be subtracted, and a jump not executed.
I have no idea why I assumed this behavior. Changeing dec a,b to the function
{
a=a-1
if a = 0 then goto b
}
will naturally derive different behavior.
Example multiply:
It is my nature to combine obsessions.
The IMISet provides a simple framework for the archetecture of my Marble Calculater.
See Physical Counter Computing