Processor: AMD ( Semipron 2800+ )? 2.00 Ghz
OS: MS-Dos
First Question:
Does the rdtsc instruction count cycles like the cycles given in
Apendix D of Art of Asemmbly? If not, how can if find the aprox. time
of on tick. Is very accurate? (meaning could a program that i'm trying to time stop the counter ?)
Second Question:
I'm makeing a program that takes 3 files, 1st is startup code, 2nd is code to be timed, 3rd is cleanup code. Then load them in the mem after CS+codesize or SS which ever is greater. Is this mem that i'm using ok?
I've read in A of A that in MS-Dos all the mem after you program is reserved for you use. is that correct?
This is the code i am using the find the mem to load the files into.
<code>
mov ax, ss
mov bx, cs
cmp ax, bx
ja .usess
mov bx, endofcode-startcode
shr bx, 4
add ax, bx
.usess:
inc ax
cmp ax, 0a000h
jae outofmem
</code>
the file is loaded at GS:00. ( GS is initalize to SS+1 or (CS+codesize)+1 whichever is greater )
then this code calculates the size of the file and determines where to put the next one.
<code>
; bx = filesize
; gs = freemem segment
shr bx, 4
inc bx
mov ax, gs
add ax, bx
mov gs, ax
</code>
Third Question:
Then i call the startup file, inititilze the timer call the code to be timed, record the time elapased, call the cleanup file.
The call is 'Call dword [CS:codepointer]' which contains offset of 0 in the first word and the seg of the code in the second word.
This seems to work becuase the code works perfectly the fisrt time.
but when i try to run the timer again, without modifyin the
'[CS:codepointer]', it lands somewhere nere the end of the intended code ( or at least that's where the program dies because of the 'bytes at CS:IP' dump that happens when it dies). I know that the
'[CS:codepointer]' is not being modifed because i print it on the sceen just before calling it. I'm stumped. I'd appreciate any help/comments/suggestion on these topics
Thanks
Peter
Sorry about the alingment of the comments, etc.
but I don't know how to use the tabs key in the edit box, it skips to the next item on the web page rather then inserting a the tab char.
This is the code that runs the main loop.
<code>
dotime:
startup ; load ds and es with cs
mov di, 0
mov cx, 80*4
zeroscrn ; clears cx char of screen
again:
mov di, 160*3
mov eax, [CS:startfile] ; lp to startup code
dispeax ; prints eax
mov si, spcstr
mov ah,dcolor
printmsg ; print some spaces
mov eax, [CS:timefile] ; lp to code to be timed
dispeax ; prints eax
mov si, spcmsg
mov ah,dcolor
printmsg ; print some spaces
mov eax, [CS:cleanupfile] ; lp to cleanup code
dispeax ; prints eax
mov ah, dcolor
mov si, addrsmsg ; asks to continue after viewing addrs
mov di, 0
printmsg
.badkey:
getkey
or al, lower_case
cmp al, 'y'
je .continue
cmp al, 'n'
je .skip ; skips timing files
jmp .badkey
.continue:
mov di, 0
mov cx, 160
zeroscrn ; clears prompt
mov di, 160*3
mov cx, 160
zeroscrn ; clears pointer to files
call dword [CS:startfile] ; works on the first try :)
times 10h nop ; seem to make timing more accurate by waiting.
timer tm ; starts timer
call dword [CS:timefile] ; works on the first try :)
timerend tm,[CS:overhead] ; stops timer and subs the overhead
; needed to start the timer and stop it
call dword [CS:cleanupfile] ; works on the first tyr :)
.skip:
mov ax, cs
mov ds, ax ; load ds with cs
mov es, ax ; load es with cs
mov si, timemsg
mov di, 0
mov ah, dcolor
printmsg
mov eax, [CS:tm]
dispeax
mov eax, [CS:tm+4]
dispeax
mov si, againmsg
mov di, 160
mov ah, dcolor
printmsg
dokey:
getkey ; waits for key
cmp ah, 03bh ; process keystroke
je calibrate ; .................
cmp ah, 03Ch ; .................
je getfiles ; .................
cmp ah, 01h ; .................
je Exit ; .................
cmp ah, 1ch ; .................
je again ; .................
jmp dokey ; .................
Exit:
exit 00h
</code>