Replace invalid characters with HTML entities
— with — ’ with ’ + with + × with x ç with ç “ with “ ” with ” ‘ with ‘ • with • – with - µ with µ † with † Fix C++ θ with θ Yen symbol instead of times Fix broken apos Bullet again E-circumflex
This commit is contained in:
parent
9e52de9586
commit
500e7f5654
353 changed files with 5091 additions and 5091 deletions
22
22-02.html
22
22-02.html
|
|
@ -40,7 +40,7 @@
|
|||
<!-- CODE //-->
|
||||
<PRE>
|
||||
ClearS proc near
|
||||
push bp ;save caller’s BP
|
||||
push bp ;save caller’s BP
|
||||
mov bp,sp ;point to stack frame
|
||||
cmp word ptr [bp].BufSeg,0 ;skip the fill if a null
|
||||
jne Start ; pointer is passed
|
||||
|
|
@ -57,19 +57,19 @@ Start: cld ;make STOSW count up
|
|||
mov cx,[bp].BufSize ;load CX with buffer size
|
||||
rep stosw ;fill the buffer
|
||||
Bye:
|
||||
pop bp ;restore caller’s BP
|
||||
pop bp ;restore caller’s BP
|
||||
ret EndMrk-RetAddr-2 ;return, clearing the parms from the stack
|
||||
ClearS endp
|
||||
</PRE>
|
||||
<!-- END CODE //-->
|
||||
<P>(The <B>OnStack</B> structure definition doesn’t change in any of our examples, so I’m not going clutter up this chapter by reproducing it for each new version of <B>ClearS</B>.)</P>
|
||||
<P>Okay, loading ES and DI directly saves another four bytes. We’ve squeezed a total of 6 bytes—about 11 percent—out of <B>ClearS</B>. What next?</P>
|
||||
<P>(The <B>OnStack</B> structure definition doesn’t change in any of our examples, so I’m not going clutter up this chapter by reproducing it for each new version of <B>ClearS</B>.)</P>
|
||||
<P>Okay, loading ES and DI directly saves another four bytes. We’ve squeezed a total of 6 bytes—about 11 percent—out of <B>ClearS</B>. What next?</P>
|
||||
<P>Well, <B>LES</B> would serve better than two <B>MOV</B> instructions for loading ES and DI as shown in Listing 22.3.</P>
|
||||
<P><B>LISTING 22.3 L22-3.ASM</B></P>
|
||||
<!-- CODE //-->
|
||||
<PRE>
|
||||
ClearS proc near
|
||||
push bp ;save caller’s BP
|
||||
push bp ;save caller’s BP
|
||||
mov bp,sp ;point to stack frame
|
||||
cmp word ptr [bp].BufSeg,0 ;skip the fill if a null
|
||||
jne Start ; pointer is passed
|
||||
|
|
@ -86,19 +86,19 @@ Start: cld ;make STOSW count up
|
|||
mov cx,[bp].BufSize ;load CX with buffer size
|
||||
rep stosw ;fill the buffer
|
||||
Bye:
|
||||
pop bp ;restore caller’s BP
|
||||
pop bp ;restore caller’s BP
|
||||
ret EndMrk-RetAddr-2 ;return, clearing the parms from the stack
|
||||
ClearS endp
|
||||
</PRE>
|
||||
<!-- END CODE //-->
|
||||
<P>That’s good for another three bytes. We’re down to 43 bytes, and counting.
|
||||
<P>That’s good for another three bytes. We’re down to 43 bytes, and counting.
|
||||
</P>
|
||||
<P>We can save 3 more bytes by clearing the low and high bytes of AX and BX, respectively, by using <B>SUB <I>reg8,reg8</I></B> rather than ANDing 16-bit values as shown in Listing 22.4.</P>
|
||||
<P><B>LISTING 22.4 L22-4.ASM</B></P>
|
||||
<!-- CODE //-->
|
||||
<PRE>
|
||||
ClearS proc near
|
||||
push bp ;save caller’s BP
|
||||
push bp ;save caller’s BP
|
||||
mov bp,sp ;point to stack frame
|
||||
cmp word ptr [bp].BufSeg,0 ;skip the fill if a null
|
||||
jne Start ; pointer is passed
|
||||
|
|
@ -115,15 +115,15 @@ Start: cld ;make STOSW count up
|
|||
mov cx,[bp].BufSize ;load CX with buffer size
|
||||
rep stosw ;fill the buffer
|
||||
Bye:
|
||||
pop bp ;restore caller’s BP
|
||||
pop bp ;restore caller’s BP
|
||||
ret EndMrk-RetAddr-2 ;return, clearing the parms from the stack
|
||||
ClearS endp
|
||||
</PRE>
|
||||
<!-- END CODE //-->
|
||||
<P>Now we’re down to 40 bytes—more than 20 percent smaller than the original code. That’s pretty much it for simple instruction optimizations. Now let’s look for instruction optimizations.
|
||||
<P>Now we’re down to 40 bytes—more than 20 percent smaller than the original code. That’s pretty much it for simple instruction optimizations. Now let’s look for instruction optimizations.
|
||||
</P>
|
||||
<P>It seems strange to load a word value into AX and then throw away AL. Likewise, it seems strange to load a word value into BX and then throw away BH. However, those steps are necessary because the two modified word values are ORed into a single character/attribute word value that is then used to fill the target buffer.</P>
|
||||
<P>Let’s step back and see what this code really <I>does</I>, though. All it does in the end is load one byte addressed relative to BP into AH and another byte addressed relative to BP into AL. Heck, we can just do that directly! Presto—we’ve saved another 6 bytes, and turned two word-sized memory accesses into byte-sized memory accesses as well. Listing 22.5 shows the new code.</P><P><BR></P>
|
||||
<P>Let’s step back and see what this code really <I>does</I>, though. All it does in the end is load one byte addressed relative to BP into AH and another byte addressed relative to BP into AL. Heck, we can just do that directly! Presto—we’ve saved another 6 bytes, and turned two word-sized memory accesses into byte-sized memory accesses as well. Listing 22.5 shows the new code.</P><P><BR></P>
|
||||
<CENTER>
|
||||
<TABLE BORDER>
|
||||
<TR>
|
||||
|
|
|
|||
Loading…
Reference in a new issue