source: xtideuniversalbios/trunk/Assembly_Library/Src/Util/Bit.asm@ 114

Last change on this file since 114 was 103, checked in by krille_n_@…, 14 years ago

Optimizations to Assembly Library.

File size: 2.1 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for bit handling.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Bit_GetSetCountToCXfromDXAX
9; Parameters
10; DX:AX: Source DWORD
11; Returns:
12; CX: Number of bits set in DX:AX
13; Corrupts registers:
14; Nothing
15;--------------------------------------------------------------------
16ALIGN JUMP_ALIGN
17Bit_GetSetCountToCXfromDXAX:
18 push bx
19
20 call Bit_GetSetCountToCXfromAX
21 mov bx, cx
22 xchg ax, dx
23 call Bit_GetSetCountToCXfromAX
24 xchg ax, dx
25 add cx, bx
26
27 pop bx
28 ret
29
30
31;--------------------------------------------------------------------
32; Bit_GetSetCountToCXfromAX
33; Parameters
34; AX: Source WORD
35; Returns:
36; CX: Number of bits set in AX
37; Corrupts registers:
38; Nothing
39;--------------------------------------------------------------------
40ALIGN JUMP_ALIGN
41Bit_GetSetCountToCXfromAX:
42 push ax
43
44 xor cx, cx
45ALIGN JUMP_ALIGN
46.BitScanLoop:
47 shr ax, 1
48 jz SHORT .LastBitInCF
49 adc cl, ch
50 jmp SHORT .BitScanLoop
51ALIGN JUMP_ALIGN
52.LastBitInCF:
53 adc cl, ch
54
55 pop ax
56 ret
57
58
59;--------------------------------------------------------------------
60; Bit_SetToDXAXfromIndexInCL
61; Parameters:
62; CL: Index of bit to set (0...31)
63; DX:AX: Destination DWORD with flag to be set
64; Returns:
65; DX:AX: DWORD with wanted bit set
66; Corrupts registers:
67; Nothing
68;--------------------------------------------------------------------
69ALIGN JUMP_ALIGN
70Bit_SetToDXAXfromIndexInCL:
71 cmp cl, 16
72 jb SHORT Bit_SetToAXfromIndexInCL
73
74 sub cl, 16
75 xchg ax, dx
76 call Bit_SetToAXfromIndexInCL
77 xchg dx, ax
78 add cl, 16
79 ret
80
81;--------------------------------------------------------------------
82; Bit_SetToAXfromIndexInCL
83; Parameters:
84; CL: Index of bit to set (0...15)
85; AX: Destination WORD with flag to be set
86; Returns:
87; AX: WORD with wanted bit set
88; Corrupts registers:
89; Nothing
90;--------------------------------------------------------------------
91ALIGN JUMP_ALIGN
92Bit_SetToAXfromIndexInCL:
93 push dx
94
95 mov dx, 1
96 shl dx, cl
97 or ax, dx
98
99 pop dx
100 ret
Note: See TracBrowser for help on using the repository browser.