source: xtideuniversalbios/trunk/Assembly_Library/Src/String/Char.asm@ 129

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

Initial commit for Assembly Library.

File size: 5.6 KB
Line 
1; File name : Char.asm
2; Project name : Assembly Library
3; Created date : 28.6.2010
4; Last update : 7.9.2010
5; Author : Tomi Tilli
6; Description : Functions for handling characters.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; This macro can only be used within this source file!!!
13; IS_BETWEEN_IMMEDIATES
14; Parameters:
15; %1: Value to check
16; %2: First accepted value in range
17; %3: Last accepted value in range
18; Returns:
19; CF: Set if character is range
20; (Jumps to CharIsNotValid if before range)
21; Corrupts registers:
22; Nothing
23;--------------------------------------------------------------------
24%macro IS_BETWEEN_IMMEDIATES 3
25 cmp %1, %2
26 jb SHORT CharIsNotValid
27 cmp %1, (%3)+1 ; Set CF if %1 is lesser
28%endmacro
29
30
31;--------------------------------------------------------------------
32; Char_IsLowerCaseLetterInAL
33; Parameters:
34; AL: Character to check
35; Returns:
36; CF: Set if character is lower case letter ('a'...'z')
37; Cleared if character is not lower case letter
38; Corrupts registers:
39; Nothing
40;--------------------------------------------------------------------
41ALIGN JUMP_ALIGN
42Char_IsLowerCaseLetterInAL:
43 IS_BETWEEN_IMMEDIATES al, 'a', 'z'
44 ret
45
46;--------------------------------------------------------------------
47; Char_IsUpperCaseLetterInAL
48; Parameters:
49; AL: Character to check
50; Returns:
51; CF: Set if character is upper case letter ('A'...'Z')
52; Cleared if character is not upper case letter
53; Corrupts registers:
54; Nothing
55;--------------------------------------------------------------------
56ALIGN JUMP_ALIGN
57Char_IsUpperCaseLetterInAL:
58 IS_BETWEEN_IMMEDIATES al, 'A', 'Z'
59 ret
60
61;--------------------------------------------------------------------
62; Char_IsHexadecimalDigitInAL
63; Parameters:
64; AL: Character to check
65; Returns:
66; AL: Character converted to lower case
67; CF: Set if character is decimal digit ('0'...'F')
68; Cleared if character is not decimal digit
69; Corrupts registers:
70; Nothing
71;--------------------------------------------------------------------
72ALIGN JUMP_ALIGN
73Char_IsHexadecimalDigitInAL:
74 call Char_IsDecimalDigitInAL
75 jc SHORT Char_CharIsValid
76 call Char_ALtoLowerCaseLetter
77 IS_BETWEEN_IMMEDIATES al, 'a', 'f'
78 ret
79
80;--------------------------------------------------------------------
81; Char_IsDecimalDigitInAL
82; Parameters:
83; AL: Character to check
84; Returns:
85; CF: Set if character is decimal digit ('0'...'9')
86; Cleared if character is not decimal digit
87; Corrupts registers:
88; Nothing
89;--------------------------------------------------------------------
90ALIGN JUMP_ALIGN
91Char_IsDecimalDigitInAL:
92 IS_BETWEEN_IMMEDIATES al, '0', '9'
93 ret
94
95
96;--------------------------------------------------------------------
97; Char_ConvertIntegerToALfromDigitInALwithBaseInBX
98; Parameters:
99; AL: Character to convert
100; BX: Numeric base (10 or 16)
101; Returns:
102; AL: Character converted to integer
103; CF: Set if character was valid
104; Cleared if character was invalid
105; Corrupts registers:
106; Nothing
107;--------------------------------------------------------------------
108ALIGN JUMP_ALIGN
109Char_ConvertIntegerToALfromDigitInALwithBaseInBX:
110 push dx
111 call Char_GetFilterFunctionToDXforNumericBaseInBX
112 call dx ; Converts to lower case
113 pop dx
114 jnc SHORT CharIsNotValid
115
116 cmp al, '9' ; Decimal digit
117 jbe SHORT .ConvertToDecimalDigit
118 sub al, 'a'-10 ; Convert to hexadecimal integer
119 stc
120 ret
121ALIGN JUMP_ALIGN
122.ConvertToDecimalDigit:
123 sub al, '0' ; Convert to decimal integer
124 ; Fall to CharIsValid
125
126;--------------------------------------------------------------------
127; CharIsValid
128; CharIsNotValid
129; Parameters:
130; Nothing
131; Returns:
132; CF: Set for CharIsValid
133; Cleared for CharIsNotValid
134; Corrupts registers:
135; Nothing
136;--------------------------------------------------------------------
137ALIGN JUMP_ALIGN
138Char_CharIsValid:
139 stc
140 ret
141
142ALIGN JUMP_ALIGN
143CharIsNotValid:
144 clc
145 ret
146
147
148;--------------------------------------------------------------------
149; Char_ALtoLowerCaseLetter
150; Parameters:
151; AL: Character to convert
152; Returns:
153; AL: Character with possible conversion
154; Corrupts registers:
155; Nothing
156;--------------------------------------------------------------------
157ALIGN JUMP_ALIGN
158Char_ALtoLowerCaseLetter:
159 call Char_IsUpperCaseLetterInAL ; Is upper case character?
160 jnc SHORT .Return ; If not, return
161 add al, 'a'-'A' ; Convert to lower case
162.Return:
163 ret
164
165;--------------------------------------------------------------------
166; Char_ALtoUpperCaseLetter
167; Parameters:
168; AL: Character to convert
169; Returns:
170; AL: Character with possible conversion
171; Corrupts registers:
172; Nothing
173;--------------------------------------------------------------------
174ALIGN JUMP_ALIGN
175Char_ALtoUpperCaseLetter:
176 call Char_IsLowerCaseLetterInAL ; Is lower case character?
177 jnc SHORT .Return ; If not, return
178 sub al, 'a'-'A' ; Convert to upper case
179.Return:
180 ret
181
182
183;--------------------------------------------------------------------
184; Char_GetFilterFunctionToDXforNumericBaseInBX
185; Parameters
186; BX: Numeric base (10 or 16)
187; Returns:
188; CS:DX: Ptr to character filter function
189; Corrupts registers:
190; Nothing
191;--------------------------------------------------------------------
192ALIGN JUMP_ALIGN
193Char_GetFilterFunctionToDXforNumericBaseInBX:
194 mov dx, Char_IsDecimalDigitInAL
195 cmp bl, 10
196 je SHORT .Return
197 sub dx, BYTE Char_IsDecimalDigitInAL - Char_IsHexadecimalDigitInAL
198.Return:
199 ret
Note: See TracBrowser for help on using the repository browser.