|
> Now I'm not sure how I should handle the overflow. Initially I had this: > 1. add number to register > 2. if register > 255, set to 255 and set the Carry Flag.
What you're describing is saturation: When a value overflows/underflows and is "clipped" to the maximum/minimum representable number. Saturated arithmetic is only present on some specialized hardware and instruction sets (MMX and other SIMD ISAs have support for it, for example.)
Normal arithmetic, as you discovered, is more useful and it also happens that when implementing ALUs in hardware, it is the natural way things occur (bits carried out of the register are simply lost -- or an extra bit is used to calculate status flags.)
|