/
main.html
371 lines (330 loc) · 16.5 KB
/
main.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="FRISCjs - FRISC processor simulator in JavaScript" />
<meta name="author" content="Ivan Zuzak" />
<title> FRISCjs - FRISC processor simulator in JavaScript</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" />
<link rel="stylesheet" href="ace-mode-frisc.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="friscasm.js"></script>
<script type="text/javascript" src="friscjs.js"></script>
<script type="text/javascript" src="https://raw.github.com/ajaxorg/ace/master/build/src/ace.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/bootstrap-tab.js"></script>
<script type="text/javascript" src="https://raw.github.com/madrobby/keymaster/master/keymaster.js"></script>
<script type="text/javascript" src="ace-mode-frisc.js"></script>
</head>
<body>
<div class="container" style="width: 1140px">
<h1> FRISCjs <small> FRISC processor simulator in JavaScript </small> </h1>
<ul class="nav nav-tabs">
<li class="active"><a href="#sim" data-toggle="tab">Simulator</a></li>
<li><a href="#frisc-usage" data-toggle="tab">Usage instructions</a></li>
<li><a href="#frisc-about" data-toggle="tab">About</a></li>
</ul>
<div class="tab-content">
<div class="container tab-pane" id="frisc-usage" style="margin-bottom: 20px; width: auto;">
<div id="frisc-upute" class="well" style="visible: false">
<h3> Usage instructions </h3>
<ol>
<li> Enter your FRISC assembler program into the textbox on the left. Note: the simulator has a memory module of 256KB, i.e. from 0x00000000 to 0x0003FFFF.</li>
<li> Press the <b>"Load"</b> button to parse the program and load it into memory. In case of parsing errors, the error message, line and column numbers will be logged to the output screen.</li>
<li> Press the <b>"Run all"</b> button to start the CPU.</li>
<li> Enter the instructions-per-second frequency and press <b>"Set CPU freq!"</b> to change the CPU speed.</li>
<li> Press the <b>"Pause"</b> button to pause CPU execution.</li>
<li> Press the <b>"Run one"</b> button to force the CPU to execute the next instruction.</li>
<li> Press the <b>"Stop"</b> button to stop the CPU completely and return to defining the program. </li>
<li> Press the <b>"Clear"</b> button to clear the log output screen. </li>
<li> To view the state of a part of memory, enter the lower and upper bound into the textboxes and press <b>"Show memory state"</b>.
<p>You can choose wether you want the memory to be displayed in <b>hexadecimal</b> or <b>decimal</b> form by clicking on the button next to HEX, or DEC.</p>
</li>
</ol>
<p>You can read more about how FRISC works <a href="http://www.fer.unizg.hr/_download/repository/knjiga_FRISC_izvadak.pdf">here</a>. You can find the FRISC cheat sheet <a href="http://www.fer.unizg.hr/_download/repository/salabahter_cijeli.pdf">here</a>.</p>
</div>
</div>
<div class="container tab-pane" id="frisc-about" style="margin-bottom: 20px; width: auto;">
<div id="frisc-about" class="well" style="visible: false">
<h3> About </h3>
<p>
FRISCjs is a simulator of the FRISC processor written in JavaScript.<br>
FRISC is a simple RISC processor developed at the <a href="http://fer.unizg.hr/en">Faculty of Electrical Engineering and Computer Science</a>, Zagreb. <a href="http://www.fer.unizg.hr/rasip/knjige/frisc">More...</a><br>
The simulator has two parts: a <a href="https://github.com/izuzak/FRISCjs/blob/master/friscasm.pegjs">FRISC assembler</a> (built using PEGjs) which translates FRISC assembly code to machine code and a <a href="https://github.com/izuzak/FRISCjs/blob/master/friscjs.js">FRISC CPU simulator</a> which executes machine code.<br>
This Web application is a graphical interface for the simulator, while there also exists a <a href="https://github.com/izuzak/FRISCjs/blob/master/main.js">console interface which runs on NodeJS</a>.
</p>
<h3> Source code and bug reports </h3>
<p>
The complete source code for FRISCjs and this Web application is <a href="https://github.com/izuzak/FRISCjs">available on GitHub</a>.
Please use the GitHub issue tracker for reporting bugs and feature requests.
</p>
<h3> Credits and licence </h3>
<p>
FRISCjs was developed by <a href="http://ivanzuzak.info">Ivan Zuzak</a>. License: <a href="https://github.com/izuzak/FRISCjs/blob/master/LICENSE.markdown">Apache 2.0.</a> Contributors: <a href="https://github.com/ibudiselic">Ivan Budiselic</a>, <a href="https://github.com/Stankec">Stanko Krtalic</a>.
</p>
<p>
FRISCjs is built with many open-source projects: <a href="http://pegjs.majda.cz/">PEGjs</a>, <a href="http://nodejs.org">NodeJS</a>, <a href="http://jquery.com">jQuery</a>, <a href="http://twitter.github.com/bootstrap">Bootstrap</a> and <a href="http://ace.ajax.org/">Ace</a>.
</p>
</div>
</div>
<div class="active container-fluid tab-pane" style="padding-left: 0px;" id="sim">
<div class="sidebar" id="frisc-inputdiv" style="width: 450px; height: 500px;">
</div>
<div class="content" style="margin-left: 460px;">
<div id="frisc-controls" style="float: left; margin-left: 10px;">
<div id="frisc-cpu-controls" class="form-inline" style="width: 650px;">
<button type="button" class="btn btn-success" id="frisc-load"><i class="icon-download-alt icon-white"></i> Load</button>
<button type="button" class="btn btn-primary" id="frisc-execute"><i class="icon-fast-forward icon-white"></i> Run all</button>
<button type="button" class="btn btn-primary" id="frisc-next"><i class="icon-step-forward icon-white"></i> Run one</button>
<button type="button" class="btn btn-primary" id="frisc-pause"><i class="icon-pause icon-white"></i> Pause</button>
<button type="button" class="btn btn-danger" id="frisc-stop"><i class="icon-stop icon-white"></i> Stop</button>
<input type="text" class="input-mini" style="margin-bottom: 0px;" id="frisc-freq" value="1000" />
<button type="button" class="btn" id="frisc-freqset">Set CPU freq</button>
<button type="button" class="btn btn-primary" id="frisc-clear"><i class="icon-remove-sign icon-white"></i> Clear</button>
</div>
<div id="cpuout" style="font-size: 10pt; font-family: courier new; background-color: #D4CDCF; width: 650px; height: 150px; overflow: auto; border: 1px solid #666; padding: 8px; margin-top: 15px; color: black;"></div>
<div id="frisc-memcontrols" class="form-inline" style="width: 650px; margin-top: 15px;">
<label>Lower memory bound:</label>
<input type="text" class="input-mini" id="frisc-mem-lower" value="0" />
<label>Upper memory bound:</label>
<input type="text" class="input-mini" id="frisc-mem-upper" value="100" />
<label class="radio"> <input type="radio" name="optionsRadios" id="skrBaseRadioDec" value="option1" checked=""> DEC </label>
<label class="radio"> <input type="radio" name="optionsRadios" id="skrBaseRadioHex" value="option2"> HEX </label>
<button type="button" class="btn" id="frisc-mem-refresh">Show memory state</button>
</div>
<div id="memout" style="font-size: 10pt; font-family: courier new; background-color: #D4CDCF; width: 650px; height: 150px; overflow: auto; border: 1px solid #666; padding: 8px; margin-top: 15px; color: black;"></div>
</div>
<script type="text/javascript">
key('backspace', function(){ return false; });
$("#frisc-input").height(($("body").height() - ($("#frisc-usage").height()) - 40 + "px"));
var height = ($("#frisc-inputdiv").innerHeight() - $("#frisc-cpu-controls").innerHeight() * 2)/2 - 40 + "px";
$("#cpuout").height(height);
$("#memout").height(height);
var _state = "stopped";
// create FRISC
var simulator = new FRISC();
simulator.CPU._frequency = parseFloat($("#frisc-freq").val());
window.onload = function() {
$(function() { $("li").css("color", "#404040"); });
editor = ace.edit("frisc-inputdiv");
var FriscMode = require("ace/mode/frisc").Mode;
editor.getSession().setMode(new FriscMode());
document.getElementById('frisc-inputdiv').style.fontSize='10pt';
document.getElementById('frisc-inputdiv').style.fontFamily='courier new';
$(".ace_gutter").width("40px");
editor.renderer.setHScrollBarAlwaysVisible(false);
editor.getSession().setValue("; aluop\n\
lab1 ADD R1, R2, R3\n\
lab2 ADD r2, 5, r5\n\
ADD r5, lab1, r2\n\
; cmpop\n\
CMP R1, R2\n\
lab5 CMP R1, 5\n\
lab6 CMP r4, lab5\n\
; moveop\n\
lab7 MOVE R4, R5\n\
lab8 MOVE R5, SR\n\
lab9 MOVE SR, r5\n\
MOVE lab5, r4\n\
lab11 MOVE lab6, sr\n\
; uprop\n\
JP lab2\n\
JP_N 54\n\
lab12 JP_UGE (r1)\n\
lab13 RETI_M\n\
; memop\n\
lab14 STORE r1, (r2)\n\
STORE r4, (r3+23)\n\
STORE r4, (lab14)\n\
lab15 STORE r5, (200)\n\
lab16 POP r3\n\
; asmop\n\
lab17 `ORG 234\n\
`DW 1,2,3,4,5\n\
`DW 54\n\
lab18 `EQU 300\n\
lab19 `DS 12\n\
lab21 `BASE H\n\
lab22 DW 54\n\
DH 34\n\
DB 12\n\
lab20 `END\n\
lab23 ADD R1, R2, R3\n\
; fds fsd';");
editor.resize();
};
function simulatorLog(text, marginLeft) {
if (typeof text !== "string") {
text = JSON.stringify(text);
}
if (typeof marginLeft === "undefined") {
marginLeft = "0px";
}
$("#cpuout").append("<div style='margin: 1px; margin-left: " + marginLeft + "; padding: 0px;'>" + text + "</div>");
$("#cpuout").scrollTop($("#cpuout")[0].scrollHeight);
}
function memLog(text) {
$("#memout").html(text);
}
function getBase () {
if ($("#skrBaseRadioDec").is(':checked')) {
return 10;
} else {
return 16;
}
}
function getMemState(lower, upper) {
var memStateString = "";
var base = getBase();
for (var i=lower; i>=0 && i<simulator.MEM._memory.length && i<upper; i+=4) {
var decoded = simulator.CPU._decode(simulator.MEM.read(i));
decoded = decoded ? " - " + instructionToString(decoded) : "";
memStateString += i.toString(base)+ ": " + simulator.MEM.read(i).toString() + " - " + convertIntToBinary(simulator.MEM.read(i), 32) + decoded + "</br>";
}
return memStateString;
}
function changeState(st) {
if (st === "stopped") {
enableElements(["#frisc-input", "#frisc-load"]);
disableElements(["#frisc-execute", "#frisc-next", "#frisc-pause", "#frisc-stop"]);
_state = st;
} else if (st ==="loaded") {
enableElements(["#frisc-execute", "#frisc-next", "#frisc-stop"]);
disableElements(["#frisc-input", "#frisc-load", "#frisc-pause"]);
_state = st;
} else if (st === "running") {
enableElements(["#frisc-stop", "#frisc-pause", "#frisc-next"]);
disableElements(["frisc-execute", "#frisc-input", "#frisc-load"]);
_state = st;
}
}
changeState("stopped");
function enableElements(elems) {
for (var i=0; i<elems.length; i++) {
$(elems[i]).attr('disabled', false);
}
}
function disableElements(elems) {
for (var i=0; i<elems.length; i++) {
$(elems[i]).attr('disabled', true);
}
}
function cpuStateToString() {
var retVal = "";
for (var key in simulator.CPU._r) {
if (key !== 'sr') {
retVal += key + ": " + simulator.CPU._r[key].toString() + " ";
} else {
retVal += key + ": " + simulator.CPU._r[key].toString() + " ( ";
for (var flag in simulator.CPU._f) {
retVal += flag + ": " + simulator.CPU._getFlag(simulator.CPU._f[flag]) + " ";
}
retVal += ") ";
}
}
return retVal;
}
function instructionToString(instruction) {
if (typeof instruction.args === 'undefined' || instruction.args === null) {
return instruction.op;
} else {
return instruction.op + " " + instruction.args.join(" ");
}
}
simulator.CPU.onBeforeRun = function() {
simulatorLog("<span style='padding: 2px 4px 1px'; class='label label-success'><b>Starting (or continuing) simulation!</b></span>");
};
simulator.CPU.onBeforeCycle = function() {
simulatorLog("<span style='padding: 2px 4px 1px'; class='label label-success'><b>New CPU cycle starting!</b></span>");
simulatorLog("<span style='padding: 2px 4px 1px'; class='label label-info'>CPU state:</span>" + " " + cpuStateToString(), "10px");
};
simulator.CPU.onAfterCycle = function() {
simulatorLog("<span style='padding: 2px 4px 1px'; class='label label-info'>CPU state:</span>" + " " + cpuStateToString(), "10px");
};
simulator.CPU.onBeforeExecute = function(instruction) {
simulatorLog("<span style='padding: 2px 4px 1px'; class='label label-info'>Executing FRISC instruction:</span>" + " " + instructionToString(instruction), "10px");
};
simulator.CPU.onStop = function() {
simulatorLog("<span style='padding: 2px 4px 1px'; class='label label-warning'><b>FRISC processor stopped!</b></span>");
changeState("stopped");
};
$("#frisc-load").click(function() {
if (_state === "stopped") {
try {
simulator.CPU.reset();
var source = editor.getSession().getValue();
if (source.length > 0 && source[source.length-1] !== '\n') {
source += '\n';
}
var result = frisc_asm.parse(source);
simulator.MEM.loadBinaryString(result.mem);
simulatorLog("<span style='padding: 2px 4px 1px'; class='label label-success'><b>Input program parsed successfully.</b></span>");
changeState("loaded");
} catch (e) {
simulatorLog("<span style='padding: 2px 4px 1px'; class='label label-important'><b>Parsing error</b></span> on line " + e.line + " column " + e.column + " -- " + e.toString() + "");
}
}
});
$("#frisc-execute").click(function() {
if (_state === "loaded") {
simulator.CPU.run();
changeState("running");
}
});
$("#frisc-stop").click(function() {
if (_state === "running" || _state === "loaded") {
simulator.CPU.stop();
changeState("stopped");
}
});
$("#frisc-next").click(function() {
if (_state === "running" || _state === "loaded") {
simulator.CPU.performCycle();
}
});
$("#frisc-pause").click(function() {
if (_state === "running") {
simulator.CPU.pause();
changeState("loaded");
}
});
$("#frisc-clear").click(function() {
$("#cpuout").html("");
});
$("#frisc-freqset").click(function() {
simulator.CPU._frequency = parseFloat($("#frisc-freq").val());
});
$("#frisc-mem-refresh").click(function() {
var lower = parseInt($("#frisc-mem-lower").val());
var higher = parseInt($("#frisc-mem-upper").val());
if(getBase() === 16) { //If HEX
lower = parseInt($("#frisc-mem-lower").val(), 16);
higher = parseInt($("#frisc-mem-upper").val(), 16);
}
memLog(getMemState(lower, higher));
});
$("#skrBaseRadioDec, #skrBaseRadioHex").click(function() {
// $("#frisc-mem-refresh").click();
});
</script>
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25513601-1']);
_gaq.push(['_setDomainName', 'auto']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
</div>
</div>
</div>
</div>
</body>
</html>