Change bold code snippets to inline code blocks
This commit is contained in:
parent
f658bfbb40
commit
3c76d884ef
185 changed files with 1772 additions and 1772 deletions
32
09-01.md
32
09-01.md
|
|
@ -78,14 +78,14 @@ feedback.
|
|||
|
||||
#### Another Look at LEA {#Heading3}
|
||||
|
||||
Several people have pointed out that while **LEA** is great for
|
||||
Several people have pointed out that while `LEA` is great for
|
||||
performing certain additions (see Chapter 6), it isn't a perfect
|
||||
replacement for **ADD**. What's the difference? **LEA**, an addressing
|
||||
replacement for `ADD`. What's the difference? `LEA`, an addressing
|
||||
instruction by trade, doesn't affect the flags, while the arithmetic
|
||||
**ADD** instruction most certainly does. This is no problem when
|
||||
`ADD` instruction most certainly does. This is no problem when
|
||||
performing additions that involve only quantities that fit in one
|
||||
machine word (32 bits in 386 protected mode, 16 bits otherwise), but it
|
||||
renders **LEA** useless for multiword operations, which use the Carry
|
||||
renders `LEA` useless for multiword operations, which use the Carry
|
||||
flag to tie together partial results. For example, these instructions
|
||||
|
||||
```nasm
|
||||
|
|
@ -100,11 +100,11 @@ LEA EAX,[EAX+EBX]
|
|||
ADC EDX,ECX
|
||||
```
|
||||
|
||||
because **LEA** doesn't affect the Carry flag.
|
||||
because `LEA` doesn't affect the Carry flag.
|
||||
|
||||
The no-carry characteristic of **LEA** becomes a distinct advantage when
|
||||
The no-carry characteristic of `LEA` becomes a distinct advantage when
|
||||
performing pointer arithmetic, however. For instance, the following code
|
||||
uses **LEA** to advance the pointers while adding one 128-bit memory
|
||||
uses `LEA` to advance the pointers while adding one 128-bit memory
|
||||
variable to another such variable:
|
||||
|
||||
```nasm
|
||||
|
|
@ -120,15 +120,15 @@ ADDLOOP:
|
|||
LOOP ADDLOOP
|
||||
```
|
||||
|
||||
(Yes, I could use **LODSD** instead of **MOV/LEA**; I'm just
|
||||
illustrating a point here. Besides, **LODS** is only 1 cycle faster than
|
||||
**MOV/LEA** on the 386, and is actually more than twice as slow on the
|
||||
486.) If we used **ADD** rather than **LEA** to advance the pointers,
|
||||
the carry from one **ADC** to the next would have to be preserved with
|
||||
either **PUSHF/POPF** or **LAHF/SAHF**. (Alternatively, we could use
|
||||
multiple **INC**s, since **INC** doesn't affect the Carry flag.)
|
||||
(Yes, I could use `LODSD` instead of `MOV/LEA`; I'm just
|
||||
illustrating a point here. Besides, `LODS` is only 1 cycle faster than
|
||||
`MOV/LEA` on the 386, and is actually more than twice as slow on the
|
||||
486.) If we used `ADD` rather than `LEA` to advance the pointers,
|
||||
the carry from one `ADC` to the next would have to be preserved with
|
||||
either `PUSHF/POPF` or `LAHF/SAHF`. (Alternatively, we could use
|
||||
multiple `INC`s, since `INC` doesn't affect the Carry flag.)
|
||||
|
||||
In short, **LEA** is indeed different from **ADD**. Sometimes it's
|
||||
In short, `LEA` is indeed different from `ADD`. Sometimes it's
|
||||
better. Sometimes not; that's the nature of the various instruction
|
||||
substitutions and optimizations that will occur to you over time.
|
||||
There's no such thing as "best" instructions on the x86; it all depends
|
||||
|
|
@ -180,7 +180,7 @@ ADC CX,CX ;CX=1 if copy length was odd,
|
|||
REP MOVSB ;copy any odd byte
|
||||
```
|
||||
|
||||
(**ADC CX,CX** can be replaced with **RCL CX,1**; which is faster
|
||||
(`ADC CX,CX` can be replaced with `RCL CX,1`; which is faster
|
||||
depends on the processor type.) It might be hard to believe that the
|
||||
above is faster than this:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue