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

Last change on this file since 126 was 105, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:

  • More optimizations to reduce size.
  • Removed some utility functions to reduce size.
File size: 3.2 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for memory access.
3
4; Section containing code
5SECTION .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
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
[41]44; Corrupts registers:
[46]45; Nothing
[41]46;--------------------------------------------------------------------
47ALIGN JUMP_ALIGN
[46]48Memory_CopyCXbytesFromDSSItoESDI:
49 OPTIMIZE_STRING_OPERATION rep, movs
50 ret
[41]51
[46]52
[41]53;--------------------------------------------------------------------
[46]54; Memory_ZeroSSBPwithSizeInCX
[41]55; Parameters
[46]56; CX: Number of bytes to zero
[41]57; SS:BP: Ptr to buffer to zero
58; Returns:
59; Nothing
60; Corrupts registers:
61; Nothing
62;--------------------------------------------------------------------
63ALIGN JUMP_ALIGN
[46]64Memory_ZeroSSBPwithSizeInCX:
[50]65 push es
66 push di
[41]67 push ax
[105]68 call Registers_CopySSBPtoESDI
[46]69 call Memory_ZeroESDIwithSizeInCX
[41]70 pop ax
[50]71 pop di
72 pop es
[41]73 ret
74
75;--------------------------------------------------------------------
[46]76; Memory_ZeroESDIwithSizeInCX
[41]77; Parameters
[46]78; CX: Number of bytes to zero
79; ES:DI: Ptr to destination buffer
[41]80; Returns:
[50]81; DI: Updated by number of BYTEs stored
[41]82; Corrupts registers:
83; AX
84;--------------------------------------------------------------------
85ALIGN JUMP_ALIGN
[46]86Memory_ZeroESDIwithSizeInCX:
[41]87 xor ax, ax
[46]88 ; Fall to Memory_StoreCXbytesFromAccumToESDI
[41]89
90;--------------------------------------------------------------------
[46]91; Memory_StoreCXbytesFromAccumToESDI
[41]92; Parameters
93; AX: Word to use to fill buffer
[46]94; CX: Number of BYTEs to store
95; ES:DI: Ptr to destination buffer
[41]96; Returns:
[50]97; DI: Updated by number of BYTEs stored
[41]98; Corrupts registers:
99; Nothing
100;--------------------------------------------------------------------
101ALIGN JUMP_ALIGN
[46]102Memory_StoreCXbytesFromAccumToESDI:
103 OPTIMIZE_STRING_OPERATION rep, stos
[41]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;--------------------------------------------------------------------
116ALIGN JUMP_ALIGN
117Memory_ReserveCXbytesFromStackToDSSI:
118 pop ax
119 push ss
120 pop ds
121 sub sp, cx
122 mov si, sp
123 jmp ax
Note: See TracBrowser for help on using the repository browser.