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>
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. This may<BR>
be one. Maybe Jim will time the various solutions posted, and<BR>
mention which he chose.<BR>
<BR>
The effort behind my entry was to have no jumps and no =
extra<BR>
memory access (immediate data, variables, or PUSH/POP). My 8088 =
is<BR>
dead, so I have not programed for it for quite some time. But =
for<BR>
my 80186 machine, those two rules have sped up some programs.<BR>
<BR>
Anyway, here is an example of using SALC.<BR>
<BR>
Regards,<BR>
<BR>
Steve N.<BR>
<BR>
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - =
-<BR>
SALC =
MACRO ; Set =
AL to Carry (not for NEC V20).<BR>
=
DB 0D6H ; One byte =
instead of the two byte SBB reg,reg.<BR>
ENDM<BR>
<BR>
CLAMP: &=
nbsp; ; Setup<BR>
XOR =
DH,DH ; Convert unsigned byte to word.<BR>
=
CBW &nbs=
p; ; Convert signed byte to word.<BR>
MOV =
BL,AL ; Save for unsigned byte calc.<BR>
<BR>
&=
nbsp; ; =
Signed word add:<BR>
ADD =
AX,DX<BR>
SAR =
AH,1 ; \ Make mask for zero clamp.<BR>
NOT =
AH ; /<BR>
<BR>
&=
nbsp; ; =
Unsigned byte add:<BR>
ADD =
BL,DL ; (Could be DL,BL if result in DL wanted.)<BR>
=
SALC ; =
Make mask for 0FFH clamp.<BR>
<BR>
=
OR BL,AL ; Clamp high.<BR>
AND =
BL,AH ; Clamp low.<BR>
<BR>
RET<BR>
<BR>
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - =
-<BR>
</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C8A3B7.B3C5784C--


|