Answer:
This program is trying to add two 16-bit numbers. The error is that when higher-order bytes of the 16-bit numbers (stored in locations NUM1H and NUM2H) are being added then the carry that might have result ed from addition of lower-order byte is not taken into account. In other words the addition of higher order bytes should be done using Add-with-carry (ADCA) instruction and not ADDA instruction.
So the code should be
............
CLRB ; Clear accumulator B
LDAA NUM1L
ADDA NUM2L ; Add the lower order bytes of the two numbers
STAA RESL ; Store the lower-order byte of result in the location RESL
LDAA NUM1H
ADCA NUM2H ; This adds (with carry) the higher order byte of the input numbers
BVS OVRFLW; Branch to program location OVRFLW in case overflow flag is set
STAA RESH ; Store the higher-order byte of result in the location RESH
.............
RTS
OVRFLW: LDAB #FF ; Put FF hex in accumulator B to indicate that overflow has occured
Also the calling program needs to fill the four memory locations (NUM1L, NUM1H, NUM2L and NUM2H) with the lower and higher order bytes of input numbers. For example
if number1 = 1234 Hex, and
number2 = ABCD Hex then
NUM1L should contain 34 Hex
NUM1H should contain 12 Hex
NUM2L should contain CD Hex and
NUM2H should contain AB Hex
Also to avoid any confusion, the calling program should initialize RESL and RESH (the location that would contain the result eventually) to 0.
Hope this helps.
.
A subroutine cal led 'AAD16' written in M68HC11 assembly language is shown below: It has an error! Determin...