deleting line
[sped.git] / utils.asm
1
2 %include "macros.S"
3
4 extern memmove
5 extern free
6 extern realloc
7
8 global shiftLeft
9 global shiftRight
10
11 section .text
12
13 ; shrinks array (4byte) by shifting blocks left
14 ; args: buffer, buffer_len, shift_pos (index that gets destroyed)
15 ; return:
16 ;   eax: location of new buffer
17 ; issues: 
18 shiftLeft:
19     %define _BUFFER      16
20     %define _BUFFER_LEN  12
21     %define _SHIFT_POS   8
22     %define SHIFT_LEN    4
23     %define BLOCK_OFFSET 8 ; mem location of block to be destroyed
24     %define NEW_BUFFER   12
25
26     push ebp
27     mov ebp, esp
28
29     sub esp, 12
30
31     ; set vars
32     mov eax, DWORD [ebp+_BUFFER_LEN]
33     sub eax, [ebp+_SHIFT_POS]
34     sub eax, 1
35     mov [ebp-SHIFT_LEN], eax
36
37     str_offset [ebp+_BUFFER], [ebp+_SHIFT_POS]
38     mov [ebp-BLOCK_OFFSET], eax
39     
40     ; free string to be destoryed first
41     mov eax, DWORD [ebp-BLOCK_OFFSET]
42     mov eax, [eax]
43     push eax
44     call free
45
46     ; move the memory
47     mov eax, DWORD [ebp-SHIFT_LEN]
48     mov ecx, 4
49     mul ecx
50     push eax
51     mov eax, DWORD [ebp-BLOCK_OFFSET]
52     add eax, 4
53     push eax
54     push DWORD [ebp-BLOCK_OFFSET]
55     call memmove
56     
57     ; realloc to shrink the array
58
59     %undef _BUFFER
60     %undef _BUFFER_LEN
61     %undef _SHIFT_POS
62     
63     mov esp, ebp
64     pop ebp
65     ret
66
67 ; grows array by shifting blocks right
68 ; args: buffer, buffer_len, shift_pos (new uninitalized index)
69 ; return: location of new buffer
70 shiftRight:
71     push ebp
72     mov ebp, esp
73
74     
75     
76     mov esp, ebp
77     pop ebp
78     ret
79