home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
EXPAND16.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
2KB
|
81 lines
;void expand_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 _expand_16
_expand_16 proc near
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
cld ;set direction flag
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 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: 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 ax,[bp+10] ;add Position
cmp ax,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+6]
mov dl,[si] ;Source element in DL
inc si ;forward source ptr
mov dh,1 ;DH masks Source byte
L3: sub ax,ax ;AX holds Target word
mov bx,[bp+10] ;get starting mask
sub cx,cx ;clear CX
mov cl,[bp+8] ;bit field length
L4: test dl,dh ;test if bit set
jz L5 ;jump if not set
or ax,bx ;else set bit in Target
L5: cmp dh,128 ;end of Source byte?
jne L6 ;jump ahead if not
mov dl,[si] ;get fresh Source byte
inc si ;forward Source ptr
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
stosw ;save Target word
dec word ptr [bp+12] ;dec source element ctr
jnz L3 ;go get next element
pop ds ;
dec _error_code ;0 = no error
jmp short L9 ;
L8: pop ds ;
L9: popf ;
pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_expand_16 endp
_TEXT ENDS
END