Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decimal adjustment (DAA) result error #18

Open
baikunth2a opened this issue Sep 28, 2020 · 7 comments
Open

Decimal adjustment (DAA) result error #18

baikunth2a opened this issue Sep 28, 2020 · 7 comments
Assignees

Comments

@baikunth2a
Copy link

baikunth2a commented Sep 28, 2020

It adds 06 to any numbers (i.e. although the number is less than 0xA) to adjust decimal using DAA after once DAA executed for number greater than 0x9.

@debjitbis08 debjitbis08 self-assigned this Oct 23, 2020
@debjitbis08
Copy link
Owner

@baikunth2a Can you share an example that is failing? The output you are observering and the expected one will be good to know.

@baikunth2a
Copy link
Author

baikunth2a commented Oct 23, 2020

@debjitbis08 Thanks for responding. Please observe the result of following program.
MVI A, 0AH
DAA
MVI A, 01H
DAA
HLT
Expected output A=01
Output observed A=07

@debjitbis08
Copy link
Owner

@baikunth2a This is happening because the AC flag is being set by the first DAA instruction. You would need to handle the flag value from the first DAA execution.

From the documentation,

DAA operates as follows:

  1. If the least significant four bits of the accumulator have a value greater than nine, or if the auxiliary
    carry flag is ON, DAA adds six to the accumulator.
  2. If the most significant four bits of the accumulator have a value greater than nine, or if the carry
    flag is ON, DAA adds six to the most significant four bits of the accumulator.

Hope this helps.

@abhishekUpmanyu
Copy link

abhishekUpmanyu commented Nov 3, 2020

Hi, I'm facing a similar issue with DAA. Here is my code to convert hex to bcd:

;

jmp start

;code
start: LDA 2050H
MOV C, A
MVI D, 00H
MVI A, 00H

loop: ADI 01H
DAA
JNC skip
INR D

skip: DCR C
JNZ loop
MOV L, A
MOV H, D
SHLD 2060H
hlt

When I insert FF at 2050, the expected output is 55 at 2060 and 02 at 2061; instead I'm getting 13 at 2060 and 0B at 2061. I cross checked my code on these websites:
https://www.tutorialspoint.com/8085-program-to-convert-hex-to-bcd
https://www.zseries.in/embedded%20lab/8085%20programs/hex%20to%20bcd%20conversion.php#.X6Efq3xR201

@shres58tha
Copy link

shres58tha commented Nov 3, 2020 via email

@jarp0l
Copy link

jarp0l commented Feb 27, 2021

@abhishekUpmanyu that's because the AC flag was set by DCR C, and 06/60 was being added to the accumulator after DAA since it takes AC flag into account.

Just load 02H in C and see the result. The expected result is 02H, but due to the DCR C instruction the result becomes 08H (02H + 06H) after DAA. So, you'll have to handle the AC flag yourself.
---
Just found that this is the problem with sim8085 itself.

@Vaibhav974
Copy link

@jarp0l After DCR C, ADI 01H will be there, so Flags should again get adjusted (Reset) properly before getting up to DAA. So yes this is an error with sim8085 itself...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants