1 ; MMURTL Operating System Source Code
\r
2 ; Copyright 1991,1992,1993,1994 Richard A. Burgess
\r
3 ; ALL RIGHTS RESERVED Version 1.0
\r
7 ;=============================================================================
\r
9 ;=============================================================================
\r
11 ; HextoDD - Converts a text string of Hex chars to a DD
\r
12 ; This converts an ASCII string of hex digits to a DD (3 params)
\r
13 ; 1) 32 bit near ptr to the ASCII Hex String
\r
14 ; 2) The 32 Bit Near Ptr (relative to DS) of returned DD
\r
15 ; 3) DD with count of bytes in string
\r
16 ; This can easily be converted to accept a DF (48 bit Far Ptr)
\r
17 ; EAX returns ercBadString if string supplied was not convertable!
\r
18 ; This only saves segment registers!!!
\r
20 pHexStr EQU DWORD PTR [EBP+10h]
\r
21 pDDOut EQU DWORD PTR [EBP+0Ch]
\r
22 cbHexStr EQU DWORD PTR [EBP+08h]
\r
23 HexTotal EQU DWORD PTR [EBP-04h] ;Local variable
\r
27 MOV ECX,cbHexStr ;how long is the string
\r
28 MOV ESI,pHexStr ;EBX points to str[1]
\r
29 ADD ESI, ECX ;EBX points to str[cbStr] (LSD)
\r
30 DEC ESI ;Offset of last is p - 1
\r
31 MOV EDI,pDDOut ;prepare to return answer
\r
32 MOV HexTotal, 0 ;start with nothing
\r
33 MOV EBX, 1 ;First mutliplier
\r
38 JB Hex000 ;It's not lower case...
\r
39 AND AL, 01001111b ;make it Upper case
\r
41 CMP AL, 30h ;Less than "0"?
\r
43 SUB AL, 30h ;No, make it a binary number
\r
44 CMP AL, 0Ah ;Is it A-F??
\r
46 SUB AL, 07h ;Yes, make it a number
\r
48 MUL EBX ;TIMES multiplier
\r
49 ADD EAX, HexTotal ;add to total
\r
51 SHL EBX, 4 ;increase mutiplier TIMES 16
\r
59 MOV EAX, ercBadString
\r
64 ;=============================================================================
\r
67 ; This converts an ASCII string of Decimal digits to a DD (3 params)
\r
68 ; 1) 32 bit near ptr to the ASCII Decimal String
\r
69 ; 2) The 32 Bit Near Ptr (relative to DS) of returned DD
\r
70 ; 3) DD with count of bytes in string
\r
71 ; EAX returns ercBadString if string supplied was not convertable!
\r
73 ;=============================================================================
\r
75 pDecStr EQU DWORD PTR [EBP+16]
\r
76 pDDOut1 EQU DWORD PTR [EBP+12]
\r
77 cbDecStr EQU DWORD PTR [EBP+08]
\r
78 DecTotal EQU DWORD PTR [EBP-04]
\r
82 MOV ECX,cbDecStr ;how long is the string
\r
83 MOV ESI,pDecStr ;EBX points to str[1]
\r
84 ADD ESI, ECX ;EBX points to str[cbStr] (LSD)
\r
85 DEC ESI ;Offset of last is p - 1
\r
86 MOV EDI,pDDOut1 ;prepare to return answer
\r
87 MOV DecTotal, 0 ;start with nothing
\r
88 MOV EBX, 1 ;First mutliplier
\r
93 JA BadDec ;It's not lower case...
\r
95 CMP AL, 30h ;Less than "0"?
\r
97 SUB AL, 30h ;No, make it a binary number
\r
98 MUL EBX ;TIMES multiplier
\r
99 ADD EAX, DecTotal ;add to total
\r
102 MUL EBX ;increase mutiplier TIMES 10
\r
111 MOV EAX, ercBadString
\r
116 ;=============================================================================
\r
119 ; This converts a DD to an 8 Byte ASCII String in Hex (2 params)
\r
120 ; 1) the DD to convert
\r
121 ; 2) The 32 Bit Near Ptr (relative to DS) of returned string
\r
123 ;=============================================================================
\r
125 DDin EQU DWORD PTR [EBP+0Ch]
\r
126 pStrOut EQU DWORD PTR [EBP+08h]
\r
137 MOV BH,30h ;0 in ASCII
\r
152 ;=============================================================================
\r
155 ; This converts a DD to a 10 Byte ASCII DECIMAL String (2 params)
\r
156 ; 1) the DD to convert
\r
157 ; 2) The 32 Bit Near Ptr (relative to DS) of returned string
\r
158 ; This can easily be converted to accept a DF (48 bit Far Ptr)
\r
160 ;=============================================================================
\r
162 DDinD EQU DWORD PTR [EBP+0Ch]
\r
163 pStrOutD EQU DWORD PTR [EBP+08h]
\r
168 MOV ESI,DDin ;ESI has what's left of DD
\r
171 MOV EBX, 1000000000 ;A billion (exactly...DUH)
\r
172 MOV AL, 30h ;A zero (ASCII)
\r
175 JB DDtoDec1 ;Go for the next digit
\r
180 MOV [EDI], AL ;Give them this byte
\r
181 INC EDI ;setup for next byte in string
\r
182 XOR EDX,EDX ;Div EBX by 10 put back in EBX
\r
187 MOV AL, 30h ;start with zero again
\r
188 LOOP DDtoDec0 ;Go back for more
\r
193 ;============ End of Module ==================
\r