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

  1.     page    66,132
  2. ;******************************** CONV12.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_WORD -  convert signed asciiz string to binary word
  17. ;
  18. ; inputs  ds:si points    at string ending with zero
  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.  
  26.     extrn    ten:word
  27.     public    DEC_STR3_TO_WORD
  28. DEC_STR3_TO_WORD    proc    far
  29.     push    dx
  30.     cld
  31.     mov    bx,0
  32.     mov    cs:str_sign,0
  33. ab5:    lodsb
  34.     cmp    al,' '
  35.     je    ab5            ;remove leading spaces
  36.     cmp    al,'+'
  37.     je    ab6            ;jmp if sign found
  38.     cmp    al,'-'
  39.     jne    ab7
  40.     mov    cs:str_sign,1        ;set sign negative
  41. ab6:    lodsb                ;get next char
  42.  
  43. ab7:    or    al,al
  44.     jz    ab3_done
  45.     sub    al,'0'
  46.     js    ab3_done        ;jmp if error, not number
  47.     cmp    al,9
  48.     ja    ab3_done        ;jmp if error, not number
  49.  
  50.     sub    ah,ah
  51.     push    ax            ;save current char
  52.  
  53.     mov    ax,bx            ;get running sum
  54.     mul    cs:ten
  55.     pop    dx            ;get current char
  56.     add    ax,dx
  57.     mov    bx,ax            ;save running sum
  58.     lodsb
  59.     jmp    ab7            ;loop till done
  60.  
  61. ab3_done:
  62.     cmp    str_sign,0        ;is result +
  63.     je    ab3_done2        ;jmp if + number
  64.     neg    bx
  65. ab3_done2:    
  66.     pop    dx
  67.     retf        
  68.         
  69. DEC_STR3_TO_WORD    endp
  70.  
  71. LIBSEG    ENDS
  72.     end
  73.     
  74.