home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
BITS.ASM
/
INTFIELD.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
1KB
|
50 lines
;unsigned short int_field(value,start_bit,number_bits);
; unsigned short value;
; unsigned char start_bit,number_bits;
EXTRN _memory_model:byte
EXTRN _error_code:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _int_field
_int_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,15 ;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,16 ;fits in the byte?
ja L1 ;quit if not
mov cx,16 ;from 16 bits...
sub cx,bx ;subtract number of bits
sub cx,dx ;subtract starting bit
mov ax,[bp+4] ;get the integer
shl ax,cl ;shift field to high end
add cx,dx ;prepare to shift back
shr ax,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
_int_field ENDP
_TEXT ENDS
END