Keep DAA! (was Re: 8086 bugs)

Dave Dunfield dave04a at
Sat Dec 10 18:20:18 CST 2005

> On 12/10/2005 at 12:09 PM Chuck Guzis wrote:
> >Code-cruncher quiz:  Could this be done in 8088 code without DAA or a jump
> >or a reference to a table in memory using only a single 8-bit register?
> What?  No takers?  
> I'll post my solution tomorrow if no one beats me to it.  Uses only AL (or
> A) register, no jumps, no tables and will work on x80 and x86.

After looking at what I posted in my previous response, I realized that I
could do the adjustments in single instructions by alternating ACI and
SBI instructions - took a little bit of head scratching to work through the
carries and come up with the right numbers, however this little sequence
will do it in only 8 instructions (plus the ANI 15 which isn't really part of
the algorithm if you need it):

    ANI  $0F

    ADI  $F6
    ACI  $0A
    SBI  $09
    SBI  $F5
    ACI  $F6
    ACI  $0A
    SBI  $09
    SBI  $C5

I don't think you can get any fewer instructions using this algorithm,
because you need to adjust the alphanumerics by an offset of 7, and
you need one extra instruction to set the inital carry flag boundary,
which makes 8 in total.

There will be an equivalent sequence beginning with a SUI 10
and reversing the operations all the way down.


dave04a (at)    Dave Dunfield
dunfield (dot)  Firmware development services & tools:
com             Collector of vintage computing equipment:

More information about the cctech mailing list