home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Assembler / dse-src6.dms / in.adf / BOUNCHSRCS.LZH / crunch.s < prev    next >
Encoding:
Text File  |  1989-01-22  |  2.3 KB  |  68 lines

  1.  
  2. ; Mini cruncher
  3.  
  4. ; By Fredrik Juto 1989
  5. ; This software is public domain,
  6. ; you may freely distribute, modify or sell it.
  7. ; (See `decrunch.s' for decrunch routine)
  8.  
  9. ;  FROM  A0
  10. ;   TO   A1
  11. ; LENGTH D0
  12.  
  13. crunch:
  14.    movem.l  d0-d3/a0-a3,-(sp) ; push the registers we are going to use on stack
  15.    movea.l  a0,a3
  16.    adda.l   d0,a3           ; a3 points to source end
  17.    moveq    #0,d1
  18.  
  19. cr_main:
  20.    cmpa.l   a0,a3           ; source = source end?
  21.    beq.s    cr_end         ; Yep, exit. 
  22.    move.b   #-1,d2         ; Start counting on -1 (both crunch & dump)
  23.    move.b   1(a0),d1
  24.    cmp.b    (a0),d1        ; Are the two next chars equal?
  25.    beq.s    cr_crunch      ; Yes, crunch them.
  26.  
  27. *** Dump ***
  28.    move.l   a1,a2          ; A2 points to control byte
  29.    addq.l   #1,a1          ; Make room for it
  30. cr_dump:
  31.    move.b   (a0)+,(a1)+    ; Dumping...
  32.    addq.b   #1,d2          ; Increase counter
  33.    cmp.b    #$7f,d2        ; Max length reached?
  34.    beq.s    cr_enddump     ; Yes, stop dumping.
  35.    cmpa.l   a0,a3          ; Are we done crunching?
  36.    beq.s    cr_enddump     ; Yes, stop dumping (main will exit)
  37.    move.b   1(a0),d1       ; See if we can crunch the two
  38.    cmp.b    (a0),d1        ; next chars.
  39.    bne.s    cr_dump        ; No, continue crunching...
  40. cr_enddump:
  41.    move.b   d2,(a2)        ; Write control byte,
  42.    bra.s    cr_main        ; and jump to main.
  43.  
  44. *** Crunch ***
  45. cr_crunch:
  46.    addq.b   #1,d2          ; Increase byte counter
  47.    cmp.b    #$7f,d2        ; No room for more bytes in counter?
  48.    beq.s    cr_endcrunch   ; Yep, stop crunching.
  49.    cmpa.l   a0,a3          ; Is the job done yet?
  50.    beq.s    cr_doendcrunch ; Yeah! we stop crunching and main will return for us.
  51.    move.b   1(a0),d3
  52.    cmp.b    (a0)+,d3       ; Is it possible to continue crunching?
  53.    beq.s    cr_crunch      ; Yes, we can continue.
  54.    bra.s    cr_doendcrunch ; Nope, jump to cr_doendcrunch
  55. cr_endcrunch:
  56.    addq.l   #1,a0          ; increase source ptr.
  57. cr_doendcrunch:
  58.    bset     #7,d2          ; set bit #7 of byte counter.
  59.    move.b   d2,(a1)+       ; save counter to destination.
  60.    move.b   d1,(a1)+       ; save byte to destination.
  61.    bra.s    cr_main        ; and goto main
  62.  
  63. cr_end:
  64.    movem.l  (sp)+,d0-d3/a0-a3 ; push the callers registers back from stack.
  65.    rts                     ; return to caller
  66.  
  67.    end                     ; end of assembly
  68.