This is a multi-part message in MIME format. ------=_NextPart_000_0122_01C2CE27.A9431F30 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 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?". http://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" To: Sent: Tuesday, February 04, 2003 4:52 PM Subject: Re: [PIC]: DAW how it works (BCD) > 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. > > http://asp.microchip.com/webboard/wbpx.dll/~devtools > Search for DAW > > Thanks again > > Mike Jones > > ----- Original Message ----- > From: "Andre Abelian" > To: > Sent: Tuesday, February 04, 2003 2:46 PM > Subject: [PIC]: DAW how it works (BCD) > > > > 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 listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > -- 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 ------=_NextPart_000_0122_01C2CE27.A9431F30 Content-Type: text/plain; name="DAW Examples.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="DAW Examples.txt" (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 ------=_NextPart_000_0122_01C2CE27.A9431F30--