News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Cpu speed

Started by Magnum, November 17, 2011, 08:45:00 PM

Previous topic - Next topic

Magnum

Temporarily doing some 16 bit code.  :P

I must have the wrong version of ml.exe for this or link.exe.

I am using this to assemble and link.

ml /c /AT %1.asm
link %1.obj



; cpu.asm MASM CODE Com file
;         Uses rdtsc command
;         CPU speed routine (+/- 3%)

cseg segment
assume cs: cseg,ds:cseg,es:cseg,ss:cseg

org 100h
.586     

main:   

        jmp go

msg db " MHz",13,10,"$"

getSpeed proc

        push    40h
        pop     es

        mov     ch, 17                  ; 17 values for average of 16 periods
l0:
        mov     ax, es:[6ch]
roll:
        cmp     ax, es:[6ch]            ; wait until rollover
        jz      roll
        rdtsc                           ; Pentium instruction (.586)

        push    edx
        push    eax
        dec     ch
        jnz     l0

        xor     cl, cl
        xor     eax, eax                ; allocate cl:eax for the sum
        pop     ebx
        pop     edx
        mov     ch, 16
l2:
        pop     esi
        pop     edi
        sub     ebx, esi
        sbb     edx, edi
        add     eax, ebx
        adc     cl, dl
        mov     ebx, esi
        mov     edx, edi
        dec     ch
        jnz     l2

; cl:eax = total sum of 16 values
        shrd    eax, ecx, 4             ; eax = average value

        xor     edx, edx
        mov     ebx, 54925              ; 1e6 / (1193180Hz / 65536 = 18.2Hz)
        div     ebx

        mov     bx, 10

        xor     ch, ch
l3:
        xor     dx, dx
        div     bx

        push    dx
        inc     ch
        or      ax, ax
        jnz     l3

        mov     ah, 2

        xor     ebx, ebx

l4:
        pop     dx
        mov     bl, dl
        shl     bl, 4

        add     dl, "0"
        int     21h
        dec     ch
        jnz     l4

        mov     ah, 9
        lea     dx, msg
        int     21h
         
        ret
getSpeed endp

go:
        call    getSpeed ; should detect if it's a pentium 1st!

exit:

mov ax,4c00h
int 21h

cseg ends
end main

Have a great day,
                         Andy

clive

You'd want to use LINK16
It could be a random act of randomness. Those happen a lot as well.

Magnum

I was using the right link, but I had to go back to Version 6.14 of masm.

Now I am trying to figure out how to get it to not show

Run File

and

List File
Have a great day,
                         Andy

clive

To get it to not ask for listing, library, definitions, etc?

link16 test.obj,test.exe,,,,

Newer MASM might require /OMF to get the 16-bit Object Module Format, conversely the older ones require /COFF to get 32-bit Common Object File Format
It could be a random act of randomness. Those happen a lot as well.

Magnum

Clive,

I found that a ";" at the end worked.

Have a great day,
                         Andy