My problem is that I don't know how to handle the addition when it gets out of the 8-Bit range.
My program runs with small Hex numbers like #02h + #05h but not with higher numbers like #0A9H + #0B5H.
My problem is that I don't know how to handle the addition when it gets out of the 8-Bit range.
My program runs with small Hex numbers like #02h + #05h but not with higher numbers like #0A9H + #0B5H.
For 2 numbers, there's an asm trick: the carry flag holds the 9th bit of the ADD result, and we can right shift that 9-bit value with rotate-right through carry. 8051's RRC instruction does that.
ADD A, R0
RRC
Without that, see questions like How can I safely average two unsigned ints in C++? and Explanation of the safe average of two numbers
For more than 2 numbers, do extended-precision (using add-with-carry) to keep a wider sum.