1 | ; File name : String.asm
|
---|
2 | ; Project name : Assembly Library
|
---|
3 | ; Created date : 12.7.2010
|
---|
4 | ; Last update : 12.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 | ; SI: Updated
|
---|
19 | ; CF: Cleared if successfull
|
---|
20 | ; Set if error during conversion
|
---|
21 | ; Corrupts registers:
|
---|
22 | ; Nothing
|
---|
23 | ;--------------------------------------------------------------------
|
---|
24 | ALIGN JUMP_ALIGN
|
---|
25 | String_ConvertWordToAXfromStringInDSSIwithBaseInBX:
|
---|
26 | push di
|
---|
27 | push dx
|
---|
28 |
|
---|
29 | xor di, di
|
---|
30 | mov dx, StringProcess_ConvertToWordInDIWithBaseInBX
|
---|
31 | call StringProcess_DSSIwithFunctionInDX
|
---|
32 | xchg ax, di
|
---|
33 |
|
---|
34 | pop dx
|
---|
35 | pop di
|
---|
36 | ret
|
---|
37 |
|
---|
38 |
|
---|
39 | ;--------------------------------------------------------------------
|
---|
40 | ; String_CopyDSSItoESDIandGetSizeToCX
|
---|
41 | ; Parameters:
|
---|
42 | ; DS:SI: Ptr to source NULL terminated string
|
---|
43 | ; ES:DI: Ptr to destination buffer
|
---|
44 | ; Returns:
|
---|
45 | ; CX: Number of characters copied
|
---|
46 | ; SI,DI: Updated by CX characters
|
---|
47 | ; Corrupts registers:
|
---|
48 | ; Nothing
|
---|
49 | ;--------------------------------------------------------------------
|
---|
50 | ALIGN JUMP_ALIGN
|
---|
51 | String_CopyDSSItoESDIandGetSizeToCX:
|
---|
52 | push ax
|
---|
53 |
|
---|
54 | xor cx, cx
|
---|
55 | ALIGN JUMP_ALIGN
|
---|
56 | .CopyNextCharacter:
|
---|
57 | lodsb ; Load from DS:SI to AL
|
---|
58 | test al, al ; NULL to end string?
|
---|
59 | jz SHORT .EndOfString
|
---|
60 | stosb ; Store from AL to ES:DI
|
---|
61 | inc cx ; Increment number of characters written
|
---|
62 | jmp SHORT .CopyNextCharacter
|
---|
63 |
|
---|
64 | ALIGN JUMP_ALIGN
|
---|
65 | .EndOfString:
|
---|
66 | pop ax
|
---|
67 | ret
|
---|
68 |
|
---|
69 |
|
---|
70 | ;--------------------------------------------------------------------
|
---|
71 | ; String_GetLengthFromDSSItoCX
|
---|
72 | ; Parameters:
|
---|
73 | ; DS:SI: Ptr to NULL terminated string
|
---|
74 | ; Returns:
|
---|
75 | ; CX: String length in characters
|
---|
76 | ; Corrupts registers:
|
---|
77 | ; Nothing
|
---|
78 | ;--------------------------------------------------------------------
|
---|
79 | ALIGN JUMP_ALIGN
|
---|
80 | String_GetLengthFromDSSItoCX:
|
---|
81 | push ax
|
---|
82 | push si
|
---|
83 |
|
---|
84 | call Memory_ExchangeDSSIwithESDI
|
---|
85 | xor ax, ax ; Find NULL
|
---|
86 | mov cx, -1 ; Full segment if necessary
|
---|
87 | repne scasb
|
---|
88 | mov cx, di
|
---|
89 | call Memory_ExchangeDSSIwithESDI
|
---|
90 |
|
---|
91 | pop si
|
---|
92 | stc
|
---|
93 | sbb cx, si ; Subtract NULL
|
---|
94 | pop ax
|
---|
95 | ret
|
---|