Searching \ for '[PIC]: DAW how it works (BCD)' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'DAW how it works (BCD)'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: DAW how it works (BCD)'
2003\02\04@175115 by Andre Abelian

picon face
Hi to all,

I did some test using DAW instruction on MPLAB ICE2000
and this is the result.

       Movlw           0x0F            ; w reg has d=15: B=00001111
       DAW                             ; do decimal adjustments
       Movwf           BCD_REG ; BCD_REG has d=21 b=00010101 C=0


Second digit (F)                05
First  digit (0)     + 01
Result               015        ; 0 means C=0: 1 is bits 4,5,6,7  and
                                                       5 is bits
0,1,2,3


Now lets deal with higher numbers

       Movlw           0xEF            ; w reg has d=239: b=11101111
       DAW                             ; do decimal adjustments
       Movwf           BCD_REG ; BCD_REG has d=85 h=55 b=10101010


Second digit (F)                15      ; decimal
First  digit (E)     + 14       ; decimal
Result               155        ; 1 means C=1: 5 is bis 4,5,6,7  and
                                                       5 is bits
0,1,2,3


Andre Abelian

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\04@183632 by Jon M (Mike) Jones

picon face
Thanks for setting that up and testing, it's appreciated.

I don't know how hard it is to set up but you might try the following;
DC= 1
C   = 1
W = 32
(This would be the result of adding 99 + 99)
Then execute the 'DAW
The result should be (according to Microchip for the 18F series)
DC= 1
C   = 0
W= 98

Using a 18F452, I arrived at the results (as above) that Microchip
said you should get.

I found a question nearly identical to mine in the Microchip
Developers conference and their answer was as above. I still
don't know why but I asked. Maybe I'll get a response in a day or
two.

asp.microchip.com/webboard/wbpx.dll/~devtools
Search for DAW

Thanks again

Mike Jones

{Original Message removed}

2003\02\04@185717 by Andre Abelian

picon face
Mike,

If Wreg = d'32' that is 0x20
After DAW every thing remains the same d'32' and C=0 DC=0
The only time DC will be 1 when goes over d'15' and
C will be 1 if your number goes over 99.

Andre Abelian



{Original Message removed}

2003\02\04@195151 by Andre Abelian

picon face
Mike,

99+99=198 in decimal
if Wreg=198
after DEW
your Wreg is 98  C=1 DC=0

Andre Abelian



-----Original Message-----

Thanks for setting that up and testing, it's appreciated.

I don't know how hard it is to set up but you might try the following;
DC= 1
C   = 1
W = 32
(This would be the result of adding 99 + 99)
Then execute the 'DAW
The result should be (according to Microchip for the 18F series)
DC= 1
C   = 0
W= 98

Using a 18F452, I arrived at the results (as above) that Microchip
said you should get.

I found a question nearly identical to mine in the Microchip
Developers conference and their answer was as above. I still
don't know why but I asked. Maybe I'll get a response in a day or
two.

asp.microchip.com/webboard/wbpx.dll/~devtools
Search for DAW

Thanks again

Mike Jones

----- Original Message -----
From: "Andre Abelian" <.....engelecKILLspamspam@spam@EARTHLINK.NET>
To: <PICLISTspamKILLspamMITVMA.MIT.EDU>
Sent: Tuesday, February 04, 2003 2:46 PM
Subject: [PIC]: DAW how it works (BCD)


