Multibyte Addition :
The Microchip PIC instruction set provides opcodes that will perform the addition or subtraction two 8-bit values but what if we need to add or subtract 16-, 24- or 32-bit values held in several bytes?
The following code illustrates how to perform 16-, 24- and 32-bit arithmetic on values held in multiple registers. The examples use a number of register areas with prefixes 'R', 'A' and 'B'. The input values to an arithmetic operation will either be in the 'R' and 'A' registers (for R += A and R -= A) or the 'A' and 'B' registers (for R = A + B and R = A - B). The result of the operation is always placed in the 'R' registers.
The number of 'R', 'A' and 'B' registers used depends on size of the values. A 16-bit operation will only use registers suffixed with a 0 or a 1 (e.g. R0 and R1), while a 24-bit operation will use 0, 1, 2 and a 32-bit operation will use 0, 1, 2 and 3. The bigger the suffix value, the more significant the byte it holds.
The all of the code assumes that A0-3, B0-3 and R0-3 are accessible simultaneously. This means that they must either be in the same bank of file registers or split between a single bank and the common shared (or access) file register area.
No comments:
Post a Comment