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

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

Changes to all parts of the project:

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