-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
283 lines (269 loc) · 15.2 KB
/
index.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html manifest="ram.appcache">
<head>
<title>Random Access Machine Emulator (by Simon Gottlieb and Simon Koennecke)</title>
<script type="text/javascript" src="./js/jquery-1.10.2.min.js"></script>
<script>
$.noConflict();
// Code that uses other library's $ can follow here.
</script>
<script type="text/javascript" src="./js/bootstrap.min.js"></script>
<script type="text/javascript" src="./js/ha.js"></script>
<link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css" media="all" />
<link rel="stylesheet" type="text/css" href="./css/bootstrap-theme.min.css" media="all" />
<link rel="stylesheet" type="text/css" href="./css/ha.css" media="all" />
</head>
<body>
<header>
<h2>Random Access Machine Emulator</h2>
<a href="https://github.com/simonkoennecke/ram"><img style="position: absolute; top: 0; right: 0; border: 0;z-index: 100;width: 106px;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>
<div class="input-group button-run">
<div class="input-group">
<span class="input-group-addon button-run-addon">
<button class="btn btn-default" type="button" onclick="run()"><span class="glyphicon glyphicon-play"></span></button>
</span>
<select name="runMode" id="runMode" class="form-control">
<option value="run">Run</option>
<option value="animated" selected="selected">Animated</option>
<option value="debug">Debug</option>
</select>
</div><!-- /input-group -->
</div>
<!--
<button type="button" class="btn btn-default" onclick="runAnimated()">
<span class="glyphicon glyphicon-cog"></span> Run animated
</button>
<button type="button" class="btn btn-default" onclick="debug()">
<span class="glyphicon glyphicon-wrench"></span> Debug
</button>
-->
<button type="button" class="btn btn-default" onclick="pause()" id="ramPause" disabled="disabled">
<span class="glyphicon glyphicon-pause"></span> Pause
</button>
<button type="button" class="btn btn-default" onclick="nextStep()" id="ramNext" disabled="disabled">
<span class="glyphicon glyphicon-share-alt"></span> Next
</button>
<button type="button" class="btn btn-default" onclick="resetAndstop(RAM)" id="ramStop">
<span class="glyphicon glyphicon-stop"></span> Reset
</button>
<button type="button" class="btn btn-default" onclick="getLink()" id="ramLink">
<span class="glyphicon glyphicon-link"></span> Link
</button>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#infoModal">
<span class="glyphicon glyphicon-question-sign"></span> Manual
</button>
<div style="display:none;" id="ram_url">
<div class="input-group input-group-lg ram-url" style="width:98%;">
<span class="input-group-addon">URL</span>
<input type="text" class="form-control" value="0">
</div>
</div>
<div class="modal" id="infoModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h2 class="modal-title">A Random Access Machine (RAM)</h2>
For a description of RAM, please see the Wikipedia page <a href="http://en.wikipedia.org/wiki/Random-access_machine" target="_blank">here</a> or see also the German script of lecture <a href="http://www.pnjb.de/uni/ws1011/hoehere-algorithmik.pdf" target="_blank">here</a> (section 1.2 "Berechnungsmodelle").
</div>
<div class="modal-body">
<ul class="nav nav-tabs">
<li class="active"><a href="#overview" data-toggle="tab">Overview</a></li>
<li><a href="#function_of_emulater" data-toggle="tab">Functionality of Emulator</a></li>
<li><a href="#commands" data-toggle="tab">Commands</a></li>
<li><a href="#samples" data-toggle="tab">Examples</a></li>
<li><a href="#authors" data-toggle="tab">Authors</a></li>
<li><a href="#license" data-toggle="tab">License</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="overview">
<h3>The Random Acess Machine Emulator</h3>
<p>The Random Access Machine (RAM; German: Registermaschine) is a mathematical model to help to evaluated algorithm by runtime and memory consumptions. The RAM runs on a low set of instructions. This set of instruction is turing complete. For more details about the set of instruction see the tab "Commands".</p>
<p>
With this Emulator we want to give the possibility to run a RAM program. Details on how to use our RAM Emulator can be found on the tab "Functionality of Emulator". We also provide some examples program on the tab "Examples".
The RAM Emulator was created for the lecture "Höhere Algorithmik" at Freie Universität Berlin thought by Helmut Alt.
</p>
</div>
<div class="tab-pane" id="function_of_emulater">
<h3>Run (Mode)</h3>
The "play" can be run in three modes:
<ul>
<li>Run:<br/>
This mode will not take care of any breaking points or anything else expect the given code.
</li><li>Animated: <br/>
The code will be run by highlighting the current line and a specific amount of time will pass between each command. The register will also be colored: red -> writing, yellow ->reading as an indirect address, green -> reading as a direct address.
</li><li>Debug:<br/>
The debug mode will run until a break point is set, then the RAM hold and the "Next" or "Play" buttons can be pressed.
</li>
</ul>
All modes will set the editor to read-only. After execution the editor will get the writing permission back.
<h3>Pause</h3>
The pause button can be pressed when the RAM is running in the "run" and "animated" modes. After pressing the pause button the processing of program code will end in the debug mode. Now you can continue with "Next" or a differed run mode.
<h3>Next</h3>
When the program is paused the "Next" button is enabled. After pressing the "Next" Button one line of code will be execute. Therefore, you can iterate step by step through the code. Please Note, all register can be manipulated between executes.
If the program stops at a break point or the pause button is pressed then "Next" button will be disabled. The code can run with this button step by step.
<h3>Reset</h3>
The reset button will always reset the RAM to not running and will restore the default value of the registers.
<h3>Link</h3>
The "Link" button should help you to share your code with your friends or teaching assistants.
<h3>Register add / remove</h3>
The + and - buttons on the right side will add and remove a register.
</div>
<div class="tab-pane" id="commands">
The RAM runs on a low set of commands.
<h3>Assignment</h3>
The signs for assignment are := / =. This command can change the state of a register.
<h3>Addressing</h3>
There are different ways of addressing registers. Directly, like R1 or indirectly (R1). For example, RAM runs with the registers R0=1, R1=2 and R3=3 with following program:<br/>
(R0)=22 <br/>
R3 = 0 <br/>
HALT <br/>
The RAM will end with the following values in the register: R0=1, R1=22 and R3=0.
<h3>Operations</h3>
<p>The valid operations for this emulator are +,-,* and /. All operations are based on integers.
<h3>Label</h3>
Every line can be marked with a label simply by adding an alphanumerical word ending with ":" at the beginning of a line. Now the label can be used in GOTO statements.
<h3>GOTO Statements</h3>
<p>
There is a limited set of GOTO statements with and without conditions:
</p><p>
<b>GOTO</b> «Label»
</p><p>
Go to a label without any validation of a condition.
</p><p>
<b>GGZ</b> «Expression: Value or Register», «Label»
</p><p>
Go to the label if the expression is greater than zero.
</p><p>
<b>GLZ</b> «Expression: Value or Register», «Label»
</p><p>
Go to the label if the expression is less than zero.
</p><p>
<b>GZ</b> «Expression: Value or Register», «Label»
</p><p>
Go to the label if the expression is equal to zero.
</p>
<h3>Comments</h3>
Comments help to improve the readability of code. RAM code in particular needs to be commented because you need a lot of lines to realize simple things. The command are ";" or "/".
<h3>HALT</h3>
To complete the RAM successfully it needs to end with a HALT command.
</div>
<div class="tab-pane" id="samples">
<p>
<a href="mailto:simonkoennecke+ram@gmail.com?Subject=RAM%20Emulator%20Sample%20Code" target="_blank">Please send us your RAM Code of an interesting algorithm.</a>
</p><p>Examples:</p>
<ul>
<li><a href=#reg=0;3;0&code=%3BThis%20programm%20runs%20a%20loop%2010%20times%0AR0%20%3D%2010%0Aloop%3A%0A%3B%20This%20lines%20beeing%20executed%2010%20times%0AR0%20%3D%20R0%20-%201%0AGGZ%20R0%2C%20loop%0AHALT" target="_blank">Simple Loop</a>
</li>
<li>
<a href="#reg=10;3;2;3;2;3;2;3;2;3;2&code=%3B%20Simple%20programm%20to%20fill%20R1-R10%20with%20zeros%0A%0Aloop%3A%20GZ%20R0%2C%20end%0A%28R0%29%20%3D%200%0AR0%20%3D%20R0%20-%201%0AGOTO%20loop%0A%0Aend%3A%0AHALT" target="_blank">Fill Register 1-10 with zeros</a>
</li><li>
<a href="#reg=10;3;2;3;2;3;2;3;2;3;2&code=%3B%20Calculates%20sum%20of%20R1%20-%20R10%20and%20saves%20it%20in%20R1%0A%0Aloop%3A%0AR1%20%3D%20R1%20+%20%28R0%29%0AR0%20%3D%20R0%20-%201%0AGGZ%20R0%2C%20loop%0A%0AR1%20%3D%20R1%20/%202%0AHALT" target="_blank">Calculate sum of Register 1-10</a></li>
<li>
<a href="#reg=1;161604;0&code=%3B%20A%20very%20simple%20GOTO%20use%20case%0AR0%20%3D%201%0AGOTO%20l1%0A%0A%0Al1%3A%20R1%20%3D%20R1%20+%201%0AGOTO%20l6%0Al2%3A%20R1%20%3D%20R1%20*%20R1%0AGOTO%20l5%0Al3%3A%0AHALT%20%20%0Al5%3A%20R1%20%3D%20R1%20+%202%0AGOTO%20l4%0Al6%3A%20R1%20%3D%20R1%20*%205%0AGOTO%20l2%0Al4%3A%20R1%20%3D%20R1%20*%20R1%0AGOTO%20l3%0A%0A%3Bplease%20don%27t%20write%20your%20code%20like%20this%20%3A-%28" target="_blank">Simple GOTO example</a>
</li>
</ul>
</div>
<div class="tab-pane" id="authors">
<h3>Simon Gene Gottlieb</h3>
<h3>Simon Koennecke</h3>
<a href="mailto:simonkoennecke+ram@gmail.com?Subject=RAM%20Emulator" target="_blank">Mail us if you have any question about the tool.</a>
</div>
<div class="tab-pane" id="license">
<p>
Copyright (c) 2013 Simon Gene Gottlieb, Simon Koennecke
</p><p>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
</p><p>
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
</p><p>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</p>
<p>Please notice, the used Frameworks have following licenses:</p>
<ul>
<li>Bootstrap (CSS Framework): Copyright 2013 Twitter, Inc under the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank" rel="nofollow">Apache 2.0</a> license.</li>
<li>jQuery (JavaScript Framework): <a href="http://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt" target="_blank" rel="nofollow">MIT license.</a></li>
<li>ACE (JavaScript Editor): BSD license.</li>
</div>
</div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!--
<button type="button" class="btn btn-default" onclick="reset()" id="ramReset">
<span class="glyphicon glyphicon-step-backward"></span> Reset
</button>
-->
<div class="form-inline" id="register">
<div class="input-group input-group-lg register-button">
<button type="button" class="btn btn-default btn-lg" onclick="addRegister()">
<span class="glyphicon glyphicon-plus"></span>
</button>
<button type="button" class="btn btn-default btn-lg" onclick="removeRegister()">
<span class="glyphicon glyphicon-minus"></span>
</button>
</div>
<div class="input-group input-group-lg">
<span class="input-group-addon">EKM</span>
<input type="text" id="ram_ekm" class="form-control" value="0" disabled="disabled">
</div>
<div class="input-group input-group-lg">
<span class="input-group-addon">LKM</span>
<input type="text" id="ram_lkm" class="form-control" value="0" disabled="disabled">
</div>
<div id="setRegister" data="4;3;"></div>
</div>
</header>
<div class="input">
<div id="code">; R0 = base
; R1 = exponent
GZ R1, exp_zero ;if R0^0 goto this special case
R2 = R0 ;remember the base for every iteration
R1 = R1 - 1 ;decrease the counter, because the loop should run only R1 times.
while: GZ R1, ende ;loop until R1 is zero
R0 = R0 * R2 ;multiply the current value with the start value of R0
R1 = R1 - 1 ;decrease the exponent
GOTO while ;goto to the head of the loop
exp_zero: R0 = 1 ;Case R0 ^ 0
ende: R1 = 1 ;set exponent to 1 to ensure that R0 will not change
HALT ; R0 = R0 ^ R1</div>
</div>
<div class="output">
<div id="setRunRegister"></div>
<div id="run"></div>
</div>
<div style="clear:both;"></div>
<script src="./js/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("code");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/assembly_x86");
editor.getSession().setBreakpoint(2);
editor.on("guttermousedown", function(e){
var target = e.domEvent.target;
if (target.className.indexOf("ace_gutter-cell") == -1)
return;
if (!editor.isFocused())
return;
if (e.clientX > 25 + target.getBoundingClientRect().left)
return;
var row = e.getDocumentPosition().row
if(editor.session.getBreakpoints()[row] == undefined)
e.editor.session.setBreakpoint(row)
else
e.editor.session.clearBreakpoint(row)
e.stop()
})
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46403112-1', 'farbtrommel.de');
ga('send', 'pageview');
</script>
</body>
</html>