debjitbis08 / sim8085

Online 8085 simulator

Home Page:https://www.sim8085.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decimal adjustment (DAA) result error

baikunth2a opened this issue · comments

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.

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

@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

@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.

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

@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.

@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...