1 | ; Project name : Assembly Library |
---|
2 | ; Description : Functions for memory access. |
---|
3 | |
---|
4 | ; Section containing code |
---|
5 | SECTION .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 | |
---|
30 | ALIGN 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 |
---|
48 | ALIGN JUMP_ALIGN |
---|
49 | Memory_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 | ;-------------------------------------------------------------------- |
---|
65 | ALIGN JUMP_ALIGN |
---|
66 | Memory_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 | ;-------------------------------------------------------------------- |
---|
87 | ALIGN JUMP_ALIGN |
---|
88 | Memory_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 | ;-------------------------------------------------------------------- |
---|
103 | ALIGN JUMP_ALIGN |
---|
104 | Memory_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 | ;-------------------------------------------------------------------- |
---|
118 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
119 | ALIGN JUMP_ALIGN |
---|
120 | Memory_ReserveCXbytesFromStackToDSSI: |
---|
121 | pop ax |
---|
122 | push ss |
---|
123 | pop ds |
---|
124 | sub sp, cx |
---|
125 | mov si, sp |
---|
126 | jmp ax |
---|
127 | %endif |
---|