In article
<9c1c6a51-9572-4ffb-9546-b94987c1720f@[EMAIL PROTECTED]
>
spamtrap@[EMAIL PROTECTED]
"Jim Leonard " writes:
> On Apr 15, 12:11 am, pete <spamt...@[EMAIL PROTECTED]
> wrote:
> > Just to be absolutely clear about the problem (and without any
> > attempt at optimizing the code), can you confirm that the below
> > is what you're after?
> >
> > (unsigned sample in DL, signed "update" in AL)
> >
> > sub dh, dh ;DH = 0
> > cbw ;sign-extend AL to AX
> > add dx, ax ;signed addition
> > Now:
> > if DH == 0, nothing to do: ans in DL
> > if DH == FF, -ve overflow so clamp to 0: set DL = 0
> > if DH == 1, +ve overflow so clamp to FF: set DL = FF
> >
> > Is that correct?
>
> Yes, that's exactly correct. My beginner's attempt at applying the
> clamping has been done with JMPs, which are really costly in an inner
> loop (especially on my lowly 808x) and I feel that I'm missing
> something obvious.
>
> Was Terje's solution:
>
> add dl,al ; Carry set if it overflows!
> sbb al,al ; AL = 0xff if overflow
> or dl,al ; Turns any overflow into 0xff
>
> ...the right one? I see overflow handling but not underflow...
Well, I'd guess that Terje has more expertise in his little
finger that I in my entire body :-) but below is the best I can
come up with -- still a jmp in there though...
; unsigned sample in DL, signed "update" in AL
sub dh, dh
cbw
add dx, ax
or dh, dh
jz done
; either DH == FF (-ve overflow) or DH == 1 (+ve overflow)
sar dh, 1 ;now DH is 0 or FF, but the wrong way round
not dh ;invert it
mov dl, dh
done:
Perhaps (certainly!) someone can improve on that?
Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."


|