-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicArray_Variant13.asm
More file actions
167 lines (143 loc) · 3.42 KB
/
Copy pathDynamicArray_Variant13.asm
File metadata and controls
167 lines (143 loc) · 3.42 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
format PE console
entry start
include 'win32a.inc'
section '.data' data readable writable
strVecSize db 'Input array size: ', 0
strIncorSize db 'Invalid array size = %d', 10, 0
strVecElemI db 'Input A[%d] element of array: ', 0
strScanInt db '%d', 0
strMinValue db 'Minimal value = %d', 10, 0
strVecElemOut db 'B[%d] = %d', 10, 0
vec_size dd 0
min dd ?
i dd 0
size_tmp dd ?
tmp dd ?
tmpStack dd ?
vec rd 3
;--entry point--
section '.code' code readable executable
start:
; 1) input of array A
call VectorInput
; 2) get min value
call MinValue
; 3) print min value
push [min]
push strMinValue
call [printf]
; 4) output of array B
call VectorOut
finish:
call [getch]
push 0
call [ExitProcess]
;--input of array A--
VectorInput:
push strVecSize
call [printf]
add esp, 4
push vec_size
push strScanInt
call [scanf]
add esp, 8
mov eax, [vec_size]
cmp eax, 0
jg getVector
; invalid array size instruction
push [vec_size]
push strIncorSize
call [printf]
jmp finish
getVector:
xor ecx, ecx
mov ebx, vec
getVecLoop:
mov [tmp], ebx
cmp ecx, [vec_size]
jge endInputVector
mov [i], ecx
push ecx
push strVecElemI
call [printf]
add esp, 8
push ebx
push strScanInt
call [scanf]
add esp, 8
mov ecx, [i]
inc ecx
mov ebx, [tmp]
add ebx, 4
jmp getVecLoop
endInputVector:
ret
;--get min value--
MinValue:
xor ecx, ecx
mov ebx, vec
mov [min], ebx
inc ecx
add ebx, 4
minValLoop:
cmp ecx, [vec_size]
je endMinValue
mov eax, [ebx]
cmp [min], eax
jge startMin
inc ecx
add ebx, 4
jmp minValLoop
startMin:
mov [min], eax
inc ecx
add ebx, 4
jmp minValLoop
endMinValue:
ret
;--output of array B--
VectorOut:
mov [tmpStack], esp
xor ecx, ecx
xor eax, eax
mov ebx, vec
putVecLoop:
cmp ecx, [vec_size]
je endOutputVector
mov eax, [ebx]
cmp eax, [min]
je MinMethod
mov [i], ecx
mov [tmp], ebx
push dword [ebx]
push ecx
push strVecElemOut
call [printf]
mov ecx, [i]
inc ecx
mov ebx, [tmp]
add ebx, 4
jmp putVecLoop
MinMethod:
dec [vec_size]
add ebx, 4
jmp putVecLoop
endOutputVector:
mov esp, [tmpStack]
ret
;--import getch, scanf, printf--
section '.idata' import data readable
library kernel, 'kernel32.dll',\
msvcrt, 'msvcrt.dll',\
user32,'USER32.DLL'
include 'api\user32.inc'
include 'api\kernel32.inc'
import kernel,\
ExitProcess, 'ExitProcess',\
HeapCreate,'HeapCreate',\
HeapAlloc,'HeapAlloc'
include 'api\kernel32.inc'
import msvcrt,\
printf, 'printf',\
scanf, 'scanf',\
getch, '_getch'