home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
CHRFIELD.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
1KB
|
49 lines
;unsigned short char_field(value,start_bit,number_bits);
; unsigned char value,start_bit,number_bits;
EXTRN _memory_model:byte
EXTRN _error_code:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _char_field
_char_field proc near
push bp ;save BP
mov bp,sp ;set 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
sub ax,ax ;clear AX
mov bx,ax ;BX too
mov dx,ax ;DX too
mov bl,[bp+8] ;number of bits
mov dl,[bp+6] ;starting bit
inc _error_code ;1 = bits out of range
cmp dl,7 ;in range?
ja L1 ;quit if not
mov di,dx ;copy start bit
add di,bx ;add number bits
inc _error_code ;2 = field doesn't fit
cmp di,8 ;fits in the byte?
ja L1 ;quit if not
mov cx,8 ;from 8 bits...
sub cx,bx ;subtract number of bits
sub cx,dx ;subtract starting bit
mov al,[bp+4] ;get the byte
shl al,cl ;shift field to high end
add cx,dx ;prepare to shift back
shr al,cl ;shift field to low end
mov _error_code,0 ;0 = success
L1: pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_char_field endp
_TEXT ENDS
END