home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
CHRFSTRG.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
2KB
|
67 lines
;void char_field_string(value,start_bit,number_bits,return_string);
; unsigned char value,start_bit,number_bits,*return_string;
EXTRN _memory_model:byte
EXTRN _error_code:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _char_field_string
_char_field_string proc near
push bp ;save 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: cmp _memory_model,2 ;data near or far?
jb L0 ;jump if near
les di,dword ptr[bp+10] ;ES:DI pts to return string
jmp short L00 ;
L0: mov ax,ds ;ES = DS
mov es,ax ;
mov di,[bp+10] ;near case
L00: mov _error_code,1 ;1 = error
sub ax,ax ;clear AX
mov al,[bp+4] ;load value into AX
sub cx,cx ;CL = 0
mov es:[di],cl ;return null string if error
mov cl,[bp+6] ;starting point in CX
cmp cx,7 ;in range?
ja L4 ;quit if not
sub dx,dx ;clear DX
mov dl,[bp+8] ;field width in DX
or dx,dx ;test for zero
jz L4 ;quit if zero
mov si,cx ;starting point copy
add si,dx ;add field width
cmp si,8 ;in range?
ja L4 ;quit if not
add di,dx ;point to end of string
mov byte ptr es:[di],0 ;set terminator byte
mov bx,1 ;BX will be bit mask
shl bx,cl ;shift mask bit to strtpt
mov cx,dx ;CX counts bits
mov dx,3031H ;'0' and '1' in DH-DL
L1: dec di ;point to next byte
test ax,bx ;test if bit is 1
jz L2 ;jump below if '0'
mov es:[di],dl ;write a '1'
jmp short L3 ;jump ahead
L2: mov es:[di],dh ;write a '0'
L3: shl bx,1 ;shift mask by 1 bit
loop L1 ;go do the next digit
dec _error_code ;0 = no error
L4: pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_char_field_string ENDP
_TEXT ENDS
END