home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / LSIZE.ASM < prev    next >
Assembly Source File  |  1990-04-29  |  2KB  |  106 lines

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4. ; LSize- Returns the number of print positions required by an integer value.
  5. ;       On Input:
  6. ;                       DX:AX- Integer to get the size of.
  7. ;
  8. ;       On Output:
  9. ;                       AX: Digit count for the integer.
  10. ;
  11.         public  sl_LSize
  12. sl_LSize        proc    far
  13.         push    dx
  14.         cmp     dx, 0
  15.         jge     LSize2
  16. ;
  17. ; Negate DX:AX
  18. ;
  19.         neg     dx
  20.         neg     ax
  21.         sbb     dx, 0
  22. ;
  23.         call    GetULSize
  24.         inc     ax
  25.         pop     dx
  26.         ret
  27. ;
  28. LSize2:         call    GetULSize
  29.         pop     dx
  30.         ret
  31. sl_LSize        endp
  32. ;
  33. ; USize- Same as above, except for unsigned numbers.
  34. ;
  35.         public  sl_ULSize
  36. sl_ULSize       proc    far
  37.         call    GetULSize
  38.         ret
  39. sl_ULSize       endp
  40. ;
  41. ; GetUSize- Does the actual size comparison.
  42. ;
  43. GetULSize       proc    near
  44.         cmp     dx, 0
  45.         jne     GUSA
  46. ;
  47.         cmp     ax, 10
  48.         ja      GUS1
  49.         mov     ax, 1
  50.         ret
  51. ;
  52. GUS1:           cmp     ax, 100
  53.         ja      GUS2
  54.         mov     ax, 2
  55.         ret
  56. ;
  57. GUS2:           cmp     ax, 1000
  58.         ja      GUS3
  59.         mov     ax, 3
  60.         ret
  61. GUS3:           cmp     ax, 10000
  62.         ja      GUS4
  63.         mov     ax, 4
  64.         ret
  65. ;
  66. GUS4:           mov     ax, 5
  67.         ret
  68. ;
  69. GUSA:           sub     ax, 86a0h               ;Low (100,000)
  70.         sbb     dx, 1                   ;High(100,000)
  71.         jb      GUS5
  72.         sub     ax, 0bba0h              ;Low (900,000)
  73.         sbb     dx, 0dh                 ;High(900,000)
  74.         jb      GUS6
  75.         sub     ax, 5440h               ;low (9,000,000)
  76.         sbb     dx, 89h                 ;high(9,000,000)
  77.         jb      GUS7
  78.         sub     ax, 4a80h               ;low (90,000,000)
  79.         sbb     dx, 55dh                ;high(90,000,000)
  80.         jb      GUS8
  81.         sub     ax, 0e900h              ;low (900,000,000)
  82.         sbb     dx, 35a4h               ;high(900,000,000)
  83.         jb      GUS9
  84.         mov     ax, 10
  85.         ret
  86. ;
  87. GUS5:           mov     ax, 5
  88.         ret
  89. ;
  90. GUS6:           mov     ax, 6
  91.         ret
  92. ;
  93. GUS7:           mov     ax, 7
  94.         ret
  95. ;
  96. GUS8:           mov     ax, 8
  97.         ret
  98. ;
  99. GUS9:           mov     ax, 9
  100.         ret
  101. ;
  102. GetULSize       endp
  103. ;
  104. stdlib        ends
  105.         end
  106.