home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asm_kit / decibin.asm < prev    next >
Assembly Source File  |  1985-06-21  |  1KB  |  37 lines

  1. ;DECIBIN--Program to get decimal digits from keyboard and
  2. ;convert them to binary number in BX
  3. ;
  4. prognam segment
  5. ;
  6.         assume cs:prognam
  7. ;
  8.         mov bx,0                     ;clear BX for number
  9. ;Get digit from keyboard, convert to binary
  10. ;
  11. newchar:
  12.         mov ah,1                     ;keyboard input
  13.         int 21h                      ;call DOS
  14.         sub al,30h                   ;ASCII to binary
  15.         jl exit                      ;jump if <0
  16.         cmp al,9h                    ;is it > 9d ?
  17.         jg exit                      ;yes, not decimal digit
  18.         cbw                          ;byte in AL to word in AX
  19. ;(digit is now in AX)
  20. ;
  21. ;Multiply number in BX by 10 decimal
  22.         xchg ax,bx                   ;trade digit & number
  23.         mov cx,10d                   ;put 10 decimal in CX
  24.         mul cx                       ;number times 10
  25.         xchg ax,bx                   ;trade number & digit
  26. ;
  27. ;Add digit in AX to number in BX
  28.         add bx,ax                    ;add digit to number
  29.         jmp newchar                  ;get next digit
  30. exit:
  31. ;
  32.         int 20h
  33. ;
  34. prognam ends
  35. ;
  36.         end
  37.