-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject6.cpp
More file actions
322 lines (239 loc) · 6.1 KB
/
project6.cpp
File metadata and controls
322 lines (239 loc) · 6.1 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
Author: Cuevas, Fernando
Huang, Justin
Class: 240
Project: 6 (ARRAYS)
Due: 10/05/2017
*/
#include <iostream>
// question 1 variable and functions
// s m l xl
int b[4][4] = { 10, 20, 30, 40, // red
20, 10, 40, 30, // green
5, 15, 20, 25, // blue
30, 25, 20, 15 }; // black
int totalShirtCount = 0, totalLargeCount = 0, totalBlackSHirtCount = 0;
int arrayLoc;
void displayTotalShirt() {
std::cout << "a.) Total # of shirts is: " << totalShirtCount << std::endl;
}
void displayTotalLargeShirt() {
std::cout << "b.) Total # of large shirts: " << totalLargeCount << std::endl;
}
void displayBlackCount() {
std::cout << "c.) Total # of black shirts: " << totalBlackSHirtCount << std::endl;
}
// ------------ QUESTION 2 Stuff ------------------------
int aa[5] = {9, 3, 22, 8, 1};
int loop1Count = 0, loop2Count, index, nextIndex, element;
// to display the array i get an error when i try to display within assembly after moving the first value into element the value
// of ecx changes dramatically which leads to a crash, possible somthing with the call.
void outputOG() {
std::cout << "Original array: ";
}
void outputSortedTxt() {
std::cout << "Sorted array: ";
}
void displayArray() {
for (int i = 0; i < 5; i++) {
std::cout << aa[i] << " ";
}
std::cout << std::endl;
}
void displayMsg_Original() {
std::cout << "Original Array: ";
}
//-------------------------QUESTION 3 stuff---------------------
int a3D[3][3][2] = { 1, 2, 3,
4, 5, 6,
7, 8, 9,
10, 11, 12,
13, 14, 15,
16, 17, 18 };
int arrayPos = 0, total3DShirtCount = 0, total3DMediumCount = 0, total3DShortSleeve = 0, total3DReadShirtCount = 0;
int countJump = 4;
//functsa
void displayTotal3DCount() {
std::cout << "a.) Total # of shirts is: " << total3DShirtCount << std::endl;
}
void display3DTOtalMed() {
std::cout << "b.) Total # of shirts is: " << total3DMediumCount << std::endl;
}
void display3DTotalSHort() {
std::cout << "c.) Total # of short sleeves: " << total3DShortSleeve << std::endl;
}
void display3DTotalRed() {
std::cout << "d.) Total # of red shirts: " << total3DReadShirtCount << std::endl;
}
int main() {
//part a of 1
std::cout << "\n\tT-shirt Company\n";
_asm {
mov ecx, 0;
mov arrayLoc, 0;
looper:
cmp arrayLoc, 16; compare to see if it has reached the end of the array aka the last element which is 16th element
je done;
mov ebx, [b + ecx]; move the value at that index into ebx
add totalShirtCount, ebx; add it to the total
add ecx, 4; add for to ecx which is like the index for the array
inc arrayLoc;
jmp looper;
done:
call displayTotalShirt;
mov ecx, 8;
mov arrayLoc, 0;
looper2:
cmp arrayLoc, 4;
je done2;
mov ebx, [b + ecx];
add totalLargeCount, ebx;
add ecx, 16;
inc arrayLoc;
jmp looper2;
done2:
call displayTotalLargeShirt;
mov ecx, 48;
mov arrayLoc, 0;
Looper3:
cmp arrayLoc, 4;
je done3;
mov ebx, [b + ecx];
add totalBlackSHirtCount, ebx;
add ecx, 4;
inc arrayLoc;
jmp looper3;
done3:
call displayBlackCount;
}
//----------------------------------------------------
//part 2
std::cout << "\n\tArray ASM Bubble sort\n";
_asm {
call outputOG;
call displayArray;
mov ecx, 0;
mov loop1Count, 0;
mov loop2Count, 0;
jmp b_Sort;
swapNums:
mov [aa + ecx], ebx; this is a=b
mov[aa + ecx + 4], eax; this is b = temp, where temp is techinically a
jmp inc_Counts;
b_Sort:
cmp loop1Count, 4; loop to only go 4 times since array is of size 5 (0-4)
je display; display array
mov edx, 4; this seats up the stoping point for the check loop
sub edx, loop1Count; using bubble sort the second loo goes to n-i-1
sub edx, 1; where n is the array size, subtracted by i (value of first loop) amd then subbed by 1
check:; check if aa[i] is greater than aa[i+1] if it is then swap else increment values for check loop and continue
cmp loop2Count, edx; reachs end of loop go back to b_sort loop
je inc_Counts2;
mov eax, [aa + ecx]; temp
mov ebx, [aa + ecx + 4]; this is b
cmp eax, ebx; compare if it is greater
jle inc_Counts;
jge swapNums;
inc_Counts:; increment values ofr second check loop
inc loop2Count;
add ecx, 4;
jmp check;
inc_Counts2:; updated values for loop 1 aka b_sort
inc loop1Count;
mov loop2Count, 0;
mov ecx, 0;
jmp b_Sort;
display:
call outputSortedTxt;
call displayArray;
}
//----------------------------------------------------
//part 3
// a./ total shirts
// b.) medium size shirts
// c.) short sleeve shirts
// d.) red shirts
std::cout << "\n\t3-D array\n";
//part a
_asm {
mov ecx, 0;
loopi:
cmp arrayPos, 18;
je donney;
mov ebx, [a3D + ecx];
add total3DShirtCount, ebx;
add ecx, 4;
inc arrayPos;
jmp loopi;
donney:
call displayTotal3DCount;
}
//part b
_asm {
mov ecx, 8;
mov arrayLoc, 0;
loppi:
cmp arrayLoc, 3;
je doobi;
mov ebx, [a3D + ecx];
add total3DMediumCount, ebx;
mov ebx, [a3D + ecx + 4];
add total3DMediumCount, ebx;
mov eax, 8;
imul countJump;
mov ecx, eax;
inc arrayLoc;
add countJump, 3;
jmp loppi;
doobi:
call display3DTOtalMed;
}
//part c
_asm {
mov eax, 8;
mov arrayLoc, 0;
loodi:
cmp arrayLoc, 9;
je don;
imul arrayLoc;
mov ecx, eax;
mov eax, 8;
inc arrayLoc;
mov ebx, [a3D + ecx];
add total3DShortSleeve, ebx;
jmp loodi;
don:
call display3DTotalSHort
}
//part d
_asm {
mov ecx, 0;
mov arrayLoc, 0;
lupper:
cmp arrayLoc, 6;
je duubi;
mov ebx, [a3D + ecx];
add total3DReadShirtCount, ebx;
inc arrayLoc;
add ecx, 4;
jmp lupper;
duubi:
call display3DTotalRed;
}
return 0;
}
/*-------------------------------OUTPUT FOR ALL--------------------------
T-shirt Company
a.) Total # of shirts is: 355
b.) Total # of large shirts: 110
c.) Total # of black shirts: 90
Array ASM Bubble sort
Original array: 9 3 22 8 1
Sorted array: 3 8 9 22 1
3-D array
a.) Total # of shirts is: 171
b.) Total # of shirts is: 57
c.) Total # of short sleeves: 81
d.) Total # of red shirts: 21
Press any key to continue . . .
-------------------------------OUTPUT FOR ALL--------------------------*/