home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
BITCPY16.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
2KB
|
70 lines
;void bit_copy_16(target,source,t_start,s_start,number);
; unsigned short *target,source;
; unsigned char t_start,s_start,number;
EXTRN _memory_model:byte
EXTRN _error_code:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _bit_copy_16
_bit_copy_16 proc near
push bp ;
mov bp,sp ;set up stack frame
push di ;
push si ;
mov _error_code,0 ;clear _error_code
cmp _memory_model,0 ;near or far?
jle begin ;jump if near
inc bp ;else add 2 to BP
inc bp ;
begin: cmp _memory_model,2 ;data near or far?
jb L0 ;jump if near
les di,dword ptr[bp+4] ;point to Target
inc bp ;add 2 to bp since dword
inc bp ;
jmp short L00 ;jump ahead
L0: mov ax,es ;ES = DS
mov ds,ax ;
mov di,[bp+4] ;
L00: mov dx,es:[di] ;move to DX
mov ax,[bp+6] ;source to AX
mov bx,1 ;bit mask for target
mov si,bx ;bit mask for source
mov ch,[bp+12] ;number bits
inc _error_code ;1 = zero bits
or ch,ch ;check for zero bits
jz L4 ;quit if zero
mov cl,ch ;copy to CL for error chk
add cl,[bp+8] ;add to target start bit
inc _error_code ;2 = field out of range
cmp cl,16 ;in range?
ja L4 ;quit if out of range
mov cl,[bp+10] ;source start bit
shl si,cl ;mask bit to start pt
mov cl,[bp+8] ;target start bit
shl bx,cl ;mask bit to start pt
L1: test ax,si ;test source bit
jnz L2 ;jump if '1'
not bx ;reverse mask
and dx,bx ;zero out bit
not bx ;re-reverse mask
jmp short L3 ;jump ahead
L2: or dx,bx ;set bit
L3: shl si,1 ;shift mask up by one
shl bx,1 ;ditto
dec ch ;dec bit field counter
jnz L1 ;loop till finished
mov es:[di],dx ;set value for return
mov _error_code,0 ;success, return 0
L4: pop si ;
pop di ;
pop bp ;restore BP and quit
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_bit_copy_16 endp
_TEXT ENDS
END