[41] | 1 | ; File name : Memory.asm |
---|
| 2 | ; Project name : Assembly Library |
---|
| 3 | ; Created date : 14.7.2010 |
---|
[50] | 4 | ; Last update : 9.10.2010 |
---|
[41] | 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Functions for memory access. |
---|
| 7 | |
---|
| 8 | ; Section containing code |
---|
| 9 | SECTION .text |
---|
| 10 | |
---|
| 11 | ;-------------------------------------------------------------------- |
---|
[46] | 12 | ; OPTIMIZE_STRING_OPERATION |
---|
[41] | 13 | ; Parameters |
---|
[46] | 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 |
---|
[41] | 19 | ; Returns: |
---|
[46] | 20 | ; SI, DI: Updated by number of bytes operated |
---|
| 21 | ; Corrupts registers: |
---|
[41] | 22 | ; Nothing |
---|
[46] | 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 | |
---|
| 34 | ALIGN 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 |
---|
[41] | 48 | ; Corrupts registers: |
---|
[46] | 49 | ; Nothing |
---|
[41] | 50 | ;-------------------------------------------------------------------- |
---|
| 51 | ALIGN JUMP_ALIGN |
---|
[46] | 52 | Memory_CopyCXbytesFromDSSItoESDI: |
---|
| 53 | OPTIMIZE_STRING_OPERATION rep, movs |
---|
| 54 | ret |
---|
[41] | 55 | |
---|
[46] | 56 | |
---|
[41] | 57 | ;-------------------------------------------------------------------- |
---|
[46] | 58 | ; Memory_ZeroSSBPwithSizeInCX |
---|
[41] | 59 | ; Parameters |
---|
[46] | 60 | ; CX: Number of bytes to zero |
---|
[41] | 61 | ; SS:BP: Ptr to buffer to zero |
---|
| 62 | ; Returns: |
---|
| 63 | ; Nothing |
---|
| 64 | ; Corrupts registers: |
---|
| 65 | ; Nothing |
---|
| 66 | ;-------------------------------------------------------------------- |
---|
| 67 | ALIGN JUMP_ALIGN |
---|
[46] | 68 | Memory_ZeroSSBPwithSizeInCX: |
---|
[50] | 69 | push es |
---|
| 70 | push di |
---|
[41] | 71 | push ax |
---|
[50] | 72 | call Memory_CopySSBPtoESDI |
---|
[46] | 73 | call Memory_ZeroESDIwithSizeInCX |
---|
[41] | 74 | pop ax |
---|
[50] | 75 | pop di |
---|
| 76 | pop es |
---|
[41] | 77 | ret |
---|
| 78 | |
---|
| 79 | ;-------------------------------------------------------------------- |
---|
[46] | 80 | ; Memory_ZeroESDIwithSizeInCX |
---|
[41] | 81 | ; Parameters |
---|
[46] | 82 | ; CX: Number of bytes to zero |
---|
| 83 | ; ES:DI: Ptr to destination buffer |
---|
[41] | 84 | ; Returns: |
---|
[50] | 85 | ; DI: Updated by number of BYTEs stored |
---|
[41] | 86 | ; Corrupts registers: |
---|
| 87 | ; AX |
---|
| 88 | ;-------------------------------------------------------------------- |
---|
| 89 | ALIGN JUMP_ALIGN |
---|
[46] | 90 | Memory_ZeroESDIwithSizeInCX: |
---|
[41] | 91 | xor ax, ax |
---|
[46] | 92 | ; Fall to Memory_StoreCXbytesFromAccumToESDI |
---|
[41] | 93 | |
---|
| 94 | ;-------------------------------------------------------------------- |
---|
[46] | 95 | ; Memory_StoreCXbytesFromAccumToESDI |
---|
[41] | 96 | ; Parameters |
---|
| 97 | ; AX: Word to use to fill buffer |
---|
[46] | 98 | ; CX: Number of BYTEs to store |
---|
| 99 | ; ES:DI: Ptr to destination buffer |
---|
[41] | 100 | ; Returns: |
---|
[50] | 101 | ; DI: Updated by number of BYTEs stored |
---|
[41] | 102 | ; Corrupts registers: |
---|
| 103 | ; Nothing |
---|
| 104 | ;-------------------------------------------------------------------- |
---|
| 105 | ALIGN JUMP_ALIGN |
---|
[46] | 106 | Memory_StoreCXbytesFromAccumToESDI: |
---|
| 107 | OPTIMIZE_STRING_OPERATION rep, stos |
---|
[41] | 108 | ret |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | ;-------------------------------------------------------------------- |
---|
| 112 | ; Memory_ExchangeDSSIwithESDI |
---|
| 113 | ; Parameters |
---|
| 114 | ; Nothing |
---|
| 115 | ; Returns: |
---|
[50] | 116 | ; DS:SI and ES:DI are exchanged. |
---|
[41] | 117 | ; Corrupts registers: |
---|
| 118 | ; Nothing |
---|
| 119 | ;-------------------------------------------------------------------- |
---|
| 120 | ALIGN JUMP_ALIGN |
---|
| 121 | Memory_ExchangeDSSIwithESDI: |
---|
| 122 | push ds |
---|
| 123 | push es |
---|
| 124 | pop ds |
---|
| 125 | pop es |
---|
[50] | 126 | xchg si, di |
---|
[41] | 127 | ret |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | ;-------------------------------------------------------------------- |
---|
| 131 | ; Memory_CopySSBPtoESDI |
---|
[50] | 132 | ; Memory_CopySSBPtoDSSI |
---|
| 133 | ; Memory_CopyESDItoDSSI |
---|
[41] | 134 | ; Parameters |
---|
| 135 | ; Nothing |
---|
| 136 | ; Returns: |
---|
[50] | 137 | ; Copies farm pointer to different segment/pointer register pair |
---|
[41] | 138 | ; Corrupts registers: |
---|
| 139 | ; Nothing |
---|
| 140 | ;-------------------------------------------------------------------- |
---|
| 141 | ALIGN JUMP_ALIGN |
---|
| 142 | Memory_CopySSBPtoESDI: |
---|
| 143 | push ss |
---|
| 144 | pop es |
---|
| 145 | mov di, bp |
---|
| 146 | ret |
---|
| 147 | |
---|
[50] | 148 | ALIGN JUMP_ALIGN |
---|
| 149 | Memory_CopySSBPtoDSSI: |
---|
| 150 | push ss |
---|
| 151 | pop ds |
---|
| 152 | mov si, bp |
---|
| 153 | ret |
---|
[41] | 154 | |
---|
[50] | 155 | ALIGN JUMP_ALIGN |
---|
| 156 | Memory_CopyESDItoDSSI: |
---|
| 157 | push es |
---|
| 158 | pop ds |
---|
| 159 | mov si, di |
---|
| 160 | ret |
---|
| 161 | |
---|
| 162 | |
---|
[41] | 163 | ;-------------------------------------------------------------------- |
---|
| 164 | ; Memory_SetZFifNullPointerInDSSI |
---|
| 165 | ; Parameters |
---|
| 166 | ; DS:SI: Far pointer |
---|
| 167 | ; Returns: |
---|
| 168 | ; ZF: Set if NULL pointer in DS:SI |
---|
| 169 | ; Corrupts registers: |
---|
| 170 | ; Nothing |
---|
| 171 | ;-------------------------------------------------------------------- |
---|
| 172 | ALIGN JUMP_ALIGN |
---|
| 173 | Memory_SetZFifNullPointerInDSSI: |
---|
| 174 | push ax |
---|
| 175 | mov ax, ds |
---|
| 176 | or ax, si |
---|
| 177 | pop ax |
---|
| 178 | ret |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | ;-------------------------------------------------------------------- |
---|
| 182 | ; Memory_ReserveCXbytesFromStackToDSSI |
---|
| 183 | ; Parameters |
---|
| 184 | ; CX: Number of bytes to reserve |
---|
| 185 | ; Returns: |
---|
| 186 | ; DS:SI: Ptr to reserved buffer |
---|
| 187 | ; Corrupts registers: |
---|
| 188 | ; AX |
---|
| 189 | ;-------------------------------------------------------------------- |
---|
| 190 | ALIGN JUMP_ALIGN |
---|
| 191 | Memory_ReserveCXbytesFromStackToDSSI: |
---|
| 192 | pop ax |
---|
| 193 | push ss |
---|
| 194 | pop ds |
---|
| 195 | sub sp, cx |
---|
| 196 | mov si, sp |
---|
| 197 | jmp ax |
---|