; ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл

    .486                      ; force 32 bit code
    .model flat, stdcall      ; memory model & calling convention
    option casemap :none      ; case sensitive

comment * ---------------------------------------------
        This algorithm is a slightly modified version
        of a macro written by Ray Filiatreault that has
        been adapted to a library procedure.
        --------------------------------------------- *

    atol PROTO :DWORD

    .code

; ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл

atol proc lpSrc:DWORD

comment * -----------------------------------------------------------
        A "-" or "+" sign is permitted as the 1st character
        Conversion thereafter terminates on the first character < 30h
        lpSrc is the address of the ascii string
        EAX, ECX and EDX are modified
        ----------------------------------------------------------- *

   xor eax, eax
   xor ecx, ecx
   mov edx, lpSrc

   sub edx, 1
  @@:
   add edx, 1
   cmp BYTE PTR [edx], 32
   je @B
   cmp BYTE PTR [edx], 9
   je @B

   mov al, [edx]
   add edx, 1

   .if al == "-"
       add ecx, 1
       mov al,[edx]
       add edx, 1
   .elseif al == "+"
       mov al,[edx]
       add edx, 1
   .endif
   push ecx             ; keep sign on stack
   xor ecx,ecx
@@:
   sub al,"0"
   jc  @F
   lea ecx,[ecx+ecx*4]
   lea ecx,[eax+ecx*2]
   mov al,[edx]
   add edx, 1
   jmp @B
@@:
   mov eax,ecx
   pop ecx              ; retrieve sign
   shr ecx,1
   jnc @F
   neg eax
@@:

    ret

atol endp

; ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл

end