flat assembler
Message board for the users of flat assembler.

Index > Windows > CPUSpeed

Author
Thread Post new topic Reply to topic
viki



Joined: 03 Jan 2006
Posts: 40
Location: Czestochowa, Poland
viki 03 Jan 2006, 13:47
Hello.

I wrote small application for measure a CPU frequency.

Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

ID_DIALOG          = 10 
ID_FREQ1           = 101
ID_MSG             = 201

section '.data' data readable writeable

  CPUSpeed dd 123
  bf    db '%6lu MHz',0 
  output rb 20

section '.code' code readable executable

start:

        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,ID_DIALOG,HWND_DESKTOP,DialogProc,0
        or      eax,eax
        jz      exit
exit:
        invoke  ExitProcess,0

proc DialogProc hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_INITDIALOG
        je      wminitdialog
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        xor     eax,eax
        jmp     finish
  wminitdialog:
        jmp     processed
wmcommand:
        cmp     [wparam],BN_CLICKED shl 16 + IDCANCEL
        je      wmclose
        cmp     [wparam],BN_CLICKED shl 16 + IDOK
        jne     processed
;obsBuga ok
    invoke SleepEx, 100, 0
    rdtsc
    push edx
    push eax
    invoke SleepEx, 1000, 0
    rdtsc
    pop ecx
    sub eax, ecx
    pop ecx
    sbb edx, ecx
    mov ecx, 1000000
    div ecx
    mov [CPUSpeed], eax
  invoke  wsprintf,output,bf,[CPUSpeed] 
  invoke  SetDlgItemText,[hwnddlg],ID_FREQ1,output
  jmp processed

wmclose:
        invoke  EndDialog,[hwnddlg],0
processed:
        mov     eax,1
finish:
        pop     edi esi ebx
        ret
endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL'

;  library  user,'USER32.DLL'


  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         ExitProcess,'ExitProcess',\
         UpdateWindow,'UpdateWindow',\
         SleepEx,'SleepEx'

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
         SetDlgItemText,'SetDlgItemTextA',\
         wsprintf,'wsprintfA',\ 
         EndDialog,'EndDialog'

section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,ID_DIALOG,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration

  dialog demonstration,'CPU Frequency meter',0,0,250,50,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
    dialogitem 'STATIC','Frequency:',-1   ,5 ,10,35,10,WS_VISIBLE
    dialogitem 'STATIC',' ',ID_FREQ1,45,10,55,10,WS_VISIBLE;+WS_BORDER
    dialogitem 'BUTTON','Find',IDOK,195,10,50,14,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
    dialogitem 'BUTTON','Exit',IDCANCEL,195,25,50,14,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
  enddialog


    


On win98 and winXP it seens working but on winNT and win2000 it display a correct speed but then there is a error message like this. Any ideas?


Description:
Filesize: 9.39 KB
Viewed: 2234 Time(s)

blad.gif


Description:
Download
Filename: CPUSpeed.zip
Filesize: 824 Bytes
Downloaded: 230 Time(s)

Post 03 Jan 2006, 13:47
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 03 Jan 2006, 20:59
Run it inside a debugger, like OllyDbg, and see where the crash occurs.
Post 03 Jan 2006, 20:59
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
viki



Joined: 03 Jan 2006
Posts: 40
Location: Czestochowa, Poland
viki 04 Jan 2006, 09:30
Thanks comrade. I used OllyDbg and I found the problem. Problem was that I used invoke instead of cinvoke in wsprintf function
Code:
format PE GUI 4.0
entry start 

include 'fasminc\win32a.inc'

ID_DIALOG          = 10  
ID_FREQ1           = 101 
ID_MSG             = 201 

section '.data' data readable writeable 

  CPUSpeed dd 123 
  bf    db '%6lu MHz',0  
  output rb 20 

section '.code' code readable executable 

start: 

        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,ID_DIALOG,HWND_DESKTOP,DialogProc,0 
        or      eax,eax 
        jz      exit 
exit: 
        invoke  ExitProcess,0 

proc DialogProc hwnddlg,msg,wparam,lparam
        push    ebx esi edi 
        cmp     [msg],WM_INITDIALOG 
        je      wminitdialog 
        cmp     [msg],WM_COMMAND 
        je      wmcommand 
        cmp     [msg],WM_CLOSE 
        je      wmclose 
        xor     eax,eax 
        jmp     finish 
  wminitdialog: 
        jmp     processed 
wmcommand: 
        cmp     [wparam],BN_CLICKED shl 16 + IDCANCEL 
        je      wmclose 
        cmp     [wparam],BN_CLICKED shl 16 + IDOK 
        jne     processed 
;obsBuga ok 
    invoke SleepEx, 100, 0 
    rdtsc 
    push edx 
    push eax 
    invoke SleepEx, 1000, 0 
    rdtsc 
    pop ecx 
    sub eax, ecx 
    pop ecx 
    sbb edx, ecx 
    mov ecx, 1000000 
    div ecx 
    mov [CPUSpeed], eax 
  cinvoke  wsprintf,output,bf,[CPUSpeed]
  invoke  SetDlgItemText,[hwnddlg],ID_FREQ1,output 
  jmp processed 

wmclose: 
        invoke  EndDialog,[hwnddlg],0 
processed: 
        mov     eax,1 
finish: 
        pop     edi esi ebx 
        ret 
endp 

section '.idata' import data readable writeable 

  library kernel,'KERNEL32.DLL',\ 
          user,'USER32.DLL' 

;  library  user,'USER32.DLL' 


  import kernel,\ 
         GetModuleHandle,'GetModuleHandleA',\ 
         ExitProcess,'ExitProcess',\ 
         UpdateWindow,'UpdateWindow',\ 
         SleepEx,'SleepEx' 

  import user,\ 
         DialogBoxParam,'DialogBoxParamA',\ 
         SetDlgItemText,'SetDlgItemTextA',\ 
         wsprintf,'wsprintfA',\  
         EndDialog,'EndDialog' 

section '.rsrc' resource data readable 
  RT_MANIFEST = 24 
  
  directory RT_DIALOG,dialogs,RT_MANIFEST,manifests 
  
  resource dialogs,ID_DIALOG,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration 
  resource manifests,1,LANG_ENGLISH+SUBLANG_DEFAULT,man 
  
  dialog demonstration,'CPU Frequency meter',0,0,250,50,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME 
    dialogitem 'STATIC','Frequency:',-1   ,5 ,10,35,10,WS_VISIBLE 
    dialogitem 'STATIC',' ',ID_FREQ1,45,10,55,10,WS_VISIBLE;+WS_BORDER 
    dialogitem 'BUTTON','Find',IDOK,195,10,50,14,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON 
    dialogitem 'BUTTON','Exit',IDCANCEL,195,25,50,14,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON 
  enddialog 

  resdata man 
         db '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',13,10 
         db '<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">',13,10 
         db '<assemblyIdentity name="x.x.x" processorArchitecture="x86" version="5.1.0.0" type="win32"/> ',13,10 
         db '<description>no</description>',13,10 
         db '<dependency>',13,10 
         db '<dependentAssembly>',13,10 
         db '<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*" />',13,10 
         db '</dependentAssembly>',13,10 
         db '</dependency>',13,10 
         db '</assembly>',13,10 
  endres
    
Post 04 Jan 2006, 09:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.