home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / bluebook / asm-subr / dec16in < prev    next >
Encoding:
Text File  |  1985-12-22  |  1.5 KB  |  54 lines

  1. ;-------------------------dec16in routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 57
  4. ;
  5. ; NAME DEC16IN
  6. ; ROUTINE FOR conversion from ASCII decimal to 16-bit Binary
  7. ;
  8. ; FUNCTION: This routine accepts an decimal number from the standard input
  9. ; device and converts it to internal 16-bit binary form.
  10. ; INPUT: The individual digits of the decimal number are received in ASCII
  11. ; through a call to a standard I/O routine.  The valid digits are 0 - 9.
  12. ; An ASCII code other than for a valid digit will terminate the routine.
  13. ;
  14. ; OUTPUT: A 16-bit binary number is returned in the DX register.
  15. ; REGISTERS USED:  Only DX is modified. It returns the result.
  16. ; SEGMENTS REFERENCED:  None
  17. ; ROUTINES CALLED:  STDIN
  18. ; SPECIAL NOTES: None
  19. ;
  20. ; ROUTINE TO CONVERT FROM ASCII decimal TO INTERNAL 16-BIT BINARY
  21. ;
  22. dec16in    proc    far
  23. ;
  24.     push    cx        ; save registers
  25.     push    ax
  26. ;
  27.     mov    dx,0        ; initialize DX
  28. ;
  29. dec16in1:
  30.     call    stdin        ; a digit comes in in AL
  31.     sub    al,30h        ; reduce from ASCII
  32.     jl    dec16in2    ; check if too low
  33.     cmp    al,9
  34.     jg    dec16in2    ; check if too high
  35.     cbw            ; convert to word
  36. ;
  37.     push    ax        ; save digit
  38.     mov    ax,dx        ;
  39.     mov    cx,10        ; decimal power of 10
  40.     mul    cx        ; multiply
  41.     mov    dx,ax        ; store result in DX
  42.     pop    axl        ; restore digit
  43.     add    dx,ax        ; add in digit
  44.     jmp     dec16in1
  45. ;
  46. dec16in2:
  47. ;
  48.     pop    ax        ; restore registers
  49.     pop    cx
  50.     ret            ; return
  51. ;
  52. dec16in    endp
  53. ;-------------------------dec16in routine ends---------------------------+
  54.