-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment2.cpp
More file actions
240 lines (184 loc) · 4.72 KB
/
assignment2.cpp
File metadata and controls
240 lines (184 loc) · 4.72 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
/*******************
Assignment 2 (ADD, SUB, IMUl, IDIV instructions)
Cuevas, Fernando
Huang, Justin
*****************/
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
// //-------------------START QUESTION 1-------------------------------------------------
// // must use short for this question
// //variables that will store the amount the user specifies for each option
// short int drinkAmount, sanwichAmount, drinksCost = 2, foodCost = 4, totalCost;
// //main menu of program
// cout << "---------------MENU---------------" << endl;
// cout << " Drinks.....................$2 \n";
// cout << " Sandwiches.................$4 " << endl;
//
// cout << " How many drinks: ";
// cin >> drinkAmount;
//
// cout << " How many sandwiches: ";
// cin >> sanwichAmount;
//
// // aritmatic operations will take place using assembly...
// _asm
// {
// // calculate how much it will cost for the drinks
// // first by putting the user amount in ax (short int is 2 bytes so we use ax which is 2 bites or 16 bits) and then multiplying it by the drink value
//
// mov ax, drinkAmount; ax now have the value from drinka mount
// imul drinksCost; multiple what is in ax and store it in ax
// mov drinkAmount, ax;
//
// //now do the same thing for the sandwiches
//
// mov bx, sanwichAmount; move value in sanwichAmount into bx
// imul foodCost;
// mov sanwichAmount, bx;
//
// //fianally add together
// add cx, drinkAmount;
// add cx, sanwichAmount;
//
// mov totalCost, cx;
// }
//
// // dispplay information
//
// cout << "\t Your total bill $" << totalCost << endl;
//
//-------------------END QUESTION 1------------------------
//-------------------START QUESTION 2----------------------
#include <iostream>
using namespace std;
int main()
{
int a, b, c, h, l, w, areaT, preT, areaR, preR;
int t = 2;
cout << " /| \ " << endl;
cout << " / | \ " << endl;
cout << "a / | \ b" << endl;
cout << " / h| \ " << endl;
cout << "/ | \ " << endl;
cout << "____________ " << endl;
cout << " c " << endl;
cout << " -------------------------- " << endl;
cout << " | |" << endl;
cout << " | | width" << endl;
cout << " | |" << endl;
cout << " | |" << endl;
cout << " --------------------------" << endl;
cout << " length " << endl;
cout << " Please enter for a,b,c and h" << endl;
cin >> a;
cin >> b;
cin >> c;
cin >> h;
cout << " Please enter for length and width " << endl;
cin >> l;
cin >> w;
_asm
{
mov eax,c
imul h
idiv t
mov areaT,eax
mov eax,c
add eax,a
add eax,b
mov preT,eax
mov eax,l
imul w
mov areaR, eax
mov eax,l
add eax,w
add eax,eax
mov preR,eax
}
cout << "triangle " << endl;
cout << "Area............." << areaT << endl;
cout << "Perimeter........" << preT << endl;
cout << "Rectangle " << endl;
cout << " Area............" << areaR << endl;
cout << " Perimeter......." << preR << endl;
return 0;
}
//-------------------------------OutPut---------------------------------------------
// / |
// / |
// a / | b
// / h |
// / |
// ____________
// c
//--------------------------
//| |
//| | width
//| |
//| |
//--------------------------
//length
//Please enter for a, b, c and h
//4
//6
//9
//10
//Please enter for length and width
//15
//10
//
//triangle
//Area.............45
//Perimeter........19
//Rectangle
//Area............150
//Perimeter.......50
//Press any key to continue . . .
//---------------------------------------------------------------------------------
//-------------------QUESTION 3------------------------------------------------------
/*******************
Assignment 2 (ADD, SUB, IMUl, IDIV instructions)
Cuevas, Fernando
Huang, Justin
*****************/
#include <iostream>
using namespace std;
int main()
{
short F, C,b=9,d=5;
cout << " Enter temperature in Fahrenheight: ";
cin >> F;
_asm
{
mov ax, F
sub ax, 32
imul b
idiv d
mov c,ax
}
cout << F << "F " << C << "C " << endl;
return 0;
}
// -----------------------------------------------------------------------------------------------
//-------------------------------QUESTION 4-----------------------------------------------
int number, total, hun = 100, t = 10, r;
std::cout << "Enter a 3 digit number: ";
std::cin >> number;
_asm {
mov eax, number;
cdq;
idiv hun;
mov total, eax;
mov r, edx;
mov eax, r
cdq;
idiv t;
add total, eax;
add total, edx;
}
std::cout << "The total of the digits in " << number << " is " << total << "\n";
return 0;
}