-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_sum.asm
95 lines (75 loc) · 1.43 KB
/
2_sum.asm
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
section .data
array dd 2, 7, 11, 15
target dd 9
array_len equ ($ - array) / 4
result_str db "Indices of the 2 nums: ", 0xA
result_len equ $ - result_str
newline db 0xA
newline_len equ 1
section .bss
indices_buffer resb 2
section .text
global _start
_start:
mov ecx, array_len
outer_loop:
dec ecx
test ecx, ecx
jz not_found
mov eax, ecx
mov edx, array
inner_loop:
mov ebx, [edx + eax * 4]
add ebx, [array]
cmp ebx, [target]
je found
dec eax
jnz inner_loop
jmp outer_loop
found:
mov ebx, [edx + eax * 4]
add ebx, [array]
sub ebx, [target]
mov eax, ecx
mov edx, eax
mov eax, 4
mov ebx, 1
mov ecx, result_str
mov edx, result_len
int 0x80
mov eax, ecx
add eax, '0'
mov [indices_buffer], al
inc eax
mov [indices_buffer + 1], al
mov eax, 4
mov ebx, 1
mov ecx, indices_buffer
mov edx, 2
int 0x80
mov eax, 4
mov ebx, 1
mov ecx, esp
mov edx, 1
int 0x80
mov eax, edx
add eax, '0'
mov [indices_buffer], al
inc eax
mov [indices_buffer + 1], al
mov eax, 4
mov ebx, 1
mov ecx, indices_buffer
mov edx, 2
int 0x80
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, newline_len
int 0x80
jmp exit_program
not_found:
mov ebx, 0
exit_program:
mov eax, 1
int 0x80