Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1186 savelij 1
		ifndef   bitfuncsinc    ; avoid multiple inclusion
2
bitfuncsinc     equ      1
3
 
4
                save
5
                listing off   ; no listing over this file
6
 
7
;****************************************************************************
8
;*                                                                          *
9
;*   AS 1.42 - File BITFUNCS.INC                                            *
10
;*   								            *
11
;*   Contains Functions For Bit Manipulation                                *
12
;*									    *
13
;****************************************************************************
14
 
15
		if	 mompass=1
16
		 message "Standard Bit Manipulation Functions (C) 1993 Alfred Arnold"
17
		endif
18
 
19
;----------------------------------------------------------------------------
20
; some sub-functions for a start:
21
 
22
; delivers a mask with 'bits' bits set, starting at position 'start', used for
23
; masking individual bits:
24
 
25
mask            function start,bits,((1<<bits)-1)<<start
26
 
27
; the same in inverted form to clear bit groups:
28
 
29
invmask         function start,bits,~mask(start,bits)
30
 
31
; delivers the bits from 'start' to 'start'+'bits'-1 from 'x':
32
 
33
cutout          function x,start,bits,x&mask(start,bits)
34
 
35
;----------------------------------------------------------------------------
36
; some commonly used bit masks:
37
 
38
; upper byte of a 16 bit word:
39
 
40
hi              function x,(x>>8)&255
41
 
42
; the same for the lower byte:
43
 
44
lo              function x,x&255
45
 
46
; upper half of a 32 bit word:
47
 
48
hiword          function x,(x>>16)&65535
49
 
50
; the same for the lower half:
51
 
52
loword          function x,x&65535
53
 
54
; boolean functions, whether a number is odd or even::
55
 
56
odd             function x,(x&1)=1
57
even            function x,(x&1)=0
58
 
59
; delivers bit 'n' from 'x':
60
 
61
getbit          function x,n,(x>>n)&1
62
 
63
;----------------------------------------------------------------------------
64
; Shift Functions:
65
 
66
; Shift a word of 'size' bits by 'n' positions to the left or right:
67
 
68
shln            function x,size,n,(x<<n)&mask(0,size)
69
shrn            function x,size,n,(x>>n)&mask(0,size-n)
70
 
71
; Rotate a word of 'size' bits by 'n' positions to the left or right;
72
; the first sub-term leaves the remaining bits unchanged and may be deleted if undesired:
73
 
74
rotln           function x,size,n,cutout(x,size,32-size)|shln(x,size,n)|shrn(x,size,size-n)
75
rotrn           function x,size,n,cutout(x,size,32-size)|shrn(x,size,n)|shln(x,size,size-n)
76
 
77
                restore                 ; allow listing again
78
 
79
                endif			; bitfuncsinc
80