home *** CD-ROM | disk | FTP | other *** search
/ Total Destruction / Total_Destruction.iso / addons / Lccwin32.exe / Lccwin32 / lccpub / lib / src / atoll.asm < prev    next >
Encoding:
Assembly Source File  |  1997-08-31  |  1.4 KB  |  78 lines

  1.     .text
  2.     .file "atoll.c"
  3.     .type    _atoll,function
  4. _atoll:
  5. ; Register assignments:
  6. ; eax: digit to be converted
  7. ; edx: old value of esi
  8. ; ecx: zero if positive, 1 if negative
  9. ; esi: points to string
  10. ; st(0) accumulator for the result
  11. ; st(1) 10
  12. ; Save esi in edx
  13.     movl    %esi,%edx
  14. ; Read argument
  15.     movl    4(%esp),%esi
  16. ; clear eax register for making sure only al is set later
  17.     xor    %eax,%eax
  18.     push    %eax
  19. ; load 10 into st(1) and zero into st(0)
  20.     fildl    _$13
  21.     fldz
  22.     or    %esi,%esi
  23. ; test for NULL pointer
  24.     je    _$atollExit
  25. ; number defaults to positive
  26.     movl    %eax,%ecx
  27. _$IgnoreSpaceLoop:
  28.     lodsb
  29.     cmpb    $32,%al
  30.     je    _$IgnoreSpaceLoop
  31.     cmpb    $9,%al
  32.     je    _$IgnoreSpaceLoop
  33. ; Ignore '+' sign if present
  34.     cmpb    $43,%al
  35.     je    _$atolltest
  36. ; test if first digit is negative sign
  37.     cmpb    $45,%al
  38.     jne    _$atollTestentry
  39. ; ecx contains 1 if first digit negative sign
  40.     inc    %ecx
  41. ; skip negative sign
  42.     jmp    _$atolltest
  43. _$atollLoop:
  44. ; 1) convert al from ascii to binary
  45.     subb    $48,%al
  46. ; 2) Multiply old value by 10
  47.     fmul    %st(1),%st
  48. ; 3) Add new digit
  49.     movl    %eax,(%esp)
  50.     fiaddl    (%esp)
  51. _$atolltest:
  52.     lodsb
  53. _$atollTestentry:
  54.     cmpb    $48,%al
  55.     jl    _$atollTestIfNegative
  56.     cmpb    $57,%al
  57.     jle    _$atollLoop
  58. _$atollTestIfNegative:
  59.     or    %ecx,%ecx
  60.     je    _$atollExit
  61.     fchs
  62. _$atollExit:
  63.     push    %eax
  64.     fistpq    (%esp)
  65.     pop    %eax
  66.     movl    %edx,%esi
  67.     pop    %edx
  68.     ffree    %st(0)
  69.     fincstp
  70.     ret
  71. _$20:
  72.     .size    _atoll,_$20-_atoll
  73.     .globl    _atoll
  74.     .data
  75.     .align    2
  76. _$13:
  77.     .long    0xa
  78.