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
126
03-05.md
126
03-05.md
|
|
@ -82,43 +82,45 @@ and should contain calls to **ZTimerOn** and **ZTimerOff** .
|
|||
|
||||
**LISTING 3.2 PZTEST.ASM**
|
||||
|
||||
; Program to measure performance of code that takes less than
|
||||
; 54 ms to execute. (PZTEST.ASM)
|
||||
;
|
||||
; Link with PZTIMER.ASM (Listing 3.1). PZTEST.BAT (Listing 3.4)
|
||||
; can be used to assemble and link both files. Code to be
|
||||
; measured must be in the file TESTCODE; Listing 3.3 shows
|
||||
; a sample TESTCODE file.
|
||||
;
|
||||
; By Michael Abrash
|
||||
;
|
||||
mystack segment para stack ‘STACK'
|
||||
db 512 dup(?)
|
||||
mystack ends
|
||||
;
|
||||
Code segment para public ‘CODE'
|
||||
assume cs:Code, ds:Code
|
||||
extrnZTimerOn:near, ZTimerOff:near, ZTimerReport:near
|
||||
Start proc near
|
||||
push cs
|
||||
pop ds ; set DS to point to the code segment,
|
||||
; so data as well as code can easily
|
||||
; be included in TESTCODE
|
||||
;
|
||||
include TESTCODE ;code to be measured, including
|
||||
; calls to ZTimerOn and ZTimerOff
|
||||
;
|
||||
; Display the results.
|
||||
;
|
||||
call ZTimerReport
|
||||
;
|
||||
; Terminate the program.
|
||||
;
|
||||
mov ah,4ch
|
||||
int 21h
|
||||
Start endp
|
||||
Code ends
|
||||
end Start
|
||||
```nasm
|
||||
; Program to measure performance of code that takes less than
|
||||
; 54 ms to execute. (PZTEST.ASM)
|
||||
;
|
||||
; Link with PZTIMER.ASM (Listing 3.1). PZTEST.BAT (Listing 3.4)
|
||||
; can be used to assemble and link both files. Code to be
|
||||
; measured must be in the file TESTCODE; Listing 3.3 shows
|
||||
; a sample TESTCODE file.
|
||||
;
|
||||
; By Michael Abrash
|
||||
;
|
||||
mystack segment para stack ‘STACK'
|
||||
db 512 dup(?)
|
||||
mystack ends
|
||||
;
|
||||
Code segment para public ‘CODE'
|
||||
assume cs:Code, ds:Code
|
||||
extrnZTimerOn:near, ZTimerOff:near, ZTimerReport:near
|
||||
Start proc near
|
||||
push cs
|
||||
pop ds ; set DS to point to the code segment,
|
||||
; so data as well as code can easily
|
||||
; be included in TESTCODE
|
||||
;
|
||||
include TESTCODE ;code to be measured, including
|
||||
; calls to ZTimerOn and ZTimerOff
|
||||
;
|
||||
; Display the results.
|
||||
;
|
||||
call ZTimerReport
|
||||
;
|
||||
; Terminate the program.
|
||||
;
|
||||
mov ah,4ch
|
||||
int 21h
|
||||
Start endp
|
||||
Code ends
|
||||
end Start
|
||||
```
|
||||
|
||||
Listing 3.3 shows some sample code to be timed. This listing measures
|
||||
the time required to execute 1,000 loads of AL from the memory variable
|
||||
|
|
@ -130,30 +132,32 @@ after the code in Listing 3.3 has been run.
|
|||
|
||||
**LISTING 3.3 LST3-3.ASM**
|
||||
|
||||
; Test file;
|
||||
; Measures the performance of 1,000 loads of AL from
|
||||
; memory. (Use by renaming to TESTCODE, which is
|
||||
; included by PZTEST.ASM (Listing 3.2). PZTIME.BAT
|
||||
; (Listing 3.4) does this, along with all assembly
|
||||
; and linking.)
|
||||
;
|
||||
jmp Skip ;jump around defined data
|
||||
;
|
||||
MemVar db ?
|
||||
;
|
||||
Skip:
|
||||
;
|
||||
; Start timing.
|
||||
;
|
||||
call ZTimerOn
|
||||
;
|
||||
rept 1000
|
||||
mov al,[MemVar]
|
||||
endm
|
||||
;
|
||||
; Stop timing.
|
||||
;
|
||||
call ZTimerOff
|
||||
```nasm
|
||||
; Test file;
|
||||
; Measures the performance of 1,000 loads of AL from
|
||||
; memory. (Use by renaming to TESTCODE, which is
|
||||
; included by PZTEST.ASM (Listing 3.2). PZTIME.BAT
|
||||
; (Listing 3.4) does this, along with all assembly
|
||||
; and linking.)
|
||||
;
|
||||
jmp Skip ;jump around defined data
|
||||
;
|
||||
MemVar db ?
|
||||
;
|
||||
Skip:
|
||||
;
|
||||
; Start timing.
|
||||
;
|
||||
call ZTimerOn
|
||||
;
|
||||
rept 1000
|
||||
mov al,[MemVar]
|
||||
endm
|
||||
;
|
||||
; Stop timing.
|
||||
;
|
||||
call ZTimerOff
|
||||
```
|
||||
|
||||
It's worth noting that Listing 3.3 begins by jumping around the memory
|
||||
variable **MemVar**. This approach lets us avoid reproducing Listing 3.2
|
||||
|
|
|
|||
Loading…
Reference in a new issue