home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
MEMWORD.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
2KB
|
71 lines
;void set_mem_word(bit_string,position,segment,offset);
; unsigned char *bit_string,position;
; unsigned short segment,offset;
EXTRN _memory_model:byte
EXTRN _error_code:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _set_mem_word
_set_mem_word proc near
push bp ;
mov bp,sp ;set stack frame
push di ;
push si ;
cmp _memory_model,0 ;near or far?
jle begin ;jump if near
inc bp ;else add 2 to BP
inc bp ;
begin: push ds ;save DS
cmp _memory_model,2 ;data near or far?
jb L0 ;jump ahead if near
lds si,dword ptr[bp+4] ;DS:SI pts to Bits
inc bp ;add 2 to BP since dword ptr
inc bp ;
jmp short L00 ;
L0: mov si,[bp+4] ;
L00: mov byte ptr[bp+4],0 ;errorcode 0 = no error
mov ax,[bp+8] ;get segment
mov es,ax ;place in ES
mov di,[bp+10] ;get offset
mov bx,1 ;BX is mask, set low bit
sub cx,cx ;clear CX
mov cl,[bp+6] ;get field start pos
jcxz L1 ;jump if start at bit 0
shl bx,cl ;mov mask bit to starting pos
L1: cmp byte ptr[si],0 ;null string?
je L6 ;quit if so
mov cx,16 ;as many as eight bits
sub cx,dx ;minus start position = max bits to write
mov dx,es:[di] ;place memory value in DX
L2: mov al,[si] ;get byte from string
cmp al,0 ;end of string?
je L5 ;quit
cmp al,'1' ;a '1'?
jne L3 ;jump if not
or dx,bx ;set bit
jmp short L4 ;jump ahead
L3: not bx ;reverse mask
and dx,bx ;clear the bit
not bx ;restore mask
L4: inc si ;forward string pointer
shl bx,1 ;shift mask
loop L2 ;go do next
inc byte ptr[bp+4] ;1 = binary string too long
L5: mov es:[di],dx ;return value to memory
L6: pop ds ;restore DS
mov al,[bp+4] ;fetch _error_code
mov _error_code,al ;set it
pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_set_mem_word endp
_TEXT ENDS
END