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

  1.     page    66,132
  2. ;******************************** CONV11.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_STR2_TO_WORD -  convert unsigned ascii string to binary word
  16. ;
  17. ; inputs  ds:si = string ptr
  18. ;            cx = string length
  19. ; output  bx = binary value
  20. ;       si = updated to point at end of value
  21. ;       al = zero if success
  22. ;* * * * * * * * * * * * * *
  23. 
  24.     extrn    ten:word
  25.     public    DEC_STR2_TO_WORD
  26. DEC_STR2_TO_WORD    proc    far
  27.     push    dx
  28.     cld
  29.     mov    bx,0               ;set running sum = 0
  30. ;
  31. ; remove blanks in front of number
  32. ;
  33. ab3:    lodsb
  34.     jcxz    ab2_done
  35.     dec    cx
  36.     cmp    al,' '
  37.     je    ab3            ;remove leading spaces
  38.  
  39. ab4:    sub    al,'0'
  40.     js    ab2_err            ;jmp if error, not number
  41.     cmp    al,9
  42.     ja    ab2_err         ;jmp if error, not number
  43.  
  44.     sub    ah,ah
  45.     push    ax            ;save current char
  46.  
  47.     mov    ax,bx            ;get running sum
  48.     mul    cs:ten
  49.     pop    dx            ;get current char
  50.     add    ax,dx
  51.     mov    bx,ax            ;save running sum
  52.     jcxz    ab2_done
  53.     lodsb
  54.     dec    cx
  55.     jmp    ab4            ;loop till done
  56.     
  57. ab2_done:
  58.     xor    al,al
  59. ab2_err:    
  60.     pop    dx
  61.     RETF
  62. DEC_STR2_TO_WORD    endp
  63.     
  64.  
  65. LIBSEG    ENDS
  66.     end
  67.