source: xtideuniversalbios/trunk/Assembly_Library/Src/Util/Memory.asm @ 52

Last change on this file since 52 was 52, checked in by aitotat, 14 years ago

Changes to Assembly Library:
Completely rewritten line splitting (slower but no need to modify string).
Some changes to string processing functions.
Saved few bytes from CGA detection.

File size: 4.8 KB
Line 
1; File name     :   Memory.asm
2; Project name  :   Assembly Library
3; Created date  :   14.7.2010
4; Last update   :   11.10.2010
5; Author        :   Tomi Tilli
6; Description   :   Functions for memory access.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; OPTIMIZE_STRING_OPERATION
13;   Parameters
14;       %1:     Repeat instruction
15;       %2:     String instruction without size (for example MOVS and not MOVSB or MOVSW)
16;       CX:     Number of BYTEs to operate
17;       DS:SI:  Ptr to source data
18;       ES:DI:  Ptr to destination
19;   Returns:
20;       SI, DI: Updated by number of bytes operated
21;   Corrupts registers:
22;       Nothing
23;--------------------------------------------------------------------
24%macro OPTIMIZE_STRING_OPERATION 2
25    push    cx
26
27    shr     cx, 1           ; Operate with WORDs for performance
28    jcxz    %%HandleRemainingByte
29    %1      %2w
30%%HandleRemainingByte:
31    jnc     SHORT %%OperationCompleted
32    %2b
33
34ALIGN JUMP_ALIGN
35%%OperationCompleted:
36    pop     cx
37%endmacro
38
39
40;--------------------------------------------------------------------
41; Memory_CopyCXbytesFromDSSItoESDI
42;   Parameters
43;       CX:     Number of bytes to copy
44;       DS:SI:  Ptr to source data
45;       ES:DI:  Ptr to destination buffer
46;   Returns:
47;       SI, DI: Updated by number of bytes copied
48;   Corrupts registers:
49;       Nothing
50;--------------------------------------------------------------------
51ALIGN JUMP_ALIGN
52Memory_CopyCXbytesFromDSSItoESDI:
53    OPTIMIZE_STRING_OPERATION rep, movs
54    ret
55
56
57;--------------------------------------------------------------------
58; Memory_ZeroSSBPwithSizeInCX
59;   Parameters
60;       CX:     Number of bytes to zero
61;       SS:BP:  Ptr to buffer to zero
62;   Returns:
63;       Nothing
64;   Corrupts registers:
65;       Nothing
66;--------------------------------------------------------------------
67ALIGN JUMP_ALIGN
68Memory_ZeroSSBPwithSizeInCX:
69    push    es
70    push    di
71    push    ax
72    call    Memory_CopySSBPtoESDI
73    call    Memory_ZeroESDIwithSizeInCX
74    pop     ax
75    pop     di
76    pop     es
77    ret
78
79;--------------------------------------------------------------------
80; Memory_ZeroESDIwithSizeInCX
81;   Parameters
82;       CX:     Number of bytes to zero
83;       ES:DI:  Ptr to destination buffer
84;   Returns:
85;       DI:     Updated by number of BYTEs stored
86;   Corrupts registers:
87;       AX
88;--------------------------------------------------------------------
89ALIGN JUMP_ALIGN
90Memory_ZeroESDIwithSizeInCX:
91    xor     ax, ax
92    ; Fall to Memory_StoreCXbytesFromAccumToESDI
93
94;--------------------------------------------------------------------
95; Memory_StoreCXbytesFromAccumToESDI
96;   Parameters
97;       AX:     Word to use to fill buffer
98;       CX:     Number of BYTEs to store
99;       ES:DI:  Ptr to destination buffer
100;   Returns:
101;       DI:     Updated by number of BYTEs stored
102;   Corrupts registers:
103;       Nothing
104;--------------------------------------------------------------------
105ALIGN JUMP_ALIGN
106Memory_StoreCXbytesFromAccumToESDI:
107    OPTIMIZE_STRING_OPERATION rep, stos
108    ret
109
110
111;--------------------------------------------------------------------
112; Memory_ExchangeDSSIwithESDI
113;   Parameters
114;       Nothing
115;   Returns:
116;       DS:SI and ES:DI are exchanged.
117;   Corrupts registers:
118;       Nothing
119;--------------------------------------------------------------------
120ALIGN JUMP_ALIGN
121Memory_ExchangeDSSIwithESDI:
122    push    ds
123    push    es
124    pop     ds
125    pop     es
126    xchg    si, di
127    ret
128
129
130;--------------------------------------------------------------------
131; Memory_CopySSBPtoESDI
132; Memory_CopySSBPtoDSSI
133; Memory_CopyDSSItoESDI
134; Memory_CopyESDItoDSSI
135;   Parameters
136;       Nothing
137;   Returns:
138;       Copies farm pointer to different segment/pointer register pair
139;   Corrupts registers:
140;       Nothing
141;--------------------------------------------------------------------
142ALIGN JUMP_ALIGN
143Memory_CopySSBPtoESDI:
144    push    ss
145    pop     es
146    mov     di, bp
147    ret
148
149ALIGN JUMP_ALIGN
150Memory_CopySSBPtoDSSI:
151    push    ss
152    pop     ds
153    mov     si, bp
154    ret
155
156ALIGN JUMP_ALIGN
157Memory_CopyDSSItoESDI:
158    push    ds
159    pop     es
160    mov     di, si
161    ret
162
163ALIGN JUMP_ALIGN
164Memory_CopyESDItoDSSI:
165    push    es
166    pop     ds
167    mov     si, di
168    ret
169
170
171;--------------------------------------------------------------------
172; Memory_SetZFifNullPointerInDSSI
173;   Parameters
174;       DS:SI:  Far pointer
175;   Returns:
176;       ZF:     Set if NULL pointer in DS:SI
177;   Corrupts registers:
178;       Nothing
179;--------------------------------------------------------------------
180ALIGN JUMP_ALIGN
181Memory_SetZFifNullPointerInDSSI:
182    push    ax
183    mov     ax, ds
184    or      ax, si
185    pop     ax
186    ret
187
188
189;--------------------------------------------------------------------
190; Memory_ReserveCXbytesFromStackToDSSI
191;   Parameters
192;       CX:     Number of bytes to reserve
193;   Returns:
194;       DS:SI:  Ptr to reserved buffer
195;   Corrupts registers:
196;       AX
197;--------------------------------------------------------------------
198ALIGN JUMP_ALIGN
199Memory_ReserveCXbytesFromStackToDSSI:
200    pop     ax
201    push    ss
202    pop     ds
203    sub     sp, cx
204    mov     si, sp
205    jmp     ax
Note: See TracBrowser for help on using the repository browser.