home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
COMPRS8.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
3KB
|
89 lines
;unsigned int compress_8(source,target,bits,pos,num);
; unsigned char *source,*target,bits,pos,num;
EXTRN _memory_model:byte
EXTRN _error_code:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _compress_8
_compress_8 proc near
jmp short start ;
target_count dw ? ;
start: mov cs:target_count,0 ;
push bp ;
mov bp,sp ;set stack frame
push di ;
push si ;
pushf ;
push ds ;
cmp _memory_model,0 ;near or far?
jle begin ;jump if near
inc bp ;else add 2 to BP
inc bp ;
begin: mov _error_code,1 ;1 = error
cmp _memory_model,2 ;data near or far?
jb L1 ;jump if near
lds si,dword ptr[bp+4] ;DS:SI pts to Source
les di,dword ptr[bp+8] ;ES:DI pts to Target
add bp,4 ;add 4 to bp since 2 far ptrs
jmp short L2 ;jump ahead
L1: mov ax,ds ;ES = DS
mov es,ax ;
mov si,[bp+4] ;DS:SI
mov di,[bp+6] ;ES:DI
L2: cld ;set direction flag
sub ax,ax ;clear AX
mov al,[bp+8] ;number bits to copy
or ax,ax ;test for zero
jz L8 ;quit if zero
add al,[bp+10] ;add Position
cmp al,8 ;does the pattern fit?
ja L8 ;quit if not
mov bx,1 ;BX holds mask for AX
mov cl,[bp+10] ;starting bit
shl bx,cl ;move mask to start pos
mov [bp+10],bx ;copy at [BP+10]
sub dl,dl ;DL holds Target byte
mov dh,1 ;DH masks Target byte
L3: lodsb ;Source element in AL
mov bx,[bp+10] ;get starting mask
sub cx,cx ;clear CX
mov cx,[bp+8] ;bit field length
L4: test al,bl ;test if bit set
jz L5 ;jump if not set
or dl,dh ;set bit in Target value
L5: cmp dh,128 ;end of Target byte?
jne L6 ;jump ahead if not
mov es:[di],dl ;save the value
inc cs:target_count ;inc count of target bytes changed
inc di ;point to next target pos
sub dl,dl ;clear next target byte
mov dh,1 ;else restart at bottom
jmp short L7 ;don't shift target mask
L6: shl dh,1 ;forward target mask
L7: shl bx,1 ;forward source mask
loop L4 ;go do next bit of Source
dec word ptr[bp+12] ;dec source element ctr
jnz L3 ;go get next element
pop ds ;
dec _error_code ;0 = no error
mov es:[di],dl ;save last byte of Target
cmp dh,1 ;just beginning new byte?
je L9 ;jump ahead if so
inc cs:target_count ;inc count of target bytes changed
jmp short L9 ;
L8: pop ds ;
L9: mov ax,cs:target_count ;
popf ;
pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_compress_8 endp
_TEXT ENDS
END