home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CRUNCH10.ZIP / PUTCODE.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-10-27  |  3.5 KB  |  70 lines

  1.  
  2. ;  Register useage:
  3. ;
  4. ;  AX - holds Code
  5. ;  BX - BH is a work register, BL holds SaveByte
  6. ;  CX - holds our loop counter CodeSize
  7. ;  DX - holds BitsUsed
  8. ;
  9.                 mov         ax,[bp+<Code]
  10.                 xor         bx,bx
  11.                 mov         cx,bx
  12.                 mov         dx,bx
  13.                 mov         bl,[>SaveByte]
  14.                 mov         cl,[>CodeSize]
  15.                 mov         dl,[>BitsUsed]
  16.                 cmp         ax,-1               ;Any work to do?
  17.                 jnz         Repeat              ;Yup, go do it
  18.                 cmp         dl,0                ;Any leftovers?
  19.                 jz          AllDone             ;Nope, we're done
  20.                 push        bx                  ;Yup...push leftovers
  21.                 push        cs
  22.                 call        [bp+>PutCharAddr]   ;   and send to output
  23.                 jmp short   AllDone
  24. ;
  25. Repeat:         xor         bh,bh               ;Zero out BH
  26.                 rcr         ax,1                ;Get low order bit into CY flag
  27.                 jnc         SkipBit             ;Was the bit set?
  28.                 inc         bh                  ;Yes, xfer to BH
  29. SkipBit:        xchg        cx,dx               ;Swap CX & DX
  30.                 shl         bh,cl               ;Shift bit over
  31.                 xchg        cx,dx               ;Put CX & DX back where they were
  32.                 inc         dx                  ;Bump count of bit positions used
  33.                 or          bl,bh               ;Transfer bit to output byte (SaveByte)
  34.                 cmp         dx,8                ;Full byte yet?
  35.                 jb          GetNext             ;Nope, go get more code bits
  36.                 push        ax                  ;Yup, save regs in preparation
  37.                 push        bx                  ;    for call to output routine
  38.                 push        cx
  39.                 push        dx
  40.                 push        bx                  ;Push byte to output onto stack
  41.                 push        cs
  42.                 call        [bp+>PutCharAddr]   ;   and call the output routine
  43.                 xor         ax,ax
  44.                 mov         al,[>CodeBytes]     ;Recalculate position in un-arc
  45.                 inc         al                  ;  program's input code buffer
  46.                 xor         cx,cx               ;  CodeBytes :=
  47.                 mov         cl,[>CodeSize]      ;  Succ(CodeBytes) MOD CodeSize
  48.                 div         cl                  
  49.                 mov         al,ah
  50.                 mov         [>CodeBytes],al
  51.                 pop         dx
  52.                 pop         cx
  53.                 pop         bx
  54.                 pop         ax
  55.                 xor         bx,bx               ;Prepare SaveByte for next byte
  56.                 mov         dx,bx               ;Set BitsUsed to zero
  57. GetNext:        loop        Repeat              ;Repeat for all code bits
  58. ;
  59.                 mov         [>SaveByte],bl      ;Put SaveByte and BitsUsed
  60.                 mov         [>BitsUsed],dl      ;   back in memory
  61. ;
  62.                 mov byte    [>Ok_to_Clear],0    ;Test if it's ok to clear the
  63.                 xor         ax,ax               ;   Code table at this time
  64.                 mov         al,[>CodeBytes]
  65.                 add         al,2
  66.                 cmp         al,[>CodeSize]      ;Ok to clear table?
  67.                 jnz         AllDone             ;Nope, don't set flag TRUE
  68.                 mov byte    [>Ok_to_Clear],1    ;Ok, set flag
  69. AllDone:
  70.