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

Last change on this file since 182 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 6.1 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 jmp SHORT Char_ALtoUpperCaseLetter.CheckCF
164%endif
165
166;--------------------------------------------------------------------
167; Char_ALtoUpperCaseLetter
168; Parameters:
169; AL: Character to convert
170; Returns:
171; AL: Character with possible conversion
172; Corrupts registers:
173; Nothing
174;--------------------------------------------------------------------
175ALIGN JUMP_ALIGN
176Char_ALtoUpperCaseLetter:
177 call Char_IsLowerCaseLetterInAL ; Is lower case character?
178.CheckCF:
179 jnc SHORT Char_ChangeCaseInAL.Return
180 ; Fall to Char_ChangeCaseInAL
181
182;--------------------------------------------------------------------
183; Char_ChangeCaseInAL
184; Parameters:
185; AL: Character to convert (must be A-Z or a-z)
186; Returns:
187; AL: Character converted
188; Corrupts registers:
189; Nothing
190;--------------------------------------------------------------------
191Char_ChangeCaseInAL:
192 xor al, 32
193.Return:
194 ret
195
196;--------------------------------------------------------------------
197; Char_GetFilterFunctionToDXforNumericBaseInBX
198; Parameters
199; BX: Numeric base (10 or 16)
200; Returns:
201; CS:DX: Ptr to character filter function
202; Corrupts registers:
203; Nothing
204;--------------------------------------------------------------------
205%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
206ALIGN JUMP_ALIGN
207Char_GetFilterFunctionToDXforNumericBaseInBX:
208 mov dx, Char_IsDecimalDigitInAL
209 cmp bl, 10
210 je SHORT .Return
211 mov dx, Char_IsHexadecimalDigitInAL
212.Return:
213 ret
214%endif
Note: See TracBrowser for help on using the repository browser.