-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch3_2comArith.html
152 lines (144 loc) · 6.56 KB
/
ch3_2comArith.html
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
<!DOCTYPE html>
<html>
<head>
<title>CS319 Practices - Two's Complement Arithmetic</title>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META name="description" content="Practice Tools for Internal Data Representation Concepts in Computer Architecture Course">
<META name="keywords" content="Two's Complement arithmetic, 2's complement arithmetic, signed integer arithmetic, data representation, practice tool, Computer Architecture, Computer Organization">
<META http-equiv="Cache-Control" content="no-cache">
<link rel="stylesheet" href="assets/css/stylesp.css">
</head>
<body>
<ul class="breadcrumb">
<li><a href=".">Home</a></li>
<li>Two's Complement Arithmetic</li>
</ul>
<h2>Two's Complement Arithmetic</h2>
<p>This section includes exercises on 2's complement arithmetic: negation, addition, and subtraction. Multiplication and division exercises are not included yet.</p>
<p>How to use an exercise:</p>
<ul>
<li>Follow steps 1-2-3-4, but you may use the "Start" button of an exercise at any time to restart.</li>
<li>Looking for examples of how to solve a problem? Just click "Start" in step 1, type something for step 2, and move to the step-by-step solution in step 4.</li>
</ul>
<h4>Exercise 1. 8-bit 2's Complement: Negation</h4>
<p>Negate a 2's complement number: given a number n in 2's complement, please provide (-n)'s 2's complement representation in the same number of bits.</p>
<p>Reference: <a href="https://youtu.be/yBz7_l1MFj0?t=25" alt="lecture on negating a 2's complement number" target="_blank">a lecture on 2's complemet negation</a>.</p>
<table>
<tr>
<td>1. Generate a random 8-bit 2's Complement number: </td>
<td><button id="p1A_StartBtn" type="button" onclick="p1A_RandomN()">Start</button></td>
<td><p id="p1A_Data"></p></td>
</tr>
<tr>
<td>2. Please negate this 2's complement number <br/>and indicate whether overflow happened:</td>
<td>-</td>
<td><input id="p1A_Input"> (Enter result here)<br/>
Overflow?
<input name ="p1A_Input_Overflow" id="p1A_Input_Overflow_Y" type="radio" value="Y"><label for="p1A_Input_Overflow_Y">Yes</label>
<input name ="p1A_Input_Overflow" id="p1A_Input_Overflow_N" type="radio" value="N"><label for="p1A_Input_Overflow_N">No</label>
</td>
</tr>
<tr>
<td>3. Now check your answer:</td>
<td><button id="p1A_CheckBtn" type="button" onclick="p1A_CheckResult()" disabled="true">Check</button></td>
<td><p id="p1A_Result">-</p></td>
</tr>
<tr>
<td>4. Show the solution:</td>
<td><button id="p1A_AnswerBtn" type="button" onclick="p1A_ShowAnswer()" disabled="true">Solution</button></td>
<td><p id="p1A_Answer">-</p></td>
</tr>
</table>
<h4>Exercise 2. 8-bit 2's Complement: Addition</h4>
<p>Reference: <a href="https://youtu.be/njDQUbOmj2w" alt="lecture on adding two 2's complement numbers" target="_blank">lecture on 2's complement addition</a>.</p>
<table>
<tr>
<td>1. Generate two random numbers in 8-bit 2's Complement: </td>
<td><button id="p2A_StartBtn" type="button" onclick="p2A_RandomTwoN()">Start</button></td>
<td><p id="p2A_Data1"></p> + <p id="p2A_Data2"></p></td>
</tr>
<tr>
<td>2. Please add them together and specify any carry/overflow:</td>
<td>-</td>
<td><input id="p2A_Input"> (Enter result here. Should be 8 bits)<br/>
Carry out of MSB?
<input name ="p2A_Input_Carry" id="p2A_Input_Carry_Y" type="radio" value="Y"><label for="p2A_Input_Carry_Y">Yes</label>
<input name ="p2A_Input_Carry" id="p2A_Input_Carry_N" type="radio" value="N"><label for="p2A_Input_Carry_N">No</label>
<br/>
Overflow?
<input name ="p2A_Input_Overflow" id="p2A_Input_Overflow_Y" type="radio" value="Y"><label for="p2A_Input_Overflow_Y">Yes</label>
<input name ="p2A_Input_Overflow" id="p2A_Input_Overflow_N" type="radio" value="N"><label for="p2A_Input_Overflow_N">No</label>
</td>
</tr>
<tr>
<td>3. Now check your answer:</td>
<td><button id="p2A_CheckBtn" type="button" onclick="p2A_CheckResult()" disabled="true">Check</button></td>
<td><p id="p2A_Result">-</p></td>
</tr>
<tr>
<td>4. Show the solution:</td>
<td><button id="p2A_AnswerBtn" type="button" onclick="p2A_ShowAnswer()" disabled="true">Solution</button></td>
<td><p id="p2A_Answer">-</p></td>
</tr>
</table>
<h4>Exercise 3. 8-bit 2's Complement: Subtraction</h4>
<p>Reference: <a href="https://youtu.be/QhvDjPt0Rtw" alt="lecture on subtracting two 2's complement numbers" target="_blank">lecture on 2's complement subtraction</a>.</p>
<table>
<tr>
<td>1. Generate two random numbers in 8-bit 2's Complement: </td>
<td><button id="p3A_StartBtn" type="button" onclick="p3A_RandomTwoN()">Start</button></td>
<td><p id="p3A_Data1"></p> - <p id="p3A_Data2"></p></td>
</tr>
<tr>
<td>2. Please perform subtraction and specify any carry/overflow:</td>
<td>-</td>
<td><input id="p3A_Input"> (Enter result here. Should be 8 bits)<br/>
Carry out of MSB?
<input name ="p3A_Input_Carry" id="p3A_Input_Carry_Y" type="radio" value="Y"><label for="p3A_Input_Carry_Y">Yes</label>
<input name ="p3A_Input_Carry" id="p3A_Input_Carry_N" type="radio" value="N"><label for="p3A_Input_Carry_N">No</label>
<br/>
Overflow?
<input name ="p3A_Input_Overflow" id="p3A_Input_Overflow_Y" type="radio" value="Y"><label for="p3A_Input_Overflow_Y">Yes</label>
<input name ="p3A_Input_Overflow" id="p3A_Input_Overflow_N" type="radio" value="N"><label for="p3A_Input_Overflow_N">No</label>
</td>
</tr>
<tr>
<td>3. Now check your answer:</td>
<td><button id="p3A_CheckBtn" type="button" onclick="p3A_CheckResult()" disabled="true">Check</button></td>
<td><p id="p3A_Result">-</p></td>
</tr>
<tr>
<td>4. Show the solution:</td>
<td><button id="p3A_AnswerBtn" type="button" onclick="p3A_ShowAnswer()" disabled="true">Solution</button></td>
<td><p id="p3A_Answer">-</p></td>
</tr>
</table>
<script src = "js/ch3work_2com_Arith.js"></script>
<h2> </h2>
<p>
<b>© 2022
Bin Peng</b><br>
Bug reports and comments are welcome: crystal dot peng at park dot edu<br><br>
Last Update:
<script type="text/javascript">
var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
moddate=new Date(document.lastModified); //convert to local time
document.write(month[moddate.getMonth()]+" "+ moddate.getDate()+", "+ moddate.getFullYear());
</script>
<br>
Created: August 24, 2020
</p>
</body>
</html>