<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 25 Aug 1994 01:36:16 +0100 (BST)
From   : clr1@...
Subject: Someone - debug my ADC and SBC... please?

I am none too good with maths (as some of you know!) and I am desparately 
trying to debug my ADC and SBC routines. However, each time I look at 
them I come up with a different answer! These ones (I think) work - but 
could someone *please* check them?

@... {test me for sign overflow!}  { Verified OK for flag use }
   test DL,1                        { carry set? }
   jz @ADC_NoCarry                  { carry is not set }
   stc                              { set it articifially }
   jmp @ADC_do_it
@...                       { no carry }
   clc
@...
   adc CL,BL                        { perform add (with carry set) }
   lahf                             { save Z, N }
   jo @ADC_setV                     { overflow }
   mov BH,AH                        { save flags }
   and BH,1                         { just get the carry }
   and DL,255-1                     { clear current carry flag }
   or DL,BH                         { set carry if it's set }
   {and DL,255-1                    { clear carry }
   and DL,255-64                    { clear overflow flag }
   ret
@...
   mov BH,AH                        { save flags }
   and BH,1                         { just get the carry }
   and DL,255-1                     { clear current carry flag }
   or DL,BH                         { set carry if it's set }
   {or DL,1                         { set carry }
   or DL,64                         { set overflow flag }
   ret


{ I really am not very sure about the effectiveness of SBC and ADC; perhaps
  post them to cs0081 to see what everyone thinks? }


@...                               { Verified OK for flag use }
   test DL,1                        { carry set? }
   jz @SBC_NoCarry                  { carry is not set }
   clc                              { clear it articifially }
   jmp @SBC_do_it
@...                       { no carry }
   stc
@...
   sbb CL,BL                        { perform subtract (with carry) }
   lahf                             { save Z, N }
   jo @SBC_setV                     { overflow }
   mov BH,AH                        { save flags }
   and BH,1                         { just get the carry }
   xor BH,1                         { invert it; it's the wrong way around }
   and DL,255-1                     { clear current carry flag }
   or DL,BH                         { set carry if it's set }
   {or DL,1                          { set C }
   and DL,255-64                    { clear overflow flag }
   ret
@...
   {and DL,255-1                     { clear C }
   mov BH,AH                        { save flags }
   and BH,1                         { just get the carry }
   xor BH,1                         { invert it; it's the wrong way around }
   and DL,255-1                     { clear current carry flag }
   or DL,BH                         { set carry if it's set }
   or DL,64                         { set overflow flag }
   ret


Thanks for wading through! Fingers crossed they're right...

+-------------------+-------------------------------------------------+
| /-- |_| /-- | (~  | "And the driving is like the driving of Jehu,   |
| \-- | | |   | _)  | the son of Nimshi, for he drives furiously."    |
+-------------------+-------------------- Second Book of Kings 9 v20 -+
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>