.global _Compress ;Compresses n words at a time. Max bytes out is n*3;
    _Compress:
    ;w0 Pointer of input array. Also, return value for number of bytes written.
    ;w1 Pointer of output array.
    ;w2 Number of words to process.
    ;w3 Resets memory of previous word.
    
    
    push w1; save addr to stack
    cp0 w3
    bra z,skipclear
    clr PrevWord
    
    skipclear:
    
    mov w2,w3
    mov PrevWord,w2
    
    DO W3, CompLoop
    mov [w0++],w3
    sub w3,w2,w2;previous word - current word
    mov.b w2,[w1++];put lower half into output array. Will get overwritten if > |127|
    btsc W2,#15;could also check status reg for neg status
    neg w2,w2; abs value
    cp W2,#128
    bra ltu, Skip3byte
    mov.b #128,w2
    mov.b w2,[w1-1]
    swap w3
    mov.b w3,[w1++]
    swap w3
    mov.b w3,[w1++]
    
    Skip3byte:
    mov w3,w2
    CompLoop:
    nop
    
    mov w2,PrevWord
    Mov w1,w2;
    pop w1;get addr
    sub w2,w1,w0;get number of bytes written
    
    return