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

Last change on this file since 67 was 41, checked in by Tomi Tilli, 14 years ago

Initial commit for Assembly Library.

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