home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
COMPRS16.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
3KB
|
89 lines
;unsigned int compress_16(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_16
_compress_16 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,16 ;does the pattern fit?
ja L8 ;jump ahead if OK
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: lodsw ;Source element in AX
mov bx,[bp+10] ;get starting mask
sub cx,cx ;clear CX
mov cx,[bp+8] ;bit field length
L4: test ax,bx ;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 changes
jmp short L9 ;
L8: pop ds ;
L9: mov ax,cs:target_count ;set return value
popf ;
pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_compress_16 endp
_TEXT ENDS
END