home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / CONV17.ASM < prev    next >
Assembly Source File  |  1994-10-31  |  2KB  |  73 lines

  1.     page    66,132
  2. ;******************************** CONV03.ASM *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12.  
  13. comment 
  14. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( CONVERT )
  15. ;DEC_STR4_TO_DWORD -  convert signed ascii string to DWORD
  16. ;
  17. ; inputs  ds:si = string pointer
  18. ;            cx = length of string
  19. ; output  bx,dx = binary value
  20. ;       si = updated to point at end of value
  21. ;       al = zero if success
  22. ;* * * * * * * * * * * * * *
  23. 
  24. str_sign    db    0
  25.  
  26.     extrn    dmul_10_plus:far
  27.     public    DEC_STR4_TO_DWORD
  28. DEC_STR4_TO_DWORD    proc    far
  29.     mov    bx,0
  30.     mov    cs:str_sign,0
  31. sb6:    lodsb
  32.     dec    cx
  33.     jcxz    sb8_done2
  34.     cmp    al,' '
  35.     je    sb6            ;remove leading spaces
  36.     cmp    al,'+'
  37.     je    sb17            ;jmp if sign found
  38.     cmp    al,'-'
  39.     jne    sb18
  40.     mov    cs:str_sign,1        ;set sign negative
  41.  
  42.     xor    ah,ah               ;
  43.     xor    dx,dx            ;running sum = 0
  44.     xor    bx,bx            ;running sum = 0
  45. ;
  46. ; remove blanks in front of number
  47. ;
  48. sb17:    lodsb
  49.     dec    cx
  50.     jcxz    sb8_done
  51. sb18:    sub    al,'0'
  52.     js    sb8_done        ;jmp if error, not number
  53.     cmp    al,9
  54.     ja    sb8_done        ;jmp if error, not number
  55.  
  56.     call    dmul_10_plus        ;compute (dx,ax) * 10 + bx
  57.     jnc    sb17            ;jmp if no errors
  58.  
  59. sb8_done:
  60.     cmp    str_sign,0        ;is result +
  61.     je    sb8_done2        ;jmp if + number
  62.     not    dx
  63.     neg    ax
  64.     sbb    dx,-1
  65. sb8_done2:    
  66.  
  67.     retf        
  68. DEC_STR4_TO_DWORD    endp
  69.  
  70. LIBSEG    ENDS
  71.     end
  72.