home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / packetdrivers.tar.gz / pd.tar / src / decout.asm < prev    next >
Assembly Source File  |  1995-06-25  |  870b  |  47 lines

  1. ;put into the public domain by Russell Nelson, nelson@crynwr.com
  2.  
  3.     public    decout
  4. decout:
  5. ;enter with dx:ax = number to print.
  6.     mov    si,ax            ;get the number where we want it.
  7.     mov    di,dx
  8.     or    ax,dx            ;is the number zero?
  9.     jne    decout_nonzero
  10.     mov    al,'0'            ;yes - easier to just print it, than
  11.     jmp    chrout            ;  to eliminate all but the last zero.
  12. decout_nonzero:
  13.  
  14.     xor    ax,ax            ;start with all zeroes in al,bx,bp
  15.     mov    bx,ax
  16.     mov    bp,ax
  17.  
  18.     mov    cx,32            ;32 bits in two 16 bit registers.
  19. decout_1:
  20.     shl    si,1
  21.     rcl    di,1
  22.     xchg    bp,ax
  23.     call    addbit
  24.     xchg    bp,ax
  25.     xchg    bx,ax
  26.     call    addbit
  27.     xchg    bx,ax
  28.     adc    al,al
  29.     daa
  30.     loop    decout_1
  31.  
  32.     mov    cl,'0'            ;prepare to eliminate leading zeroes.
  33.     call    byteout            ;output the first two.
  34.     mov    ax,bx            ;output the next four
  35.     call    wordout            ;output the next four
  36.     mov    ax,bp
  37.     jmp    wordout
  38.  
  39. addbit:    adc    al,al
  40.     daa
  41.     xchg    al,ah
  42.     adc    al,al
  43.     daa
  44.     xchg    al,ah
  45.     ret
  46.  
  47.