Searching \ for '[PIC]: Problem with "DAW" instruction in MPLAB SIM' 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/languages.htm?key=mplab
Search entire site for: 'Problem with "DAW" instruction in MPLAB SIM'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Problem with "DAW" instruction in MPLAB SIM'
2002\12\03@181342 by Jan-Erik Soderholm

face picon face
Hi.
I'm running a short test program in MPLAB SIM.
The problem is the "Decimal Adjust W", the DAW instruction.
Processor is 18F252.
MPLAB version is 6.10.0.0.

Most of the times DAW does what it should, but with some values
(well, at least *one* value, havn't tested all values) it gives the
wrong result.

My case :

Have 0x96 in W             (BCD value)
Have 0x64 in a GPR         (BCD value)

Add W and GPR leaving FA in W (which is 160 decimal which is OK.)

Now executing DAW, it should first add 0x06 to the bits 3:0
and leave it as 0

Then it should add 0x06 to bits 7:4 and add one for the "overflow"
from bits 3:0 and leave 6 in bits 7:4 and set the C flag. The C flag is the
"hundreds" part of the BCD value, of course, and can be added
to the next higher BCD byte.


Now, MPLAB SIM ends up with 0x00 in W and C cleared, which is,
as far as I understand, far from right.

I'v checked Microchip site for any errata on MPLAB, but
havn't found any.

Anyone seen this ?

Best Regards
Jan-Erik Svderholm
S:t Anna Data
Sweden

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\12\03@182215 by Jan-Erik Soderholm

face picon face
Hi again.
Please forget for the time beeing my former post :-)

Something isn't right with my BCD calculations...

As someone might have noticed, 0xFA isn't 160 decimal,
it's 250 decimal...

Sorry...

Jan-Erik Svderholm
S:t Anna Data

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\12\03@200751 by Jan-Erik Soderholm

face picon face
Hi again.
Now I have some better facts about the DAW instruction in MPLAB SIM.

I'm using this short program to test it :

 movlw   0x97     ; First BCD value
 addlw   0x61     ; Add with second BCD value
 daw              ; Decimal adjust W

Here are the results for some  values :

First    Second    W before     W after  carry
value    value     DAW          DAW      flag

97       61        F8           58       1
97       62        F9           59       1
97       63        FA           00       1
97       64        FB           01       1
97       65        FC           02       1
97       66        FD           03       1
97       67        FE           04       1
97       68        FF           05       1
97       69        00           66       0
97       70        07           67       0
97       71        08           68       0


Now, the result after DAW should of course
continue from 59 to 60,61,62,63,64,65 and to 66.
And the carry flag should still be set in the
three last lines (to signal the "hundreds" character).

Same result in both V5 and V6 of MPLAB, b.t.w

I'v not tested on real hardware, I'll maybe do that
tomorrow...

Jan-Erik Svderholm
S:t Anna Data
Sweden

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\12\04@093109 by Jan-Erik Soderholm

face picon face
Hi again.
Now I'v run a short test on a "real" 18F252 and
the hardware does this right. The values 00-05 in the
table below from MPLAB SIM, becomes 60-65 in the
hardware. I'v not tested the full BCD range, but have no
reason to think that it shouldn't work for any BCD value.

My point on the C flag for the last three lines below was
wrong, since the carry is set in the ADD operation before
the DAW and should be taken care of then. There is no
carry from the DAW instruction as such in these cases.

Anyway, I'm glad to see that the silicon is OK :-)

Now, back to the 10-bit bin ADC value to 4 figure
BCD value conversion routine...

Jan-Erik.


Jan-Erik Soderholm wrote:
>
...
{Quote hidden}

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


2002\12\04@111310 by Jan-Erik Soderholm

face picon face
Well, the DAW instruction is not the only reason
to select the 18F series for this particular project.
As you know, there are other features in the 18F
series also.

And why use a particular chip, if not using it's features ??
And there will only be one or two DAW instructions in
a subroutine anyway, so it *will* be possible to replace
it with something else.

And, a "Decimal Adjust" or "Decimal Add" instruction have
been there in most other architectures I'v seen, such as
the 68xx series. The PICmicro midrange series is more of
an exception in this case.

And about Drew, did you experiensed similar differences
between the "real thing" and the "simulator" :-) :-) :-)

Jan-Erik.


Bill wrote :

{Quote hidden}

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


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