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

  1.     page    66,132
  2. ;******************************** CONV13.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_WORD -  convert signed ascii string to binary word
  16. ;
  17. ; inputs  ds:si = string pointer
  18. ;            cx = length of string
  19. ; output  bx = binary value
  20. ;       si = updated to point at end of value
  21. ;       al = zero if success
  22. ;* * * * * * * * * * * * * *
  23. 
  24. str_sign    db    0
  25.     extrn    ten:word
  26.     public    DEC_STR4_TO_WORD
  27. DEC_STR4_TO_WORD    proc    far
  28.     push    dx
  29.     cld
  30.     mov    bx,0
  31.     mov    cs:str_sign,0
  32. ab8:    jcxz    ab4_done
  33.     lodsb
  34.     dec    cx
  35.     cmp    al,' '
  36.     je    ab8            ;remove leading spaces
  37.     cmp    al,'+'
  38.     je    ab9            ;jmp if sign found
  39.     cmp    al,'-'
  40.     jne    ab10
  41.     mov    cs:str_sign,1        ;set sign negative
  42. ab9:    jcxz    ab4_done
  43.     lodsb                ;get next char
  44.     dec    cx
  45.  
  46. ab10:    sub    al,'0'
  47.     js    ab4_err         ;jmp if error, not number
  48.     cmp    al,9
  49.     ja    ab4_err         ;jmp if error, not number
  50.  
  51.     sub    ah,ah
  52.     push    ax            ;save current char
  53.  
  54.     mov    ax,bx            ;get running sum
  55.     mul    cs:ten
  56.     pop    dx            ;get current char
  57.     add    ax,dx
  58.     mov    bx,ax            ;save running sum
  59.     jcxz    ab4_done
  60.     lodsb
  61.     dec    cx
  62.     jmp    ab10            ;loop till done
  63.  
  64. ab4_done:
  65.     cmp    str_sign,0        ;is result +
  66.     je    ab4_done2        ;jmp if + number
  67.     neg    bx
  68. ab4_done2:    
  69.     sub    al,al
  70. ab4_err:    
  71.     pop    dx
  72.     retf        
  73. DEC_STR4_TO_WORD    endp
  74.  
  75. LIBSEG    ENDS
  76.     end
  77.