Category : Files from Magazines
Archive   : PCTJ0287.ZIP
Filename : BUSPERFX.ASM

 
Output of file : BUSPERFX.ASM contained in archive : PCTJ0287.ZIP
TITLE BUSPERFX - TIMER ROUTINES FOR PC PERFORMANCE TESTS

COMMENT " Routines to time execution of various operations.
Copyright (c) PC Tech Journal 1986
Written by Ted Mirecki, Oct. 1986.

Linkage conventions per Lattice C.
Limitation: test must not span midnight.
"
INCLUDE DOS.MAC ;LATTICE INTERFACE DEFININTIONS
;***************************************************************
; DATA SEGMENTS
;***************************************************************

BIOSDATA SEGMENT AT 40H
ORG 6CH ;DEFINE TIMER WORDS AT 40:6C
TIMERLO DW ?
TIMERHI DW ?
BIOSDATA ENDS

DSEG ;MACRO TO OPEN DATA SEG (DOS.MAC)
T1LO DW ? ;TIMER COUNT BEFORE CALIB
T1MID DW ?
T1HI DW ?
T2LO DW ? ;TIMER COUNT AFTER CALIB
T2MID DW ?
T2HI DW ?
NEWSEG DW ? ;SAVE ALLOCATED WORKSPACE
WORKDATA DB 10 DUP (0) ;SCRATCH AREA
ENDDS ;MACRO TO END DATA SEG (DOS.MAC)
;***************************************************************
; MACROS USED IN CODE SEGMENT
;***************************************************************

MARK MACRO TX
CALL TIMERGET ;;GET CURRENT TIMER VALUES
MOV TX&HI,AX ;;SAVE 3 WORDS OF TIMER
MOV TX&MID,BX
MOV TX&LO,CX
ENDM
PSEG ;MACRO TO START PROG SEG (IN DOS.MAC)

;***************************************************************
; TIMERSET: INITIALIZE TIMER FOR INTERVAL TIMING.
;
; Sets Timer 0 (the time-of-day counter) to mode 2, with a period
; of 0 (equivalent to 65536). This makes it a low-order
; extension of the BIOS timer words.
;***************************************************************
BEGIN TIMERSET

TIMER0 EQU 40H ;I/O PORT FOR TIMER 0
TIMERCTL EQU 43H ;I/O PORT FOR TIMER CONTROL
SETMODE2 EQU 00110100B ;VALUE FOR MODE 2, 2 BYTES, BINARY

MOV AL,SETMODE2 ;SEND CONTROL BYTE TO TIMER
OUT TIMERCTL,AL
XOR AL,AL ;SEND ZERO COUNTER VALUE (=65536)
NOP ;DELAY FOR PORT RECOVERY
OUT TIMER0,AL ;SET LO BYTE OF COUNT
NOP ;DELAY FOR RECOVERY
NOP
OUT TIMER0,AL ;SET HI BYTE OF COUNT
RET
TIMERSET ENDP
;***************************************************************
; TIMERGET: READ 3 TIMER WORDS INTO AX, BX, CX
;***************************************************************

TIMERGET PROC NEAR
ASSUME DS:BIOSDATA

LATCH EQU 0 ;COMMAND TO SAVE TIMER 0 COUNT

PUSH DS
MOV AX,BIOSDATA ;POINT TO TIMER WORDS IN BIOS
MOV DS,AX
MOV AL,LATCH ;PREPARE TO CAPTURE TIMER COUNT

CLI ;NO INTERRUPTS WHILE READING TIMER
OUT TIMERCTL,AL ;LATCH THE TIMER COUNT
MOV BX,TIMERLO ;GET TIMER VALUES FROM BIOS DATA
MOV CX,TIMERHI ;HI TIMER TEMPORARILY IN CX
IN AL,TIMER0 ;READ LOW ORDER BYTE OF TIMER COUNT
MOV AH,AL ;SAVE IT
NOP ;DELAY FOR RECOVERY
IN AL,TIMER0 ;GET HI ORDER BYTE OF COUNT
STI ;ALLOW INTERRUPTS AGAIN

XCHG AH,AL ;RESTORE CORRECT ORDER OF BYTES
NEG AX ;CONVERT TO UP-COUNT
XCHG AX,CX ;GET 3 WORDS IN PROPER ORDER
POP DS
RET
TIMERGET ENDP
;***************************************************************
; ELAPSED: CALCULATE ELAPSED TIME INTERVAL
;
; Input: T3 timer values in AX, BX, CX;
; previous values in T1 and T2 locations.
; Output: Elapsed time value, (T3-T2)-(T2-T1), as
; long int in AX:BX.
;***************************************************************

ASSUME DS:DGROUP
ELAPSED PROC NEAR
SUB CX,T2LO ;CALC (T3-T2)-(T2-T1)
SBB BX,T2MID
SBB AX,T2HI
SUB CX,T2LO
SBB BX,T2MID
SBB AX,T2HI
ADD CX,T1LO
ADC BX,T1MID
ADC AX,T1HI ;DIFFERENCE IN AX, BX, CX
MOV AX,BX ;RETURN LONG INT IN AX,BX
MOV BX,CX
RET
ELAPSED ENDP
;***************************************************************
; BUSTEST: TIME MEMORY ACCESS FOR INSTRUCTION FETCH
;***************************************************************

BEGIN BUSTEST ;MACRO TO BEGIN PROC (IN DOS.MAC)
PUSH BP
MOV BP,SP ;STANDARD C ENTRY SEQUENCE

PUSH DS
MOV AX,BIOSDATA
MOV DS,AX ;POINT TO BIOSDATA SEGMENT
ASSUME DS:BIOSDATA
MOV AX,TIMERLO
STAY: CMP AX,TIMERLO ;DID TIMER TICK OCCUR?
JE STAY ;IF NOT, WAIT UNTIL IT DOES
POP DS
ASSUME DS:DGROUP ;LATTICE DATA GROUP

MARK T1 ;GET INITIAL TIMER VALUES
;SET-UP CODE, IF ANY, GOES HERE
MARK T2 ;END CALIBRATION, START TEST

;------------------ CODE TO BE TIMED BEGINS HERE.

MOV AX,BX ;TWO-CYCLE, 2 BYTE INSTRUCTION
DB 24999 DUP (89H, 0D8H) ;PERFORM IT 25,000 TIMES

;------------------ END OF TIMED CODE

CALL TIMERGET ;GET ENDING TIME (T3) INTO REGS
CALL ELAPSED ;CALC ELAPSED TIME IN AX:BX
POP BP
RET
BUSTEST ENDP
;***************************************************************
; END OF TESTS
;***************************************************************
ENDPS ;MACRO TO CLOSE PROGRAM SEG (IN DOS.MAC)
END



  3 Responses to “Category : Files from Magazines
Archive   : PCTJ0287.ZIP
Filename : BUSPERFX.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/