Use backtick code blocks for syntax highlighting
This commit is contained in:
parent
8ed9dea394
commit
f658bfbb40
203 changed files with 26546 additions and 25801 deletions
72
04-02.md
72
04-02.md
|
|
@ -53,11 +53,15 @@ byte-sized accesses. That's why the official instruction timings
|
|||
indicate that for code running on an 8088 an additional 4 cycles are
|
||||
required for every word-sized access to a memory operand. For instance,
|
||||
|
||||
mov ax,word ptr [MemVar]
|
||||
```nasm
|
||||
mov ax,word ptr [MemVar]
|
||||
```
|
||||
|
||||
takes 4 cycles longer to read the word at address **MemVar** than
|
||||
|
||||
mov al,byte ptr [MemVar]
|
||||
```nasm
|
||||
mov al,byte ptr [MemVar]
|
||||
```
|
||||
|
||||
takes to read the byte at address **MemVar.** (Actually, the difference
|
||||
between the two isn't very likely to be exactly 4 cycles, for reasons
|
||||
|
|
@ -72,11 +76,15 @@ prior to adding to it, and one to write the result of the addition back
|
|||
to the destination operand—and thus incurs not one but two 4-cycle
|
||||
penalties. As a result
|
||||
|
||||
add word ptr [MemVar],ax
|
||||
```nasm
|
||||
add word ptr [MemVar],ax
|
||||
```
|
||||
|
||||
takes about 8 cycles longer to execute than:
|
||||
|
||||
add byte ptr [MemVar],al
|
||||
```nasm
|
||||
add byte ptr [MemVar],al
|
||||
```
|
||||
|
||||
String instructions can suffer from the 8-bit bus cycle-eater to a
|
||||
greater extent than other instructions. Believe it or not, a single
|
||||
|
|
@ -114,35 +122,39 @@ in all.
|
|||
|
||||
**LISTING 4.1 LST4-1.ASM**
|
||||
|
||||
; Measures the performance of a loop which uses a
|
||||
; byte-sized memory variable as the loop counter.
|
||||
;
|
||||
jmp Skip
|
||||
;
|
||||
Counter db 100
|
||||
;
|
||||
Skip:
|
||||
call ZTimerOn
|
||||
LoopTop:
|
||||
dec [Counter]
|
||||
jnz LoopTop
|
||||
call ZTimerOff
|
||||
```nasm
|
||||
; Measures the performance of a loop which uses a
|
||||
; byte-sized memory variable as the loop counter.
|
||||
;
|
||||
jmp Skip
|
||||
;
|
||||
Counter db 100
|
||||
;
|
||||
Skip:
|
||||
call ZTimerOn
|
||||
LoopTop:
|
||||
dec [Counter]
|
||||
jnz LoopTop
|
||||
call ZTimerOff
|
||||
```
|
||||
|
||||
**LISTING 4.2 LST4-2.ASM**
|
||||
|
||||
; Measures the performance of a loop which uses a
|
||||
; word-sized memory variable as the loop counter.
|
||||
;
|
||||
jmp Skip
|
||||
;
|
||||
Counter dw 100
|
||||
;
|
||||
Skip:
|
||||
call ZTimerOn
|
||||
LoopTop:
|
||||
dec [Counter]
|
||||
jnz LoopTop
|
||||
call ZTimerOff
|
||||
```nasm
|
||||
; Measures the performance of a loop which uses a
|
||||
; word-sized memory variable as the loop counter.
|
||||
;
|
||||
jmp Skip
|
||||
;
|
||||
Counter dw 100
|
||||
;
|
||||
Skip:
|
||||
call ZTimerOn
|
||||
LoopTop:
|
||||
dec [Counter]
|
||||
jnz LoopTop
|
||||
call ZTimerOff
|
||||
```
|
||||
|
||||
I'd like to make a brief aside concerning code optimization in the
|
||||
listings in this book. Throughout this book I've modeled the sample code
|
||||
|
|
|
|||
Loading…
Reference in a new issue