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 | ALIGN JUMP_ALIGN
|
---|
48 | Memory_CopyCXbytesFromDSSItoESDI:
|
---|
49 | OPTIMIZE_STRING_OPERATION rep, movs
|
---|
50 | ret
|
---|
51 |
|
---|
52 |
|
---|
53 | ;--------------------------------------------------------------------
|
---|
54 | ; Memory_ZeroSSBPwithSizeInCX
|
---|
55 | ; Parameters
|
---|
56 | ; CX: Number of bytes to zero
|
---|
57 | ; SS:BP: Ptr to buffer to zero
|
---|
58 | ; Returns:
|
---|
59 | ; Nothing
|
---|
60 | ; Corrupts registers:
|
---|
61 | ; Nothing
|
---|
62 | ;--------------------------------------------------------------------
|
---|
63 | ALIGN JUMP_ALIGN
|
---|
64 | Memory_ZeroSSBPwithSizeInCX:
|
---|
65 | push es
|
---|
66 | push di
|
---|
67 | push ax
|
---|
68 | call Registers_CopySSBPtoESDI
|
---|
69 | call Memory_ZeroESDIwithSizeInCX
|
---|
70 | pop ax
|
---|
71 | pop di
|
---|
72 | pop es
|
---|
73 | ret
|
---|
74 |
|
---|
75 | ;--------------------------------------------------------------------
|
---|
76 | ; Memory_ZeroESDIwithSizeInCX
|
---|
77 | ; Parameters
|
---|
78 | ; CX: Number of bytes to zero
|
---|
79 | ; ES:DI: Ptr to destination buffer
|
---|
80 | ; Returns:
|
---|
81 | ; DI: Updated by number of BYTEs stored
|
---|
82 | ; Corrupts registers:
|
---|
83 | ; AX
|
---|
84 | ;--------------------------------------------------------------------
|
---|
85 | ALIGN JUMP_ALIGN
|
---|
86 | Memory_ZeroESDIwithSizeInCX:
|
---|
87 | xor ax, ax
|
---|
88 | ; Fall to Memory_StoreCXbytesFromAccumToESDI
|
---|
89 |
|
---|
90 | ;--------------------------------------------------------------------
|
---|
91 | ; Memory_StoreCXbytesFromAccumToESDI
|
---|
92 | ; Parameters
|
---|
93 | ; AX: Word to use to fill buffer
|
---|
94 | ; CX: Number of BYTEs to store
|
---|
95 | ; ES:DI: Ptr to destination buffer
|
---|
96 | ; Returns:
|
---|
97 | ; DI: Updated by number of BYTEs stored
|
---|
98 | ; Corrupts registers:
|
---|
99 | ; Nothing
|
---|
100 | ;--------------------------------------------------------------------
|
---|
101 | ALIGN JUMP_ALIGN
|
---|
102 | Memory_StoreCXbytesFromAccumToESDI:
|
---|
103 | OPTIMIZE_STRING_OPERATION rep, stos
|
---|
104 | ret
|
---|
105 |
|
---|
106 |
|
---|
107 | ;--------------------------------------------------------------------
|
---|
108 | ; Memory_ReserveCXbytesFromStackToDSSI
|
---|
109 | ; Parameters
|
---|
110 | ; CX: Number of bytes to reserve
|
---|
111 | ; Returns:
|
---|
112 | ; DS:SI: Ptr to reserved buffer
|
---|
113 | ; Corrupts registers:
|
---|
114 | ; AX
|
---|
115 | ;--------------------------------------------------------------------
|
---|
116 | ALIGN JUMP_ALIGN
|
---|
117 | Memory_ReserveCXbytesFromStackToDSSI:
|
---|
118 | pop ax
|
---|
119 | push ss
|
---|
120 | pop ds
|
---|
121 | sub sp, cx
|
---|
122 | mov si, sp
|
---|
123 | jmp ax
|
---|