[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for memory access.
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
| 7 | ;--------------------------------------------------------------------
|
---|
[46] | 8 | ; OPTIMIZE_STRING_OPERATION
|
---|
[41] | 9 | ; Parameters
|
---|
[46] | 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
|
---|
[41] | 15 | ; Returns:
|
---|
[46] | 16 | ; SI, DI: Updated by number of bytes operated
|
---|
| 17 | ; Corrupts registers:
|
---|
[41] | 18 | ; Nothing
|
---|
[46] | 19 | ;--------------------------------------------------------------------
|
---|
| 20 | %macro OPTIMIZE_STRING_OPERATION 2
|
---|
| 21 | push cx
|
---|
| 22 |
|
---|
| 23 | shr cx, 1 ; Operate with WORDs for performance
|
---|
[103] | 24 | jz %%HandleRemainingByte
|
---|
[46] | 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
|
---|
[41] | 44 | ; Corrupts registers:
|
---|
[46] | 45 | ; Nothing
|
---|
[41] | 46 | ;--------------------------------------------------------------------
|
---|
[131] | 47 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[41] | 48 | ALIGN JUMP_ALIGN
|
---|
[46] | 49 | Memory_CopyCXbytesFromDSSItoESDI:
|
---|
| 50 | OPTIMIZE_STRING_OPERATION rep, movs
|
---|
| 51 | ret
|
---|
[131] | 52 | %endif
|
---|
[41] | 53 |
|
---|
[46] | 54 |
|
---|
[41] | 55 | ;--------------------------------------------------------------------
|
---|
[46] | 56 | ; Memory_ZeroSSBPwithSizeInCX
|
---|
[41] | 57 | ; Parameters
|
---|
[46] | 58 | ; CX: Number of bytes to zero
|
---|
[41] | 59 | ; SS:BP: Ptr to buffer to zero
|
---|
| 60 | ; Returns:
|
---|
| 61 | ; Nothing
|
---|
| 62 | ; Corrupts registers:
|
---|
| 63 | ; Nothing
|
---|
| 64 | ;--------------------------------------------------------------------
|
---|
| 65 | ALIGN JUMP_ALIGN
|
---|
[46] | 66 | Memory_ZeroSSBPwithSizeInCX:
|
---|
[50] | 67 | push es
|
---|
| 68 | push di
|
---|
[41] | 69 | push ax
|
---|
[105] | 70 | call Registers_CopySSBPtoESDI
|
---|
[46] | 71 | call Memory_ZeroESDIwithSizeInCX
|
---|
[41] | 72 | pop ax
|
---|
[50] | 73 | pop di
|
---|
| 74 | pop es
|
---|
[41] | 75 | ret
|
---|
| 76 |
|
---|
| 77 | ;--------------------------------------------------------------------
|
---|
[46] | 78 | ; Memory_ZeroESDIwithSizeInCX
|
---|
[41] | 79 | ; Parameters
|
---|
[46] | 80 | ; CX: Number of bytes to zero
|
---|
| 81 | ; ES:DI: Ptr to destination buffer
|
---|
[41] | 82 | ; Returns:
|
---|
[50] | 83 | ; DI: Updated by number of BYTEs stored
|
---|
[41] | 84 | ; Corrupts registers:
|
---|
| 85 | ; AX
|
---|
| 86 | ;--------------------------------------------------------------------
|
---|
| 87 | ALIGN JUMP_ALIGN
|
---|
[46] | 88 | Memory_ZeroESDIwithSizeInCX:
|
---|
[41] | 89 | xor ax, ax
|
---|
[46] | 90 | ; Fall to Memory_StoreCXbytesFromAccumToESDI
|
---|
[41] | 91 |
|
---|
| 92 | ;--------------------------------------------------------------------
|
---|
[46] | 93 | ; Memory_StoreCXbytesFromAccumToESDI
|
---|
[41] | 94 | ; Parameters
|
---|
| 95 | ; AX: Word to use to fill buffer
|
---|
[46] | 96 | ; CX: Number of BYTEs to store
|
---|
| 97 | ; ES:DI: Ptr to destination buffer
|
---|
[41] | 98 | ; Returns:
|
---|
[50] | 99 | ; DI: Updated by number of BYTEs stored
|
---|
[41] | 100 | ; Corrupts registers:
|
---|
| 101 | ; Nothing
|
---|
| 102 | ;--------------------------------------------------------------------
|
---|
| 103 | ALIGN JUMP_ALIGN
|
---|
[46] | 104 | Memory_StoreCXbytesFromAccumToESDI:
|
---|
| 105 | OPTIMIZE_STRING_OPERATION rep, stos
|
---|
[41] | 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 | ALIGN JUMP_ALIGN
|
---|
| 119 | Memory_ReserveCXbytesFromStackToDSSI:
|
---|
| 120 | pop ax
|
---|
| 121 | push ss
|
---|
| 122 | pop ds
|
---|
| 123 | sub sp, cx
|
---|
| 124 | mov si, sp
|
---|
| 125 | jmp ax
|
---|