Reputation: 49
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
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
Reputation: 137292
I will not give you a solution, but instead some guidance. You need to split your work into 5 simple stages:
I think that each stage is relatively easy to implement and hope this will help you to solve it by yourself.
Upvotes: 2