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

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

Changes to Assembly Library:
Sorting now works (pivot item is copied for comparison and index comparisons are now signed instead of unsigned).
Menu shadow now looks better on black and white modes.
Sorting is now implemented for File Fialog: directories are displayed before files.
File Dialog now displays directories with upper case letters and files with lower case letters.
Line splitter now removes all empty lines from the end.

File size: 4.5 KB
Line 
1; File name     :   Memory.asm
2; Project name  :   Assembly Library
3; Created date  :   14.7.2010
4; Last update   :   1.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    ax
70
71    call    Memory_ExchangeSSBPwithESDI
72    call    Memory_ZeroESDIwithSizeInCX
73    call    Memory_ExchangeSSBPwithESDI
74
75    pop     ax
76    ret
77
78;--------------------------------------------------------------------
79; Memory_ZeroESDIwithSizeInCX
80;   Parameters
81;       CX:     Number of bytes to zero
82;       ES:DI:  Ptr to destination buffer
83;   Returns:
84;       Nothing
85;   Corrupts registers:
86;       AX
87;--------------------------------------------------------------------
88ALIGN JUMP_ALIGN
89Memory_ZeroESDIwithSizeInCX:
90    xor     ax, ax
91    ; Fall to Memory_StoreCXbytesFromAccumToESDI
92
93;--------------------------------------------------------------------
94; Memory_StoreCXbytesFromAccumToESDI
95;   Parameters
96;       AX:     Word to use to fill buffer
97;       CX:     Number of BYTEs to store
98;       ES:DI:  Ptr to destination buffer
99;   Returns:
100;       Nothing
101;   Corrupts registers:
102;       Nothing
103;--------------------------------------------------------------------
104ALIGN JUMP_ALIGN
105Memory_StoreCXbytesFromAccumToESDI:
106    OPTIMIZE_STRING_OPERATION rep, stos
107    sub     di, cx
108    ret
109
110
111;--------------------------------------------------------------------
112; Memory_ExchangeSSBPwithESDI
113; Memory_ExchangeDSSIwithESDI
114;   Parameters
115;       Nothing
116;   Returns:
117;       SS:BP/DS:SI and ES:DI are exchanged.
118;   Corrupts registers:
119;       Nothing
120;--------------------------------------------------------------------
121ALIGN JUMP_ALIGN
122Memory_ExchangeSSBPwithESDI:
123    xchg    bp, di
124    push    ss
125    push    es
126    pop     ss
127    pop     es
128    ret
129
130ALIGN JUMP_ALIGN
131Memory_ExchangeDSSIwithESDI:
132    xchg    si, di
133    push    ds
134    push    es
135    pop     ds
136    pop     es
137    ret
138
139
140;--------------------------------------------------------------------
141; Memory_CopySSBPtoESDI
142;   Parameters
143;       Nothing
144;   Returns:
145;       ES:DI:      Same as SS:BP
146;   Corrupts registers:
147;       Nothing
148;--------------------------------------------------------------------
149ALIGN JUMP_ALIGN
150Memory_CopySSBPtoESDI:
151    push    ss
152    pop     es
153    mov     di, bp
154    ret
155
156
157;--------------------------------------------------------------------
158; Memory_SetZFifNullPointerInDSSI
159;   Parameters
160;       DS:SI:  Far pointer
161;   Returns:
162;       ZF:     Set if NULL pointer in DS:SI
163;   Corrupts registers:
164;       Nothing
165;--------------------------------------------------------------------
166ALIGN JUMP_ALIGN
167Memory_SetZFifNullPointerInDSSI:
168    push    ax
169    mov     ax, ds
170    or      ax, si
171    pop     ax
172    ret
173
174
175;--------------------------------------------------------------------
176; Memory_ReserveCXbytesFromStackToDSSI
177;   Parameters
178;       CX:     Number of bytes to reserve
179;   Returns:
180;       DS:SI:  Ptr to reserved buffer
181;   Corrupts registers:
182;       AX
183;--------------------------------------------------------------------
184ALIGN JUMP_ALIGN
185Memory_ReserveCXbytesFromStackToDSSI:
186    pop     ax
187    push    ss
188    pop     ds
189    sub     sp, cx
190    mov     si, sp
191    jmp     ax
Note: See TracBrowser for help on using the repository browser.