1 | ; File name : String.asm |
---|
2 | ; Project name : Assembly Library |
---|
3 | ; Created date : 12.7.2010 |
---|
4 | ; Last update : 1.10.2010 |
---|
5 | ; Author : Tomi Tilli |
---|
6 | ; Description : Functions for handling characters. |
---|
7 | |
---|
8 | ; Section containing code |
---|
9 | SECTION .text |
---|
10 | |
---|
11 | ;-------------------------------------------------------------------- |
---|
12 | ; String_ConvertWordToAXfromStringInDSSIwithBaseInBX |
---|
13 | ; Parameters: |
---|
14 | ; BX: Numeric base (10 or 16) |
---|
15 | ; DS:SI: Ptr to string to convert |
---|
16 | ; Returns: |
---|
17 | ; AX: Word converted from string |
---|
18 | ; DI: Offset to NULL or first invalid character |
---|
19 | ; CF: Set if conversion successfull |
---|
20 | ; Cleared if invalid string |
---|
21 | ; Corrupts registers: |
---|
22 | ; DX |
---|
23 | ;-------------------------------------------------------------------- |
---|
24 | ALIGN JUMP_ALIGN |
---|
25 | String_ConvertWordToAXfromStringInDSSIwithBaseInBX: |
---|
26 | xor dx, dx |
---|
27 | cld |
---|
28 | |
---|
29 | ALIGN JUMP_ALIGN |
---|
30 | .ConvertWordToAXfromStringInDSSIwithBaseInBX: |
---|
31 | lodsb ; Load character from DS:SI to AL |
---|
32 | call Char_ConvertIntegerToALfromDigitInALwithBaseInBX |
---|
33 | jnc SHORT .InvalidCharacter |
---|
34 | xor ah, ah |
---|
35 | push ax ; Push integer |
---|
36 | xchg ax, dx ; Copy WORD to AX |
---|
37 | mul bx ; DX:AX = word in AX * base in BX |
---|
38 | pop dx ; Pop integer |
---|
39 | add dx, ax ; WORD back to DX |
---|
40 | jmp SHORT .ConvertWordToAXfromStringInDSSIwithBaseInBX |
---|
41 | |
---|
42 | ALIGN JUMP_ALIGN |
---|
43 | .InvalidCharacter: |
---|
44 | sub al, 1 ; Set CF if NULL character, clear CF otherwise |
---|
45 | xchg ax, dx ; Return WORD in AX |
---|
46 | ret |
---|
47 | |
---|
48 | |
---|
49 | ;-------------------------------------------------------------------- |
---|
50 | ; String_CopyToESDIfromDSSIwithoutTerminatingESDI |
---|
51 | ; Parameters: |
---|
52 | ; DS:SI: Ptr to source NULL terminated string |
---|
53 | ; ES:DI: Ptr to destination buffer |
---|
54 | ; Returns: |
---|
55 | ; CX: Number of characters copied |
---|
56 | ; SI,DI: Updated by CX characters |
---|
57 | ; Corrupts registers: |
---|
58 | ; Nothing |
---|
59 | ;-------------------------------------------------------------------- |
---|
60 | ALIGN JUMP_ALIGN |
---|
61 | String_CopyToESDIfromDSSIwithoutTerminatingESDI: |
---|
62 | push ax |
---|
63 | xor cx, cx |
---|
64 | |
---|
65 | ALIGN JUMP_ALIGN |
---|
66 | .GetAndStoreNewCharacter: |
---|
67 | lodsb ; Load from DS:SI to AL |
---|
68 | test al, al ; NULL to end string? |
---|
69 | jz SHORT .EndOfString |
---|
70 | stosb ; Store from AL to ES:DI |
---|
71 | inc cx ; Increment number of characters written |
---|
72 | jmp SHORT .GetAndStoreNewCharacter |
---|
73 | |
---|
74 | ALIGN JUMP_ALIGN |
---|
75 | .EndOfString: |
---|
76 | pop ax |
---|
77 | ret |
---|
78 | |
---|
79 | |
---|
80 | ;-------------------------------------------------------------------- |
---|
81 | ; String_ConvertDSSItoLowerCase |
---|
82 | ; Parameters: |
---|
83 | ; DS:SI: Ptr to NULL terminated string to convert |
---|
84 | ; Returns: |
---|
85 | ; Nothing |
---|
86 | ; Corrupts registers: |
---|
87 | ; Nothing |
---|
88 | ;-------------------------------------------------------------------- |
---|
89 | ALIGN JUMP_ALIGN |
---|
90 | String_ConvertDSSItoLowerCase: |
---|
91 | push si |
---|
92 | push ax |
---|
93 | |
---|
94 | ALIGN JUMP_ALIGN |
---|
95 | .ConvertNextCharacter: |
---|
96 | lodsb |
---|
97 | test al, al ; NULL to end string? |
---|
98 | jz SHORT .EndOfString |
---|
99 | call Char_ALtoLowerCaseLetter |
---|
100 | mov [si-1], al |
---|
101 | jmp SHORT .ConvertNextCharacter |
---|
102 | |
---|
103 | ALIGN JUMP_ALIGN |
---|
104 | .EndOfString: |
---|
105 | pop ax |
---|
106 | pop si |
---|
107 | ret |
---|