Deduped images

This commit is contained in:
James Gregory 2013-12-30 12:25:34 +11:00
commit 9e52de9586
233 changed files with 128 additions and 128 deletions

View file

@ -48,7 +48,7 @@ mov al,BaseTable[ecx+edx*4]
<P>Any register may serve as the base register component of an address. Any register except ESP may also serve as the index register, which can be scaled by 1, 2, 4, or 8. (Scaling is very handy for performing lookups in arrays and tables.) The same register may serve as both base and index register, except for ESP, which can only be the base. Incidentally, it makes sense that ESP can&#146;t be scaled; ESP presumably always points to a valid stack, and I can&#146;t think of any reason you&#146;d want to use the stack pointer times 2, 4, or 8 in an address. ESP is, by its nature, a base rather than index pointer.</P>
<P>That&#146;s all there is to the functionality of 32-bit addressing; it&#146;s very simple, much simpler than 16-bit addressing, with its sharply limited memory addressing register combinations. The costs of 32-bit addressing are a bit more subtle. The only performance cost (apart from the aforementioned 1-cycle penalty for using 32-bit addressing in real mode) is a 1-cycle penalty imposed for using an index register. In this context, you use an index register when you use a register that&#146;s scaled, or when you use the sum of two registers to point to memory. <B>MOV BL,[EBX*2]</B> uses an index register and takes an extra cycle, as does <B>MOV CL,[EAX&#43;EDX]; MOV CL,[EAX&#43;100H]</B> is not indexed, however.</P>
<P>The other cost of 32-bit addressing is in instruction size. Old-style 16-bit addressing usually (except in a few special cases) uses one extra byte, which Intel calls the Mod-R/M byte, which is placed immediately after each instruction&#146;s opcode to describe the memory addressing mode, plus 1 or 2 optional bytes of addressing displacement&#151;that is, a constant value to add into the address. In many cases, 32-bit addressing continues to use the Mod-R/M byte, albeit with a different interpretation; in these cases, 32-bit addressing is no larger than 16-bit addressing, except when a 32-bit displacement is involved. For example, <B>MOV AL, [EBX]</B> is a 2-byte instruction; <B>MOV AL, [EBX&#43;10H]</B> is a 3-byte instruction; and <B>MOV AL, [EBX&#43;10000H]</B> is a 6-byte instruction.</P>
<TABLE WIDTH="100%"><TD ALIGN="LEFT" VALIGN="TOP" WIDTH="5%"><IMG SRC="images/13-03i.jpg"><TD ALIGN="LEFT" VALIGN="TOP" WIDTH="95%"><SMALL><I>Note that 1 and 4-byte displacements, but not 2-byte displacements, are supported for 32-bit addressing. Code size can be greatly improved by keeping stack frame variables within 128 bytes of EBP, and variables in pointed-to structures within 127 bytes of the start of the structure, so that displacements can be 1 rather than 4 bytes.</I></SMALL>
<TABLE WIDTH="100%"><TD ALIGN="LEFT" VALIGN="TOP" WIDTH="5%"><IMG SRC="images/i.jpg"><TD ALIGN="LEFT" VALIGN="TOP" WIDTH="95%"><SMALL><I>Note that 1 and 4-byte displacements, but not 2-byte displacements, are supported for 32-bit addressing. Code size can be greatly improved by keeping stack frame variables within 128 bytes of EBP, and variables in pointed-to structures within 127 bytes of the start of the structure, so that displacements can be 1 rather than 4 bytes.</I></SMALL>
</TABLE>
<P>However, because 32-bit addressing supports many more addressing combinations than 16-bit addressing, the Mod-R/M byte can&#146;t describe all the combinations. Therefore, whenever an index register (as described above) is involved, a second byte, the SIB byte, follows the Mod-R/M byte to provide additional address information. Consequently, whenever you use a scaled memory addressing register or use the sum of two registers to point to memory, you automatically add 1 cycle and 1 byte to that instruction. This is not to say that you shouldn&#146;t use index registers when they&#146;re needed, but if you find yourself using them inside key loops, you should see if it&#146;s possible to move the index calculation outside the loop as, for example, in a loop like this:
</P>