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

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

Minor size optimizations to all parts of the project (even the old Configurator).
Also added a new 'release' option to the makefiles of both versions of the Configurator. It invokes UPX and makes the Configurator programs ridiculously tiny.

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'-'0'-10 ; Convert to hexadecimal integer
119ALIGN JUMP_ALIGN
120.ConvertToDecimalDigit:
121 sub al, '0' ; Convert to decimal integer
122 ; Fall to CharIsValid
123
124;--------------------------------------------------------------------
125; CharIsValid
126; CharIsNotValid
127; Parameters:
128; Nothing
129; Returns:
130; CF: Set for CharIsValid
131; Cleared for CharIsNotValid
132; Corrupts registers:
133; Nothing
134;--------------------------------------------------------------------
135ALIGN JUMP_ALIGN
136Char_CharIsValid:
137 stc
138 ret
139
140ALIGN JUMP_ALIGN
141CharIsNotValid:
142 clc
143 ret
144
145
146;--------------------------------------------------------------------
147; Char_ALtoLowerCaseLetter
148; Parameters:
149; AL: Character to convert
150; Returns:
151; AL: Character with possible conversion
152; Corrupts registers:
153; Nothing
154;--------------------------------------------------------------------
155ALIGN JUMP_ALIGN
156Char_ALtoLowerCaseLetter:
157 call Char_IsUpperCaseLetterInAL ; Is upper case character?
158 jnc SHORT .Return ; If not, return
159 add al, 'a'-'A' ; Convert to lower case
160.Return:
161 ret
162
163;--------------------------------------------------------------------
164; Char_ALtoUpperCaseLetter
165; Parameters:
166; AL: Character to convert
167; Returns:
168; AL: Character with possible conversion
169; Corrupts registers:
170; Nothing
171;--------------------------------------------------------------------
172ALIGN JUMP_ALIGN
173Char_ALtoUpperCaseLetter:
174 call Char_IsLowerCaseLetterInAL ; Is lower case character?
175 jnc SHORT .Return ; If not, return
176 sub al, 'a'-'A' ; Convert to upper case
177.Return:
178 ret
179
180
181;--------------------------------------------------------------------
182; Char_GetFilterFunctionToDXforNumericBaseInBX
183; Parameters
184; BX: Numeric base (10 or 16)
185; Returns:
186; CS:DX: Ptr to character filter function
187; Corrupts registers:
188; Nothing
189;--------------------------------------------------------------------
190ALIGN JUMP_ALIGN
191Char_GetFilterFunctionToDXforNumericBaseInBX:
192 mov dx, Char_IsDecimalDigitInAL
193 cmp bl, 10
194 je SHORT .Return
195 sub dx, BYTE Char_IsDecimalDigitInAL - Char_IsHexadecimalDigitInAL
196.Return:
197 ret
Note: See TracBrowser for help on using the repository browser.