I'm developing my own virtual 4-bit ALU. I'd like to create calculator (+, -, *, /, %, only integers, maybe more bits). My target is to understand it thoroughly, not to build an efficient device.
Currently I've implemented 4 functions:
- Adding.
- Adding one.
- Positive to negative.
- Subtracting.
In all functions, the 5th bit of a result is ignored. I would like to tell the ALU whether the result should be signed or not. What is the best way to do that?
My ideas:
- Using 3 more functions (1st, 2nd and 3rd with unsigned integer as a result).
- Using one more input byte (to tell whether to ignore the 5th bit or not).
Which one of those are better? Do you know even better method?