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

  1.     page    66,132
  2. ;******************************** CONV25.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. comment 
  13. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( CONVERT )
  14. DEC_STR_TO_WORD -  convert unsigned ascii string to binary word
  15. ;
  16. ; inputs  ds:si points    at string ending with "space" or "return"
  17. ; output  ax = binary value
  18. ;       si = updated to point at end of value
  19. ;       carry set if    error
  20. ;* * * * * * * * * * * * * *
  21. 
  22. ab_low    dw    0
  23.  
  24.     PUBLIC    DEC_STR_TO_WORD
  25. DEC_STR_TO_WORD        PROC    FAR
  26.     push    di
  27.     push    bx
  28.     mov    cs:ab_low,0            ;  accumulators
  29. ;
  30. ; remove blanks in front of number
  31. ;
  32.     mov    bx,10            ;base 10?
  33. ab1:    cmp    byte ptr [si],' '
  34.     jne    ab2            ;jmp if not preceeding space
  35. nxt_flush:
  36.     inc    si
  37.     jmp    ab1
  38. ;
  39. ; conversion loop
  40. ;    
  41. ab_loop:
  42.     inc    si            ;move    to next    char
  43. ab2:    mov    al,[si]
  44. ;
  45. ; convert key to binary
  46. ;
  47. key21:    cmp    al,0dh
  48.     je    ab_done
  49.     cmp    al,' '
  50.     je    ab_done
  51.     cmp    al,09
  52.     je    ab_done
  53.     cmp    al,'/'
  54.     je    ab_done
  55.     cmp    al,0
  56.     je    ab_done
  57. key22:    cmp    al,'0'
  58.     jl    ab_err            ;skip non numeric key
  59.     cmp    al,'9'
  60.     jle    decimal            ;jump if    decimal    value
  61. ;
  62. ; we have a hex    number or bad value.
  63. ;
  64.     jmp    ab_err            ;    jmp if wrong base
  65. decimal:
  66.     sub    al,'0'            ;convert to number
  67. got_binary_key:
  68.     sub    ah,ah
  69.     push    ax            ;save key
  70. ;
  71. ; multiply sum by current base
  72. ;
  73.     mov    ax,cs:ab_low
  74.     mov    dx,0
  75.     mul    bx
  76. ;
  77. ; add latest character to sum
  78. ;
  79.     pop    di
  80.     add    ax,di            ;add to sum
  81.     mov    di,0
  82.     adc    dx,di            ;add carry
  83. ;
  84.     mov    cs:ab_low,ax
  85.     jmp    ab_loop
  86. ab_err:
  87.     stc
  88.     jmp    ab_exit
  89. ab_done:
  90.     mov    ax,cs:ab_low
  91.     clc
  92. ab_exit:
  93.     pop    bx
  94.     pop    di
  95.     RETF
  96. DEC_STR_TO_WORD ENDP
  97.  
  98. LIBSEG    ENDS
  99.     end
  100.