home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
INTBITS.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-04
|
2KB
|
77 lines
;void set_int_bits(value,bits,position);
; unsigned short *value;
; unsigned char *bits,position;
EXTRN _memory_model:byte
EXTRN _error_code:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _set_int_bits
_set_int_bits proc near
push bp ;
mov bp,sp ;set stack frame
push di ;
push si ;
push ds ;save DS
mov _error_code,1 ;flag error
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 L1 ;jump if near
les di,dword ptr[bp+4] ;get addr of the word
lds si,dword ptr[bp+8] ;DS:SI pts to bit_string
add bp,4 ;forward BP to compensate for dbl words
jmp short L2 ;jump ahead
L1: mov ax,ds ;ES = DS
mov es,ax ;
mov di,[bp+4] ;near case
mov si,[bp+6] ;
L2: sub dx,dx ;will count number bits in field
push si ;
L3: cmp byte ptr[si],0 ;end of string?
je L4 ;jump if so
inc dx ;inc counter
inc si ;forward ptr
cmp dx,16 ;reached maximum yet?
jne L3 ;loop if not
L4: pop si ;restore si
mov bx,1 ;BX is mask
sub cx,cx ;clear CX
mov cl,[bp+8] ;get field start pos
add cx,dx ;add start position to number bits
cmp cx,16 ;in range?
ja L8 ;quit routine if not
dec cx ;adjust for shift
shl bx,cl ;mov mask bit to 1st pos
mov cx,dx ;get string length
jcxz L8 ;quit if null
mov ax,es:[di] ;fetch value
L5: cmp byte ptr[si],'1' ;test a byte of the string
jne L6 ;jump if not a '1'
or ax,bx ;else, set the bit
jmp short L7 ;jump ahead
L6: not bx ;reverse the mask
and ax,bx ;clear the bit
not bx ;re-reverse the mask
L7: shr bx,1 ;shift bit mask 1 to right
inc si ;pt to next byte of strg
loop L5 ;go do next byte
mov es:[di],ax ;write the changed value
pop ds ;restore DS
dec _error_code ;0 = no error
jmp short L9 ;jump ahead
L8: pop ds ;restore DS
L9: pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_set_int_bits endp
_TEXT ENDS
END