Alek988Alek
Alek988Alek

Reputation: 49

Packed BCD 4 digit addition (8086 assembler)

Im having trouble writing this code. Could someone give me the solution (I understand BCD numbers, etc, I just can't write code that works)?

It's supposed to add two packed BCD numbers (4 digits each; they are at addresses OP1 and OP2) and place the result in address RES.

Thanks in advance :)

Upvotes: 0

Views: 2369

Answers (2)

user555045
user555045

Reputation: 64904

Using daa (decimal adjust after addition), you can simply add them directly, without a round trip through binary integers.

Something like this (completely untested)

mov al, [OP1]
add al, [OP2]
daa
mov [RES], al
mov al, [OP1 + 1]
adc al, [OP2 + 1]
daa
mov [RES + 1], al

Upvotes: 4

MByD
MByD

Reputation: 137292

I will not give you a solution, but instead some guidance. You need to split your work into 5 simple stages:

  1. Read the BCD encoded numbers
  2. Decode them to integers in the memory
  3. Perform addition
  4. Encode the addition result back to BCD representation
  5. Store the result in RES

I think that each stage is relatively easy to implement and hope this will help you to solve it by yourself.

Upvotes: 2

Related Questions