?? huf.asm
字號:
mov cx, N_CHAR ;
mov di, offset DGROUP:_son ;
mov bx, offset DGROUP:_prnt[T * 2] ;
$_4:
stosw ;
add ax, 2 ;
mov [bx], dx ;
add bx, 2 ;
add dx, 2 ;
LOOP $_4
$_5:
;
mov si, 0 ;
mov di, 2 ;
mov bx, N_CHAR * 2 ;
mov cx, N_CHAR - 1 ;
$_6:
mov ax, _freq[si] ;
add ax, _freq[di] ;
mov _freq[bx], ax ;
mov _son[bx], si ;
mov _prnt[si], bx ;
mov _prnt[di], bx ;
add si, 4 ;
add di, 4 ;
add bx, 2 ;
LOOP $_6
$_7:
xor ax, ax ;
mov _iobuf, ax ;
mov _iobuf, ax ;
mov _iolen, al ;
mov _iolen, al ;
mov word ptr DGROUP:_freq[T * 2], -1;
mov word ptr DGROUP:_prnt[R * 2], ax; 0
pop di ;
pop si ;
ret ;
_StartModel endp ;
;
;-----------------------------------------------;
; 栘峔憿偺嵞峔抸 ;
;-----------------------------------------------;
public _reconst ;
_reconst proc near ;
push si ;
mov ax, ds ;
mov es, ax ;
xor si, si ;
mov di, si ;
$_8:
cmp _son[si], T * 2
jB $_10
mov ax, _freq[si] ;
inc ax ;
shr ax, 1 ;
mov _freq[di], ax ;
mov ax, _son[si] ;
mov _son[di], ax ;
inc di ;
inc di ;
$_10:
inc si ;
inc si ;
cmp si, T * 2
jB $_8
$_9:
xor si, si ;
mov di, N_CHAR * 2 ;
$_11:
mov bx, si ;
inc bx ;
inc bx ;
mov ax, _freq[si] ;
add ax, _freq[bx] ;
mov _freq[di], ax ;
;
mov bx, di ;
$_13:
dec bx ;
dec bx ;
cmp ax, _freq[bx]
jB $_13
$_14:
inc bx ;
inc bx ;
mov cx, di ;
sub cx, bx ;
shr cx, 1 ;
std ;
push cx ;
push si ;
push di ;
lea si, _freq[di] ;
mov di, si ;
dec si ;
dec si ;
rep movsw ;
mov _freq[bx], ax ;
pop di ;
pop si ;
pop cx ;
;
push si ;
push di ;
lea si, _son[di] ;
mov di, si ;
dec si ;
dec si ;
rep movsw ;
pop di ;
pop si ;
mov _son[bx], si ;
;
add si, 4 ;
add di, 2 ;
cmp di, T * 2
jB $_11
$_12:
xor si, si ;
$_15:
mov di, _son[si] ;
mov _prnt[di], si ;
cmp di, T * 2
jAE $_17
mov _prnt[di + 2], si
$_17:
inc si ;
inc si ;
cmp si, T * 2
jB $_15
$_16:
pop si ;
ret ;
_reconst endp ;
;
;-----------------------------------------------;
; 栘峔憿偺峏怴 ;
;-----------------------------------------------;
; si : prnt[c + T] ;
;-----------------------------------------------;
public _update ;
_update proc near ;
cmp _freq[R * 2], MAX_FREQ
jB $_18
call near ptr _reconst ;
$_18:
mov si, _prnt[si + T * 2] ;
$_19:
mov ax, _freq[si] ;
inc ax ;
mov _freq[si], ax ;
lea di, [si + 2] ;
cmp ax, _freq[di]
jA $_21
jmp $_22
$_21:
$_23:
inc di ; add di, 2
inc di ;
cmp ax, _freq[di]
jA $_23
$_24:
dec di ; sub di, 2
dec di ;
xchg ax, _freq[di] ;
mov _freq[si], ax ;
;
mov bx, _son[si] ;
mov _prnt[bx], di ;
cmp bx, T * 2
jAE $_25
mov _prnt[bx + 2], di
$_25:
xchg bx, _son[di] ;
mov _prnt[bx], si ;
cmp bx, T * 2
jAE $_26
mov _prnt[bx + 2], si
$_26:
mov _son[si], bx ;
;
mov si, di ;
$_22:
mov si, _prnt[si] ;
or si, si
jZ $_27
jmp $_19
$_20:
$_27:
ret ;
_update endp ;
;
;-----------------------------------------------;
; 俫倀俥偺晞崋壔 ;
;-----------------------------------------------;
public _EncodeChar ;
_EncodeChar proc near ;
shl bx, 1 ;
mov si, bx ;
mov bx, _prnt[bx + T * 2] ;
mov ax, 0 ;
mov ch, 0 ;
$_28:
mov dx, bx ;
shr dx, 1 ;
shr dx, 1 ;
rcr ax, 1 ;
inc ch ;
mov bx, _prnt[bx] ;
cmp bx, R * 2
jNE $_28
$_29:
call _Putcode ;
call _update ;
ret ;
_EncodeChar endp ;
;
;-----------------------------------------------;
; 埵抲忣曬偺晞崋壔 ;
;-----------------------------------------------;
public _EncodePosition ;
_EncodePosition proc near ;
mov si, bx ;
mov cl, 6 ;
shr bx, cl ;
mov ah, byte ptr DGROUP:_p_code[bx] ;
mov al, 0 ;
mov ch, byte ptr DGROUP:_p_len[bx] ;
call near ptr _Putcode ;
mov ax, si ;
mov ah, al ;
mov al, 0 ;
shl ax, 1 ;
shl ax, 1 ;
mov ch, 6 ;
call near ptr _Putcode ;
ret ;
_EncodePosition endp ;
;
;-----------------------------------------------;
; 俫倀俥偺晞崋壔廔椆張棟 ;
;-----------------------------------------------;
public _EncodeEnd ;
_EncodeEnd proc near ;
$_30:
cmp DGROUP:_iolen, 0
jLE $_32
mov bx, DGROUP:_outfile ;
mov al, byte ptr _iobuf + 1 ;
putc@ ;
sub _iolen, 8 ;
add word ptr DGROUP:_codesize, 1
adc word ptr DGROUP:_codesize + 2, 0
jmp $_30
$_32:
$_31:
ret ;
_EncodeEnd endp ;
;
;-----------------------------------------------;
; 俫倀俥偺夝撉 ;
;-----------------------------------------------;
public _DecodeChar ;
_DecodeChar proc near ;
mov si, _son[R * 2] ;
mov dx, DGROUP:_iobuf ;
mov cl, DGROUP:_iolen ;
and cx, 00ffh ;
jmp short dc1 ;
$_33:
shr si, 1 ;
shl dx, 1 ;
adc si, 0 ;
shl si, 1 ;
mov si, _son[si] ;
dec cx ;
dc1: ;
jz GetBuf ;
dc2: ;
cmp si, T * 2
jB $_33
$_34:
mov DGROUP:_iobuf, dx ;
mov DGROUP:_iolen, cl ;
sub si, T * 2 ;
mov dx, si ;
call near ptr _update ;
mov ax, dx ;
shr ax, 1 ;
ret ;
_DecodeChar endp ;
;
public GetBuf ;
GetBuf: ;
mov bx, DGROUP:_infile ;
getc@ ;
mov dh, al ;
mov bx, DGROUP:_infile ;
getc@ ;
mov dl, al ;
mov cl, 16 ;
jmp short dc2 ;
;
;-----------------------------------------------;
; 埵抲忣曬偺夝撉 ;
;-----------------------------------------------;
public _DecodePosition ;
_DecodePosition proc near ;
call near ptr _GetByte ;
mov si, ax ;
mov dl, _d_code[si] ;
mov dh, 0 ;
mov cl, 6 ;
shl dx, cl ;
push dx ;
mov cl, _d_len[si] ;
mov ch, 0 ;
sub cx, 2 ;
call near ptr _GetNBits ;
or ax, si ;
rol ax, cl ;
and ax, 003fh ;
pop dx ;
add ax, dx ;
ret ;
_DecodePosition endp ;
_TEXT ends ;
end ;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -