home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / CONV16.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.  
  14. comment 
  15. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( CONVERT )
  16. ;DEC_STR3_TO_DWORD -  convert signed asciiz string to binary DWORD
  17. ;
  18. ; inputs  ds:si points    at string ending with zero
  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_STR3_TO_DWORD
  28. DEC_STR3_TO_DWORD    proc    far
  29.     mov    bx,0
  30.     mov    cs:str_sign,0
  31. sb5:    lodsb
  32.     cmp    al,' '
  33.     je    sb5            ;remove leading spaces
  34.     cmp    al,'+'
  35.     je    sb15            ;jmp if sign found
  36.     cmp    al,'-'
  37.     jne    sb16
  38.     mov    cs:str_sign,1        ;set sign negative
  39.  
  40.     xor    ah,ah               ;
  41.     xor    dx,dx            ;running sum = 0
  42.     xor    bx,bx            ;running sum = 0
  43. ;
  44. ; remove blanks in front of number
  45. ;
  46. sb15:    lodsb
  47.  
  48. sb16:    or    al,al
  49.     jz    sb7_done        ;jmp if done, end of string
  50.     sub    al,'0'
  51.     js    sb7_done        ;jmp if error, not number
  52.     cmp    al,9
  53.     ja    sb7_done        ;jmp if error, not number
  54.  
  55.     call    dmul_10_plus        ;compute (dx,ax) * 10 + bx
  56.     jnc    sb15            ;jmp if no errors
  57.  
  58. sb7_done:
  59.     cmp    str_sign,0        ;is result +
  60.     je    sb7_done2        ;jmp if + number
  61.     not    dx
  62.     neg    ax
  63.     sbb    dx,-1
  64. sb7_done2:    
  65.     retf        
  66.         
  67. DEC_STR3_TO_DWORD    endp
  68.     
  69.  
  70. LIBSEG    ENDS
  71.     end
  72.