This repository has been archived by the owner on Sep 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
318 lines (276 loc) · 10.5 KB
/
example.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
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
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Mini-MIPS</title>
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="lib/jcanvas.min.js"></script>
<script type="text/javascript">
function display_error(dom_node, message) {
var msg = '<div class="alert alert-error"">' +
' <button class="close" data-dismiss="alert">×</button>' +
' <strong>Obacht!</strong> ' + message +
'</div>';
$(dom_node).prepend(msg)
}
</script>
<script type="text/javascript" src="helpers.js"></script>
<script type="text/javascript" src="BitVector.js"></script>
<script type="text/javascript" src="Clock.js"></script>
<script type="text/javascript" src="AluCtrl.js"></script>
<script type="text/javascript" src="Memory.js"></script>
<script type="text/javascript" src="circuits/SignExt.js"></script>
<script type="text/javascript" src="circuits/Adder.js"></script>
<script type="text/javascript" src="circuits/AndGate.js"></script>
<script type="text/javascript" src="circuits/ConstGate.js"></script>
<script type="text/javascript" src="Join.js"></script>
<script type="text/javascript" src="circuits/Multiplexer.js"></script>
<script type="text/javascript" src="ProgramCounter.js"></script>
<script type="text/javascript" src="Control.js"></script>
<script type="text/javascript" src="circuits/Shift.js"></script>
<script type="text/javascript" src="Wire.js"></script>
<script type="text/javascript" src="InstructionMemory.js"></script>
<script type="text/javascript" src="RegisterSet.js"></script>
<script type="text/javascript" src="ALU.js"></script>
<script type="text/javascript" src="circuits/Multiplexer.js"></script>
<script type="text/javascript" src="SingleClockMips.js"></script>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Mini-MIPS Spielwiese</h1>
</div>
<div class="row">
<h2>Assembler in Bitstrings/Bitvektoren</h2>
<div class="span6">
<p class="well">
Hier MIPS-Assembler eingeben:<br />
<textarea style="width:100%; min-height:5em;" id="ex1_in"></textarea><br />
<small><strong>Unterstützte Befehle</strong>: add, addu, addi, addiu, sub, subu, and, andi, or, ori, nor, xor, xori, slt, sltu, sltiu, sll, sllv, srl, sra, srlv, j, jr, jal, beq, bne, lw, sw, lui, mfhi, mflo, mthi, mtlo<br />
Keine Kommentare :(</small><br />
<button class="button" id="ex1_go">Kodieren</button>
<button class="button" id="ex1_reset">Zurücksetzen</button>
</p>
</div>
<div class="span6" id="ex1_row">
Assembler:
<pre class="prettyprint linenums" id="ex1_ass"></pre>
Binary:
<pre class="prettyprint linenums" id="ex1_bin"></pre>
</div>
<script type="text/javascript">
$("#ex1_go").click(function() {
var lines = $("#ex1_in").val().split("\n");
var mem = new InstructionMemory();
try {
for(var i = 0; i < lines.length; i++) {
$("#ex1_ass").append(lines[i] + "\n");
// group by bytes and octets
var bit_vector = mem.decode(lines[i])
var binary_code = ""
for(var j = 0; j < bit_vector.length; j++) {
binary_code = binary_code + bit_vector[j]
if ((j+1) % 4 == 0) {
binary_code = binary_code + " "
}
}
$("#ex1_bin").append(binary_code + "\n");
}
} catch (e) {
display_error("#ex1_row", e)
}
})
$("#ex1_reset").click(function() {
$("#ex1_ass").text("");
$("#ex1_bin").text("");
})
</script>
</div><!-- ENDE beispiel1 -->
<div class="row">
<h2>ALU</h2>
<div class="row">
<div class="span6">
<p>
Die Eingabeoperanden für die ALU. Für nicht kommutative Operationen ist die Semantik <em>Op0 - Op1</em>. Leider funktionieren bisher nur vorzeichenlose Zahlen :(
</p>
<div class="input-prepend input-append">
<span class="add-on">Op0</span>
<input type="text" id="ex2_op0"></input>
<span class="add-on">
<sub id="ex2_op0_enc">10</sub>
</span>
<span class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">Codierung <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" id="ex2_op0_enc2">Binär</a></li>
<li><a href="#" id="ex2_op0_enc10">Dezimal</a></li>
<li><a href="#" id="ex2_op0_enc16">Hexadezimal</a></li>
</ul>
</span>
</div>
<div class="input-prepend input-append">
<span class="add-on">Op1</span>
<input type="text" id="ex2_op1"></input>
<span class="add-on">
<sub id="ex2_op1_enc">10</sub>
</span>
<span class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">Codierung <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" id="ex2_op1_enc2">Binär</a></li>
<li><a href="#" id="ex2_op1_enc10">Dezimal</a></li>
<li><a href="#" id="ex2_op1_enc16">Hexadezimal</a></li>
</ul>
</span>
</div>
</div>
<div class="span6">
<p>
Steuereingang: <input type="text" class="input-mini" id="ex2_ctrl_input" value="010" />
Der 3bit Steuereingang, der von ALUCtrl aus kommt, bestimmt die Operation, die die ALU ausführt (Script S. 211).
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btnarith" id="ex2_ctrl_add">add</button>
<button type="button" class="btn btnarith" id="ex2_ctrl_sub">sub</button>
<button type="button" class="btn btnarith" id="ex2_ctrl_eq">equals</button>
<button type="button" class="btn btnarith" id="ex2_ctrl_lt">less than</button>
</div><br />
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btnlogic" id="ex2_ctrl_and">and</button>
<button type="button" class="btn btnlogic" id="ex2_ctrl_or">or</button>
<button type="button" class="btn btnlogic" id="ex2_ctrl_andn">and not</button>
<button type="button" class="btn btnlogic" id="ex2_ctrl_orn">or not</button>
</div>
</p>
</div>
</div>
<div class="row">
<div class="span2">
<button class="btn btn-large btn-inverse" type="button" id="ex2_exec">Berechnen</button>
</div>
<div class="span8">
<strong>Ergebnis (Berechnung | Null): </strong><pre class="prettyprint linenums" id="ex2_res"></pre>
</div>
</div>
<script type="text/javascript">
var ex2 = {}
ex2.alu = new ALU();
ex2.op0_enc = 10;
ex2.op1_enc = 10;
ex2.ctrl = [0,1,0];
// mock the output wires for the alu
ex2.alu.outWire = {};
ex2.alu.zeroWire = {};
ex2.alu.outWire.receive = function(op) { $("#ex2_res").html(op.join("")) };
ex2.alu.zeroWire.receive = function(op) { $("#ex2_res").append(' |' + op) };
$("#ex2_op0_enc2").click(function() {
ex2.op0_enc = 2
$("#ex2_op0_enc").html(ex2.op0_enc)
})
$("#ex2_op0_enc10").click(function() {
ex2.op0_enc = 10
$("#ex2_op0_enc").html(ex2.op0_enc)
})
$("#ex2_op0_enc16").click(function() {
ex2.op0_enc = 16
$("#ex2_op0_enc").html(ex2.op0_enc)
})
$("#ex2_op1_enc2").click(function() {
ex2.op1_enc = 2
$("#ex2_op1_enc").html(ex2.op1_enc)
})
$("#ex2_op1_enc10").click(function() {
ex2.op1_enc = 10
$("#ex2_op1_enc").html(ex2.op1_enc)
})
$("#ex2_op1_enc16").click(function() {
ex2.op1_enc = 16
$("#ex2_op1_enc").html(ex2.op1_enc)
})
// controll
/**
* Wenn mal jemand Lust hat, könnte man ja auch
* den Input parsen...
*/
$("#ex2_ctrl_input").prop('disabled', true);
$("#ex2_ctrl_add").button('toggle')
$("#ex2_ctrl_add").click(function() {
ex2.ctrl = [0,1,0]
$(".btnlogic").removeClass('active')
$("#ex2_ctrl_input").val(ex2.ctrl.join(""))
})
$("#ex2_ctrl_sub").click(function() {
ex2.ctrl = [1,1,0]
$(".btnlogic").removeClass('active')
$("#ex2_ctrl_input").val(ex2.ctrl.join(""))
})
$("#ex2_ctrl_eq").click(function() {
ex2.ctrl = [1,1,0]
$(".btnlogic").removeClass('active')
$("#ex2_ctrl_input").val(ex2.ctrl.join(""))
})
$("#ex2_ctrl_lt").click(function() {
ex2.ctrl = [1,1,1]
$(".btnlogic").removeClass('active')
$("#ex2_ctrl_input").val(ex2.ctrl.join(""))
})
$("#ex2_ctrl_and").click(function() {
ex2.ctrl = [0,0,0]
$(".btnarith").removeClass('active')
$("#ex2_ctrl_input").val(ex2.ctrl.join(""))
})
$("#ex2_ctrl_or").click(function() {
ex2.ctrl = [0,0,1]
$(".btnarith").removeClass('active')
$("#ex2_ctrl_input").val(ex2.ctrl.join(""))
})
$("#ex2_ctrl_andn").click(function() {
ex2.ctrl = [1,0,0]
$(".btnarith").removeClass('active')
$("#ex2_ctrl_input").val(ex2.ctrl.join(""))
})
$("#ex2_ctrl_orn").click(function() {
ex2.ctrl = [1,0,1]
$(".btnarith").removeClass('active')
$("#ex2_ctrl_input").val(ex2.ctrl.join(""))
})
$("#ex2_exec").click(function() {
var rawOp0 = parseInt($("#ex2_op0").val()).toString(2).split("");
var rawOp1 = parseInt($("#ex2_op1").val()).toString(2).split("");
var j = rawOp0.length
for(var i = 0; i < 32 - j; i++) {
rawOp0 = [0].concat(rawOp0)
}
j = rawOp1.length
for(var i = 0; i < 32 - j; i++) {
rawOp1 = [0].concat(rawOp1)
}
ex2.op0 = new BitVector(rawOp0);
ex2.op1 = new BitVector(rawOp1);
ex2.ctrl = new BitVector(ex2.ctrl)
ex2.alu.receiveOp0(ex2.op0);
ex2.alu.receiveOp1(ex2.op1);
ex2.alu.receiveCtrl(ex2.ctrl);
})
</script>
</div><!-- -->
<div class="row">
<h2>Befehlsspeicher</h2>
<p>Der Befehlsspeicher bietet Zugriff auf den Speicher wie folgt: Im vorherigen Takt kam ein Befehlsindex, der sogenannte <strong>Program Counter</strong> auf der Eingangsleitung. Der Befehlsspeicher holt sich ab diesem Index 32 bit aus dem Speicher und schickt diese 32 Bit dann auf seine Ausgansleitung.</p>
<script type="text/javascript">
[Scripts für dieses Beispiel]
</script>
</div>
</div><!-- ENDE header div-->
<!-- Template für einzelne Beispiele
<div class="row">
<h2>[Überschrift]</h2>
<script type="text/javascript">
[Scripts für dieses Beispiel]
</script>
</div>
-->
</body>
</html>