1 | ; File name : StringProcess.asm |
---|
2 | ; Project name : Assembly Library |
---|
3 | ; Created date : 12.10.2010 |
---|
4 | ; Last update : 7.12.2010 |
---|
5 | ; Author : Tomi Tilli |
---|
6 | ; Description : Functions for processing characters in a string. |
---|
7 | |
---|
8 | ; Section containing code |
---|
9 | SECTION .text |
---|
10 | |
---|
11 | ;-------------------------------------------------------------------- |
---|
12 | ; Character processing callback function prototype for StringProcess_DSSIwithFunctionInDX. |
---|
13 | ; Parameters: |
---|
14 | ; AL: Character to process |
---|
15 | ; CX: Character number (index for next character) |
---|
16 | ; DS:SI: Ptr to next character |
---|
17 | ; BX,DI,ES: Free to use by processing function |
---|
18 | ; Returns: |
---|
19 | ; CF: Clear to continue with next character |
---|
20 | ; Set to stop processing |
---|
21 | ; BX,DI,ES: Free to use by processing function |
---|
22 | ; Corrupts registers: |
---|
23 | ; AX |
---|
24 | ;-------------------------------------------------------------------- |
---|
25 | |
---|
26 | |
---|
27 | ;-------------------------------------------------------------------- |
---|
28 | ; StringProcess_DSSIwithFunctionInDX |
---|
29 | ; Parameters: |
---|
30 | ; DX: Character processing function |
---|
31 | ; DS:SI: Ptr to NULL terminated string to convert |
---|
32 | ; Returns: |
---|
33 | ; CX: Number of characters processed |
---|
34 | ; CF: Clear if all characters processed |
---|
35 | ; Set if terminated by processing function |
---|
36 | ; Corrupts registers: |
---|
37 | ; Nothing (processing function can corrupt BX,DI,ES) |
---|
38 | ;-------------------------------------------------------------------- |
---|
39 | ALIGN JUMP_ALIGN |
---|
40 | StringProcess_DSSIwithFunctionInDX: |
---|
41 | push si |
---|
42 | push ax |
---|
43 | |
---|
44 | xor cx, cx |
---|
45 | ALIGN JUMP_ALIGN |
---|
46 | .ProcessNextCharacter: |
---|
47 | lodsb |
---|
48 | test al, al ; NULL to end string |
---|
49 | jz SHORT .EndOfString ; Return with CF cleared |
---|
50 | inc cx |
---|
51 | call dx |
---|
52 | jnc SHORT .ProcessNextCharacter |
---|
53 | |
---|
54 | ALIGN JUMP_ALIGN |
---|
55 | .EndOfString: |
---|
56 | pop ax |
---|
57 | pop si |
---|
58 | ret |
---|
59 | |
---|
60 | |
---|
61 | ;-------------------------------------------------------------------- |
---|
62 | ; StringProcess_ConvertToLowerCase (callback function for StringProcess_DSSIwithFunctionInDX) |
---|
63 | ; Parameters: |
---|
64 | ; AL: Character to convert to lower case |
---|
65 | ; DS:SI: Ptr to next character |
---|
66 | ; Returns: |
---|
67 | ; CF: Clear to continue processing |
---|
68 | ; Corrupts registers: |
---|
69 | ; AL |
---|
70 | ;-------------------------------------------------------------------- |
---|
71 | ALIGN JUMP_ALIGN |
---|
72 | StringProcess_ConvertToLowerCase: |
---|
73 | call Char_ALtoLowerCaseLetter |
---|
74 | mov [si-1], al |
---|
75 | clc |
---|
76 | ret |
---|
77 | |
---|
78 | |
---|
79 | ;-------------------------------------------------------------------- |
---|
80 | ; StringProcess_ConvertToWordInDIWithBaseInBX (callback function for StringProcess_DSSIwithFunctionInDX) |
---|
81 | ; Parameters: |
---|
82 | ; AL: Character to convert to lower case |
---|
83 | ; BX: Numeric base (2, 10 or 16) |
---|
84 | ; Returns: |
---|
85 | ; CF: Clear to continue processing |
---|
86 | ; Set if error |
---|
87 | ; Corrupts registers: |
---|
88 | ; AX |
---|
89 | ;-------------------------------------------------------------------- |
---|
90 | ALIGN JUMP_ALIGN |
---|
91 | StringProcess_ConvertToWordInDIWithBaseInBX: |
---|
92 | call Char_ConvertIntegerToALfromDigitInALwithBaseInBX |
---|
93 | jnc SHORT .InvalidCharacter |
---|
94 | push dx |
---|
95 | |
---|
96 | xor ah, ah ; Digit converted to integer now in AX |
---|
97 | xchg ax, di |
---|
98 | mul bx ; Old WORD *= base |
---|
99 | jc SHORT .Overflow |
---|
100 | add di, ax ; Add old WORD to new integer |
---|
101 | jc SHORT .Overflow |
---|
102 | |
---|
103 | pop dx |
---|
104 | ret |
---|
105 | .Overflow: |
---|
106 | pop dx |
---|
107 | .InvalidCharacter: |
---|
108 | stc ; Set CF to stop processing |
---|
109 | ret |
---|