BigEd wrote:
Because many ARM instructions offer a free shift, you can consider the
technique of keeping 8-bit values left-aligned in their registers - this way, N and V work out much better.
I think you meant N and Z, not V? I was going to suggest something similar, but refrained because it doesn't support carry coming in from the LSB for addition/subtraction. There are a few solutions that pull in more cases, but they all have downsides:
- Do ops in the upper 8 bits: C, N, V, Z work, but not right-input carry (ADC/SBC/ROL) nor ROR/LSR's right-output carry.
- Do ops in the upper 8 bits with the lower 24 set: Right-input carry for ADC/SBC now work, but Z breaks.
- Do ops in the lower 8 bits, then shift left 24 bits: C, N, Z, right-input, right-output, & left-output carry all work, but V and left-input carry don't.
Across the space of ops, you'd have to find the best balance for the intermediate register storage, but probably handle the individual ops differently. I also admit that I don't know how ARM's carry bit interacts with the shifter, if at all, so that would affect how useful my "shift by 24 after operation to output carry" assumptions are.
You could also do something crazy like keep the accumulator as a 10-digit number to represent what's going on with carry on both ends. But I'm pretty sure you'd always lose V in the process.