home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
SETBIT8.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
2KB
|
61 lines
;void set_bits_8(value,replacement,position,bits)
; unsigned char *value,replacement,position,bits;
EXTRN _memory_model:byte
EXTRN _error_code:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _set_bits_8
_set_bits_8 proc near
push bp ;
mov bp,sp ;set up stack frame
push di ;
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,0 ;clear _error_code
cmp _memory_model,2 ;data near or far?
jb L0 ;jump if near
les di,dword ptr[bp+4] ;ptr to Value
inc bp ;add 2 to BP since dword ptr
inc bp ;
jmp short L00 ;
L0: mov ax,ds ;ES = DS
mov es,ax ;
mov di,[bp+4] ;
L00: mov cl,[bp+10] ;number bits
inc _error_code ;1 = zero bits
or cl,cl ;error check
jz L1 ;quit if zero bits
mov dl,0FFH ;all 1s in DL
shl dl,cl ;field-width of 0s
not dl ;field-width of 1s
mov al,[bp+6] ;replacement value
and al,dl ;clear superfluous bits
mov bl,cl ;copy Bits to BL
mov cl,[bp+8] ;Position
inc _error_code ;2 = position out of range
cmp cl,7 ;in range?
ja L1 ;quit if not
add bl,cl ;add number bits
inc _error_code ;3 = field doesn't fit
cmp bl,8 ;does it fit?
ja L1 ;quit if error
shl al,cl ;shift value to position
shl dl,cl ;shift mask to position
not dl ;reverse mask
and es:[di],dl ;clear field
or es:[di],al ;write new bits
mov _error_code,0 ;success, return 0
L1: pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_set_bits_8 endp
_TEXT ENDS
END