Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly x86 > Re: Any more g...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 4626 of 4646
Post > Topic >>

Re: Any more graceful way to saturate adds?

by "Novosad, Stephan R." <spamtrap@[EMAIL PROTECTED] > Apr 21, 2008 at 06:57 AM

This is a multi-part message in MIME format.

------_=_NextPart_001_01C8A3B7.B3C5784C
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,

   Given the 8088/8086 target, and looking at the code posted,
I realized that an undocumented instruction could be used.
Ever since I heard of these instructions that were not mentioned
by Intel, I have been trying to find a use for them.  This may
be one.  Maybe Jim will time the various solutions posted, and
mention which he chose.

   The effort behind my entry was to have no jumps and no extra
memory access (immediate data, variables, or PUSH/POP).  My 8088 is
dead, so I have not programed for it for quite some time.  But for
my 80186 machine, those two rules have sped up some programs.

   Anyway, here is an example of using SALC.

Regards,

Steve N.

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SALC    MACRO           ; Set AL to Carry (not for NEC V20).
        DB      0D6H    ; One byte instead of the two byte SBB reg,reg.
        ENDM

CLAMP:                  ; Setup
        XOR     DH,DH   ; Convert unsigned byte to word.
        CBW             ; Convert signed byte to word.
        MOV     BL,AL   ; Save for unsigned byte calc.

                        ; Signed word add:
        ADD     AX,DX
        SAR     AH,1    ; \ Make mask for zero clamp.
        NOT     AH      ; /

                        ; Unsigned byte add:
        ADD     BL,DL   ; (Could be DL,BL if result in DL wanted.)
        SALC            ; Make mask for 0FFH clamp.

        OR      BL,AL   ; Clamp high.
        AND     BL,AH   ; Clamp low.

        RET

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

------_=_NextPart_001_01C8A3B7.B3C5784C
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.5.7653.19">
<TITLE>Re:  Any more graceful way to saturate adds?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=3D2>Hello,<BR>
<BR>
&nbsp;&nbsp; Given the 8088/8086 target, and looking at the code =
posted,<BR>
I realized that an undocumented instruction could be used.<BR>
Ever since I heard of these instructions that were not mentioned<BR>
by Intel, I have been trying to find a use for them.&nbsp; This may<BR>
be one.&nbsp; Maybe Jim will time the various solutions posted, and<BR>
mention which he chose.<BR>
<BR>
&nbsp;&nbsp; The effort behind my entry was to have no jumps and no =
extra<BR>
memory access (immediate data, variables, or PUSH/POP).&nbsp; My 8088 =
is<BR>
dead, so I have not programed for it for quite some time.&nbsp; But =
for<BR>
my 80186 machine, those two rules have sped up some programs.<BR>
<BR>
&nbsp;&nbsp; Anyway, here is an example of using SALC.<BR>
<BR>
Regards,<BR>
<BR>
Steve N.<BR>
<BR>
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - =
-<BR>
SALC&nbsp;&nbsp;&nbsp; =
MACRO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Set =
AL to Carry (not for NEC V20).<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
DB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0D6H&nbsp;&nbsp;&nbsp; ; One byte =
instead of the two byte SBB reg,reg.<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ENDM<BR>
<BR>
CLAMP:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Setup<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XOR&nbsp;&nbsp;&nbsp;&nbsp; =
DH,DH&nbsp;&nbsp; ; Convert unsigned byte to word.<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
CBW&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; ; Convert signed byte to word.<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MOV&nbsp;&nbsp;&nbsp;&nbsp; =
BL,AL&nbsp;&nbsp; ; Save for unsigned byte calc.<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; =
Signed word add:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ADD&nbsp;&nbsp;&nbsp;&nbsp; =
AX,DX<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SAR&nbsp;&nbsp;&nbsp;&nbsp; =
AH,1&nbsp;&nbsp;&nbsp; ; \ Make mask for zero clamp.<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NOT&nbsp;&nbsp;&nbsp;&nbsp; =
AH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; /<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; =
Unsigned byte add:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ADD&nbsp;&nbsp;&nbsp;&nbsp; =
BL,DL&nbsp;&nbsp; ; (Could be DL,BL if result in DL wanted.)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
SALC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; =
Make mask for 0FFH clamp.<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
OR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BL,AL&nbsp;&nbsp; ; Clamp high.<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp;&nbsp;&nbsp;&nbsp; =
BL,AH&nbsp;&nbsp; ; Clamp low.<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RET<BR>
<BR>
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - =
-<BR>
</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C8A3B7.B3C5784C--




 1 Posts in Topic:
Re: Any more graceful way to saturate adds?
"Novosad, Stephan R.  2008-04-21 06:57:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 10:58:56 CDT 2008.