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

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