Question

A subroutine cal led AAD16 written in M68HC11 assembly language is shown below: It has an error! Determine what the calling
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

.

Add a comment
Know the answer?
Add Answer to:
A subroutine cal led 'AAD16' written in M68HC11 assembly language is shown below: It has an error! Determin...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT