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

Last change on this file since 131 was 131, checked in by aitotat, 13 years ago

Changes to Assembly Library:

  • Some functions are now excluded from XTIDE Universal BIOS with EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS define.
File size: 3.2 KB
Line 
1; Project name  :   Assembly Library
2; Description   :   Functions for memory access.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; OPTIMIZE_STRING_OPERATION
9;   Parameters
10;       %1:     Repeat instruction
11;       %2:     String instruction without size (for example MOVS and not MOVSB or MOVSW)
12;       CX:     Number of BYTEs to operate
13;       DS:SI:  Ptr to source data
14;       ES:DI:  Ptr to destination
15;   Returns:
16;       SI, DI: Updated by number of bytes operated
17;   Corrupts registers:
18;       Nothing
19;--------------------------------------------------------------------
20%macro OPTIMIZE_STRING_OPERATION 2
21    push    cx
22
23    shr     cx, 1           ; Operate with WORDs for performance
24    jz  %%HandleRemainingByte
25    %1      %2w
26%%HandleRemainingByte:
27    jnc     SHORT %%OperationCompleted
28    %2b
29
30ALIGN JUMP_ALIGN
31%%OperationCompleted:
32    pop     cx
33%endmacro
34
35
36;--------------------------------------------------------------------
37; Memory_CopyCXbytesFromDSSItoESDI
38;   Parameters
39;       CX:     Number of bytes to copy
40;       DS:SI:  Ptr to source data
41;       ES:DI:  Ptr to destination buffer
42;   Returns:
43;       SI, DI: Updated by number of bytes copied
44;   Corrupts registers:
45;       Nothing
46;--------------------------------------------------------------------
47%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
48ALIGN JUMP_ALIGN
49Memory_CopyCXbytesFromDSSItoESDI:
50    OPTIMIZE_STRING_OPERATION rep, movs
51    ret
52%endif
53
54
55;--------------------------------------------------------------------
56; Memory_ZeroSSBPwithSizeInCX
57;   Parameters
58;       CX:     Number of bytes to zero
59;       SS:BP:  Ptr to buffer to zero
60;   Returns:
61;       Nothing
62;   Corrupts registers:
63;       Nothing
64;--------------------------------------------------------------------
65ALIGN JUMP_ALIGN
66Memory_ZeroSSBPwithSizeInCX:
67    push    es
68    push    di
69    push    ax
70    call    Registers_CopySSBPtoESDI
71    call    Memory_ZeroESDIwithSizeInCX
72    pop     ax
73    pop     di
74    pop     es
75    ret
76
77;--------------------------------------------------------------------
78; Memory_ZeroESDIwithSizeInCX
79;   Parameters
80;       CX:     Number of bytes to zero
81;       ES:DI:  Ptr to destination buffer
82;   Returns:
83;       DI:     Updated by number of BYTEs stored
84;   Corrupts registers:
85;       AX
86;--------------------------------------------------------------------
87ALIGN JUMP_ALIGN
88Memory_ZeroESDIwithSizeInCX:
89    xor     ax, ax
90    ; Fall to Memory_StoreCXbytesFromAccumToESDI
91
92;--------------------------------------------------------------------
93; Memory_StoreCXbytesFromAccumToESDI
94;   Parameters
95;       AX:     Word to use to fill buffer
96;       CX:     Number of BYTEs to store
97;       ES:DI:  Ptr to destination buffer
98;   Returns:
99;       DI:     Updated by number of BYTEs stored
100;   Corrupts registers:
101;       Nothing
102;--------------------------------------------------------------------
103ALIGN JUMP_ALIGN
104Memory_StoreCXbytesFromAccumToESDI:
105    OPTIMIZE_STRING_OPERATION rep, stos
106    ret
107
108
109;--------------------------------------------------------------------
110; Memory_ReserveCXbytesFromStackToDSSI
111;   Parameters
112;       CX:     Number of bytes to reserve
113;   Returns:
114;       DS:SI:  Ptr to reserved buffer
115;   Corrupts registers:
116;       AX
117;--------------------------------------------------------------------
118ALIGN JUMP_ALIGN
119Memory_ReserveCXbytesFromStackToDSSI:
120    pop     ax
121    push    ss
122    pop     ds
123    sub     sp, cx
124    mov     si, sp
125    jmp     ax
Note: See TracBrowser for help on using the repository browser.