{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

2003\02\04@201828 by Jon M (Mike) Jones

picon face
Andre,

My apologies, I should have been a little more clear. When I said
W=32 I was thinking, but not writing, packed BCD 32, or 0x32.
I'm not really sure how that should be written.

However, the status bits DC and C  should both
be set to '1' before the DAW in order to simulate the results
an addition (ADDWFC or similar) of two packed BCD
numbers, 99.+ 99 in this case.

BTW I heard from Microchip already, not much but they said
they will look into it. Not sure what that means but it's a start.

Mike Jones

----- Original Message -----
From: "Andre Abelian" <@spam@engelecKILLspamspamEARTHLINK.NET>
To: <KILLspamPICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Tuesday, February 04, 2003 3:59 PM
Subject: Re: [PIC]: DAW how it works (BCD)


{Quote hidden}

> {Original Message removed}

2003\02\07@005659 by Jon M (Mike) Jones

picon face
part 1 4939 bytes content-type:text/plain; (decoded 7bit)

Let me try this again. I probably wasn't clear enough in explaining
what I was really getting at.

This is probably nothing new to most but it may help some avoid
at least one pitfall.

What I finally learned is that, for example, if you are adding
two multi digit decimal numbers in packed BCD format (such
as 9990 + 9990) and are using DAW to adjust the
results after each 'add',  you need to save the
carry after each add and restore it after each DAW
(or at least before the next 'add').

If you don't, the final results may not be what
you expect. In re-reading the description of the
DAW opcode, it only says that the C bit is affected,
not how or why. Apparently the C bit is simply a
result of the additions that took place when
performing the adjust, not a result of the previous
addition (like ADDWFC) as you 'might' have liked
or expected.

In an attached file are a couple of tested examples
that, I hope, illustrate the above. BTW Example 1
was confirmed by Microchip in a response to a
question I found on their web site.

The original question was "Why is this Binary to BCD
Conversion"  macro not working correctly?".
www.piclist.org/techref/postbot.asp?by=time&id=piclist/2002/12/24/164
925a

I applied a rather brute force method of saving and restoring
the carry bit as per the above and it now works as expected.
Now I need to find a more elegant way to save and restore the
carry than with the cycle eating brute-force method I tested the
'fix' with.

Mike Jones

----- Original Message -----
From: "Andre Abelian" <RemoveMEengelecTakeThisOuTspamEARTHLINK.NET>
To: <spamBeGonePICLISTspamBeGonespamMITVMA.MIT.EDU>
Sent: Tuesday, February 04, 2003 4:52 PM
Subject: Re: [PIC]: DAW how it works (BCD)


{Quote hidden}

> {Original Message removed}
part 2 1363 bytes content-type:text/plain;
(decoded 7bit)


(In order for this to be readable you may need
to change to a fixed width font such as courier).


Example 1: Add two packed BCD numbers 99+99
                             (0x99 + 0x99)

OPCODE           Register   Value      DC  C
---------------  --------   ---------  --  -
                WREG       1001 1001
                FileX      1001 1001
                                       x  0
ADDWFC  FileX,W
                WREG       0011 0010   1  1
DAW
                WREG       1001 1000   1  0
                                          ^
                Note the carry -----------^


Example 2: Add two packed BCD numbers 70+70
                             (0x70 + 0x70)

OPCODE           Register   Value      DC  C
---------------  --------   ---------  --  -
                WREG       0111 0000
                FileX      0111 0000
                                       x  0
ADDWFC  FileX,W
                WREG       1110 0000   1  1
DAW
                WREG       0100 1000   0  1
                                          ^
                Note the carry -----------^

Notes:
This was tested on a 18F452.
FileX is an arbitrary register in Bank 0

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics




part 3 2 bytes
-

2003\02\07@073621 by Bob Ammerman

picon face
I am pretty sure you are going to have to 'or' the carry from the ADDWFC
with the one from the DAW.

You're second text case added 0x70 to 0x70 and then DAW'd

The ADDWFC should _NOT_ generate a carry (contrary to the information in
your attachment).

0x70 + 0x70 = 0xE0 with _NO_ carry.

Then the DAW should fix it up to:

0x40 with a carry.

You need that carry into the next byte.

What a stupid way to design the DAW instruction. It should have set carry as
needed, but never cleared it.

This really screws up the performance of my macro, that is for sure.

Here is the best I have come up with for saving and merging carry.

   ADDWFC    var,x        ; add two bytes
   RRCF          temp,f      ; remember the carry
   DAW                           ; adjust the value
   BTFSC        temp,7      ; was carrry set?
   SETC                           ; yes: set it again

Bob Ammerman
RAm Systems

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\07@123006 by Jon M (Mike) Jones

picon face
Bob,

You're obviously right about the second example and the need to 'or' the
carry bits. . My notes were right, I just can't seem to consistently copy
from
one medium to another correctly. I'm truly embarrassed. I think I'm going
to lower the noise level and just listen.from now on.

BTW Your 'fix' was one instruction less than mine. Thanks.

Mike Jones

{Original Message removed}

2003\02\07@160819 by Igor Pokorny

flavicon
face
A notice only

Considering long BCD numbers that was DAA or DAW developed for, the carry
never is set when you add two proper BCD numbers.
(99 + 99 = 198).

DAW or DAA in 8086 or other mnemotechnics used years ago, even in IBM 360
worked by the same way. If I remember well, COBOL, PL/1 and early versions
of Pascal used so called long BCD numbers that saves memory and were enough
long for accounting.
Who needs such arithmetics today...

Regards

Igor

{Original Message removed}

2003\02\07@163941 by Bob Ammerman

picon face
>Considering long BCD numbers that was DAA or DAW developed for, the carry
>never is set when you add two proper BCD numbers.
>(99 + 99 = 198).

Sorry, this is not true. When you are adding BCD 99 + BCD 99 you are really
adding
Hex 99 to Hex 99 or decimal 153 + decimal 153, which can obviously generate
a carry.

>DAW or DAA in 8086 or other mnemotechnics used years ago, even in IBM 360
>worked by the same way. If I remember well, COBOL, PL/1 and early versions
>of Pascal used so called long BCD numbers that saves memory and were enough
>long for accounting.
>Who needs such arithmetics today...

BCD is very convenient if entering an displaying decimal values is an
important part of the project.

>Regards
>Igor

Bob Ammerman
RAm Systems

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\08@140823 by Igor Pokorny

flavicon
face
>A notice only

>Considering long BCD numbers that was DAA or DAW developed for, the carry
never is set when you add two proper BCD numbers.
>(99 + 99 = 198).

I had to be blind or drunken not knowing about it :-). The previous sentence
isn't true of course.

Igor

{Original Message removed}

2003\02\10@122558 by Jon M (Mike) Jones

picon face
Bob,

Correct me if I am wrong, but I don't think this will work reliably;
>
> Here is the best I have come up with for saving and merging carry.
>
>     ADDWFC    var,x        ; add two bytes
>     RRCF          temp,f      ; remember the carry
>     DAW                           ; adjust the value
>     BTFSC        temp,7      ; was carrry set?
>     SETC                           ; yes: set it again
>

The RRCF will also shift a bit into the carry bit that may or may not
be what you want daw to make a decision on whether to add 6 to
the upper nibble or not. This initially looked good but when I tried it
I got some really strange results until I figured out what as going on.

The following is one instruction cycle longer but seems to work reliably.

    ADDWFC    var,x                ; add two bytes
    MOVFF       status, temp      ; remember the carry
    DAW                                    ; adjust the value
    BTFSC        temp,0               ; was carrry set?
    SETC                                    ; yes: set it again

It sure would have been nice if they had made Status Affected: None!

Mike Jones

> --
> http://www.piclist.com hint: The list server can filter out subtopics
> (like ads or off topics) for you. See http://www.piclist.com/#topics
>

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu>

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...