-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.S
73 lines (59 loc) · 1.27 KB
/
test.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
.intel_syntax noprefix
/*
void reverseIntkek(int *input, int length, int *output){
for (int idx = 0; idx < length; idx++){
int value = input[idx];
int odx = length - idx - 1;
output[odx] = value;
}
}
*/
.text
.global reverseInt
reverseInt:
push ebp
mov ebp, esp
push ebx
push edi
push esi
push edx
// input -> [ebp + 8] -> int*
// length -> [ebp + 12] -> int
// output -> [ebp + 16] -> int*
mov esi, [ebp + 8] // esi := input;
mov edi, [ebp + 16] // edi := output pointer ami az outputra mutat
mov edx, 0 // edx -> odx;
mov ebx, 0 // ebx -> idx;
LOOP:
// !(idx < length) ==> goto end
cmp ebx, [ebp + 12]
jge END
// if (idx % 2 == 0)
push edx
mov eax, ebx
cdq
mov ecx, 2
div ecx // edx := ebx % 2 maradékos osztás
mov eax, edx
pop edx
cmp eax, 0
jne SKIP
//int odx = length - idx - 1;
//mov edx, [ebp + 12] //edx := length;
//sub edx, ebx //edx -= ebx
//dec edx //edx--
//output[idx] = idx;
mov ecx, [esi + 4*ebx]
mov [ebp + 16 + 4*ebx], ecx
inc edx
SKIP:
inc ebx //idx++
jmp LOOP
END:
pop edx
pop esi
pop edi
pop ebx
mov esp, ebp
pop ebp
ret