News:

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

Average milliseconds per character to Words Per Minute

Started by Tight_Coder_Ex, January 20, 2008, 07:09:03 PM

Previous topic - Next topic

Tight_Coder_Ex

I'm working on a small application that allows user to see dynamically while typing their rate of speed in words per minute.  I'm not sure I can make this algo any smaller and would be especially interested if someone could coerce a "C" or "C++" compiler to be as efficient.

Equivalent too        60 / ((total_time / 1000) / total_characters) / 5 + .05

ECX = Number of characters entered
EBX = Value of GetTickCount

    0      8BC3                       mov     eax, ebx ; EAX = Current tick count
    2      2B06                       sub     eax, [esi] ; Minus count at start
    4      99                         cdq
    5      F7F9                       idiv    ecx
    7      8BC8                       mov     ecx, eax ; ECX = Average milliseconds / character
    9      B8 804F1200                mov     eax, 124F80 ; = 1,200,000
    E      99                         cdq
    F      F7F9                       idiv    ecx
    11     83C0 05                    add     eax, 5

  Convert unsigned value to an ascii decimal string. DispFmt = "%8d"

    14     BB 40304000                mov     ebx, offset WordsPerMin
    19     50                         push    eax
    1A     68 26304000                push    offset DispFmt
    1F     53                         push    ebx
    20     E8 A0020000                call    _wsprintfA

  Divides whole number by 100 and drops tens position of decimal 7094 converts to 70.9

    25     83C4 0C                    add     esp, 0C
    28     83C3 06                    add     ebx, 6
    2B     66:8B03                    mov     ax, [ebx]
    2E     C1E0 08                    shl     eax, 8
    31     B0 2E                      mov     al, 2E
    33     66:8903                    mov     [ebx], ax

    36 = 54 bytes
Tested and works as required