I am trying to make a huffman tree compression using assembly,now I have built the sorted frequence table of bytes,but couldn't building it to a huffman tree and do compress .:confused:
So who can tell me some tricks or some place that I could get help about such arithmetic written by assembly.:stupid:

Thanks any!

Posted on 2002-04-25 10:08:22 by smallwaves
I haven't worked with huffman *encoding* but here are my thoughts on decoding, maybe you can get some ideas from it:



P.S. my PNGlib contains the full implementation of a zlib decoder (which uses huffman as well)
Posted on 2002-04-25 10:17:26 by Thomas
Download the source pack - many compressors in ASM :)
Arithmic, DMC, Huffman, RLE, etc...
Posted on 2002-04-25 10:19:31 by bitRAKE
I'm almost temped to do this in a new thread (but since it relates to the point of compression and BitRake's link to hugi.com) -- here it goes:

In one of the examples (given in the competions examples -- Sniper?) the author creates a new file (entry.com) and stores the entire contents of "Unpacker.com" and "hugi.raw" (compressed)

Now I'm guessing that entry.com now unpacks the data contained in itself and loads the image...

Using 32 bit assembly can this method be accomplished using exe files?

Or can this only be done within the context of the 16 bit realm (in otherwords will I never be able to compete in this form of competetion because my data can't be stored in itself in the same manner?

I hope I'm being clear about this...

If anyone has an idea or (source?) as to how this can be done... I'd be very intrested in it...

I'm including the source for both the pack.c and unpacker.asm (obviously you need to have the hugi.raw to actually run the program at the above link)


; Unpack.com
; Forever Young Software
; Benjamin David Lunt (SNIPER)
; [url]http://www.zekes.com/~blunt/index.html[/url]
; This is my part entry for the seventh adok^hugi contest
; I am in the process of moving and had a little time
; to work on an entry. It is a wopping 19,999 bytes,
; however, a few points is better than no points.
; Maybe I can get back to it and do some real compression
; when I am done moving.
; - Sniper (Ben)
; 02 May 1999
; Well needless to say, I didn't get back to it at all.
; I was working on a fractal compression that compressed
; hugi.raw to 4k. However, I think it was a little
; too "lossy".
; As I stated above, a few points is better than none and
; at least I can say that I entered #7.
; For about 2 hours work, I say I did pretty good. :-}
; When I suggested this compo, I had in mind a small graphic
; so that the compo would be more about the viewer, rather
; than the actual compression of a file. Oh well, It looks
; as if you all had fun anyway, and that is the idea of
; the whole thing.
; Looking forward to #8, and good luck to all.
; -Ben
; (31 May 1999)
OurSize equ 2000

.model small, c
CodeSeg segment
assume cs:CodeSeg, ds:CodeSeg, es:CodeSeg
org 100h
mov al,13h
int 10h

mov cx,256 ; (cx = 255 on start up) (inc cx)
;xor bx,bx ; bx = 00 on start up
mov dx,offset BufferIn
mov ax,1012h
int 10h

mov si,offset BufferIn
add si,768
mov ax,0A000h
mov es,ax ; es:di = 0A000:0000h
xor di,di ;
mov cx,32
MainLoop: push cx
mov cx,ax
and cx,3FFFh
shr ax,14
cmp al,00h
jne short NotNull
mov cx,OurSize
xor al,al
rep stosb
jmp short LoopIt
NotNull: cmp al,01h
jne short NotRLE
call rleit
jmp short LoopIt
NotRLE: ;cmp al,02h
;jne short LoopIt
; do another compression algo here
LoopIt: pop cx
loop MainLoop

xor ah,ah
int 16h

mov ax,0003h
int 10h

ret ; return to DOS

rleit proc near
mov bx,cx
rleitL: lodsb
dec bx
mov cx,1
test al,10000000b
jz short NotRep
and al,01111111b
mov cl,al
dec cx
dec bx
rep stosb
NotRep: stosb
or bx,bx
jnz short rleitL
rleit endp


CodeSeg ends
end start


/* This is the packer for my wopping 19,999 byte entry.
It is in C so that I could do it fairly fast, since
I haven't much time tonight to do anything.

I hope to get to it after I am done moving.

(Anyway, a few points is better than none)

Compiled with MS Quick C 2.5 in SMALL model

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define UNSIZE 104

unsigned int i, j, k, l, rle, repcnt;
unsigned char buffer[2000];
unsigned char rlebuff[2000];
unsigned int tempw;

FILE *input;
FILE *output;

void rleit();

void main(void) {

input = fopen("unpack.com","rb");
output = fopen("entry.com","w+b");

// copy .com file code from 'unpack.com' to entry.com

input = fopen("hugi.raw","rb");
fread(&buffer,768,1,input); // write uncompressed palette
for(j=0; j < 32; j++) {
// do other compress algos here

l = 0;
for (k=0; k < sizeof(buffer); k++)
l |= buffer[k];
if (l == 0)
else {
// check for sizes here when get another compress algo
tempw = (rle | 0x4000);


void rleit() {
i = rle = 0;
do {
repcnt = 0;
while(((i+(repcnt++)) < (sizeof(buffer)-1)) &&
(buffer[i+repcnt] == buffer[i]) && (repcnt < 0x7F));
if (repcnt > 1)
rlebuff[rle++]=(repcnt | 0x80);
if (buffer[i] > 0x7F)
i += repcnt;
} while(i < sizeof(buffer));

Posted on 2002-04-25 14:04:01 by Sliver
You can create an EXE (what do you think the compiler does?), but COM files are nice(=easy) because they are flat files - you don't have to worry about headers and sections. You could not do this with the Hugi Compo because it's small DOS programs. f0dder, has hinted about needing to do this in windows.
Posted on 2002-04-25 14:13:10 by bitRAKE
There is a piece of 0The huffman source in the VX magazine by 29A,but I forget whether it's in Issue 4 or Issue 5...
Who have some standard asm LZ compression source code?
Posted on 2002-04-25 21:43:40 by Hume