home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / driver6s / getnum.asm < prev    next >
Assembly Source File  |  1990-01-12  |  2KB  |  75 lines

  1. ;put into the public domain by Russell Nelson, nelson@clutx.clarkson.edu
  2.  
  3.     public    get_number
  4. get_number:
  5.     mov    bp,10            ;we default to 10.
  6.     jmp    short get_number_0
  7.  
  8.     public    get_hex
  9. get_hex:
  10.     mov    bp,16
  11. ;get a hex number, skipping leading blanks.
  12. ;enter with si->string of digits,
  13. ;    di -> dword to store the number in.  [di] is not modified if no
  14. ;        digits are given, so it acts as the default.
  15. ;return cy if there are no digits at all.
  16. ;return nc, bx:cx = number, and store bx:cx at [di].
  17. get_number_0:
  18.     call    skip_blanks
  19.     call    get_digit        ;is there really a number here?
  20.     jc    get_number_3
  21.     or    al,al            ;Does the number begin with zero?
  22.     jne    get_number_4        ;no.
  23.     mov    bp,8            ;yes - they want octal.
  24. get_number_4:
  25.  
  26.     xor    cx,cx            ;get a hex number.
  27.     xor    bx,bx
  28. get_number_1:
  29.     lodsb
  30.     cmp    al,'x'            ;did they really want hex?
  31.     je    get_number_5        ;yes.
  32.     cmp    al,'X'            ;did they really want hex?
  33.     je    get_number_5        ;yes.
  34.     call    get_digit        ;convert a character into an int.
  35.     jc    get_number_2        ;not a digit (neither hex nor dec).
  36.     xor    ah,ah
  37.     cmp    ax,bp            ;larger than our base?
  38.     jae    get_number_2        ;yes.
  39.  
  40.     push    ax            ;save the new digit.
  41.  
  42.     mov    ax,bp            ;multiply the low word by ten.
  43.     mul    cx
  44.     mov    cx,ax            ;keep the low word.
  45.     push    dx            ;save the high word for later.
  46.     mov    ax,bp
  47.     mul    bx
  48.     mov    bx,ax            ;we keep only the low word (which is our high word)
  49.     pop    dx
  50.     add    bx,ax            ;add the high result from earlier.
  51.  
  52.     pop    ax            ;get the new digit back.
  53.     add    cx,ax            ;add the new digit in.
  54.     adc    bx,0
  55.     jmp    get_number_1
  56. get_number_5:
  57.     mov    bp,16            ;change the base to hex.
  58.     jmp    get_number_1
  59. get_number_2:
  60.     dec    si
  61.     mov    [di],cx            ;store the parsed number.
  62.     mov    [di+2],bx
  63.     clc
  64.     jmp    short get_number_6
  65. get_number_3:
  66.     cmp    al,'?'            ;did they ask for the default?
  67.     stc
  68.     jne    get_number_6        ;no, return cy.
  69.     add    si,2            ;skip past the question mark.
  70.     mov    cx,-1
  71.     mov    bx,-1
  72.     jmp    get_number_2        ;and return the -1.
  73. get_number_6:
  74.     ret
  75.