Hi,
There's a list of primitive operations that we're all used to. It's only about 20 operations:
- copy/assignment
and
or
xor
not
add
subtract
negate
multiply
divide
modulo
shift left
shift right
push
pop
call
return
jump/goto
conditional branch
These primitive operations are combined to do more complex operations. For example "if(x < y)" would be a subtraction and a branch.
In the same way, most of the primitive operations can done by other primitive operations. For example, "not" can be done with "xor", "negate" can be done with subtraction, multiplication can be done by repeated "shift and add", division (and modulo) can be done by repeated "shift and subtract", jump/goto can be done with copy/assignment (copy value into instruction pointer). This gives a "more minimal" list of operations like this:
- copy/assignment
and
or
xor
add
subtract
shift left
shift right
push
pop
call
return
conditional branch
Now; call and return are mostly the same as pushing and popping (e.g. push instruction pointer; pop instruction pointer). Pushing and popping can be done by using copy/assignment and addition or subtraction (copy something to stack top, then subtract the size from the stack pointer). Addition can be done with subtraction (e.g. "x = y + z" is the same as "x = y - (0 - z)". Shifting left can be done with addition (e.g. "x << 1" is the same as "x + x"). Shifting right can be done by shifting left with wrap around (e.g. "shr al,3" is the same as "rol al,8-3; and al,0x1F"). This gives us an "even more minimal" list:
- copy/assignment
and
or
xor
subtract
conditional branch
Copy/assignment can be done with xor (e.g. "x = y" is the same as "x = x ^ 0; x = x ^ y"). If you have a look at
De Morgan's laws you'll see that AND and OR can be done with XOR. For 2's complement, XOR can be done with "subtract then add 1". This gives us an "even more minimal" list:
- subtract
conditional branch
This list can't be reduced further; but it's only 2 operations, and it's all you need to do everything.
Of course you'd need to add addressing modes on top of this (minimum would probably be "register, immediate operand, value at address in register and value at immediate address" - e.g. "mov eax,eax", "mov eax,0x1234", "mov eax,[eax]" and "mov eax,[0x1234]"). You'd also want at least 3 registers (instruction pointer, stack pointer and accumulator).
However; getting such a minimal computer to do anything useful will be a nightmare - it'd make more sense to make it slightly more powerful. Basically; you'd want to grab the "low hanging fruit" - include things (like a true copy/assignment operator or an OR operator) that are relatively easy to include but make it less painful (and faster).
Finally, redstone circuits are "awkward at best", and if you really don't feel like doing it to begin with then even the simplest possible ALU is likely to be more work than you're willing to undertake.
Cheers,
Brendan