-
Notifications
You must be signed in to change notification settings - Fork 3
/
next.html
188 lines (171 loc) · 7.44 KB
/
next.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
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="scrolling-nav.css" rel="stylesheet">
<link href="https://bootswatch.com/flatly/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body id="page-top" data-target=".navbar-fixed-top">
<nav class="navbar navbar-inverse navbar-fixed-top top-nav-collapse">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
</button>
<a class="navbar-brand page-scroll" href="index.html">Quine8</a>
<a class="navbar-brand page-scroll" href="q8.html">Previous</a>
<a class="navbar-brand page-scroll" href="next.html">Next</a>
</div>
</div>
</nav>
<section style="margin-top: 5em; max-width: 50em;">
<h2>What's Next?</h2>
<p>Bytecode is something that modern programmers
rarely have to touch. The rare few that do typically
get at least an assembler up and running as soon as
possible. Bytecode is rarely practical, and horrible
for maintenance and readability.</p>
<p>Even the most basic of assemblers hold a few critical
advantages. With bytecode, the code you write
has to conform to fixed positions. If you want to jump
to a point in code, or access a place in memory, that
position must be hardcoded. On top of that, assembly
uses mnemonics that are far easier to remember and quickly
interpret. rather than needing a instruction table,
most assembly instructions are intuitive. <code>ADD A B</code>
is far easier to read and manage mentally than a block containing the number <code>11</code>.</p>
<p>Comments are also quite
useful. With bytecode, there's only space for code and data,
as everything you write could be executed by the processor.
With assembly, you can select lines or parts of lines to ignore,
and use that space to store information to clarify program
specifics to the reader.</p>
<p>Bytecode maintains one advantage. Self-modification. A
clever programmer writing bytecode can take make use of far
more than the apparant usable space by storing new instructions
on top of the old ones, and then re-executing the block.</p>
<p>Unfortunately, it does have a few drawbacks.
While it's nice for space-saving, it's not great for the modern
processor's caching systems. When you modify the code at runtime,
the processor's cached bytecode becomes invalid, and it has to
stop and pull in the new code. Additionally, it's not great
for system security. If the program can modify itself, the
user may be able to coerce the program to make malicious self-modifications,
jumping into blocks of code that the program wasn't intended to run.</p>
<h2>Manual Bytecode Generation</h2>
<p>Written in bytecode manually, I had to first write the program out on paper,
and then translate the chunks into operations by consulting the instruction table.
This was slow to write, and annoying to debug.</p>
<div style="width: 40%; margin-left: auto; margin-right: auto;">
<h3>Bytecode Program</h3>
<ul style="margin-left: auto; margin-right: auto;">
<li>writing requires complex mental model</li>
<li>separation of code and output unclear</li>
<li>reading requires lookup table for ops</li>
</ul>
<a href="q8.html#AwRgrMwExikgNhAUypSYGQQdnSAQygBZ0zyLLKoAzQ4ATnyxAA4QBjGu0zUA4gGYqI0WPKI4UPMABGUBN2CYQhEuSylx2nbr36Dho8ZOmz5i5avlBHIA">
<div class="img_container">
<img class="img_link" style="width: 170%;" src="mult.gif">
</div>
</a>
</div>
<h2>Automatic Bytecode Generation</h2>
<p>Taking far less time to write, this was written in assembly and then
assembled using an assembler. The resulting program performs the same operations
in the same period of time, and the source is readable, and far more easily modified.
As an added legibility bonus, logical errors are far easier to spot.</p>
<div class="multi_code_container">
<div>
<h3>Assembly Program</h3>
<ul style="margin-left: auto; margin-right: auto; width: 60%;">
<li>requires knowledge of asm</li>
<li>fewer hardcoded positions</li>
<li>lots of space for comments</li>
</ul>
<pre><code class="language-none; line-numbers">; INIT
start:
LOAD A 80 ; load x
LOAD B 81 ; load y
CMP A B ; is x > y?
JG swap ; goto swap
; 9 - SAVE_VAR
save_var:
STORE A 96 ; save min(x, y) as i
STORE B 112 ; save max(x, y) as increment
JMP loop
; 32 - SWAP
swap:
SWAP A B ; (x, y) -> (y, x)
JMP save_var
; 36 - LOOP
loop:
LOAD A 96 ; get i
ISZERO A ; is i == 0?
JZ exit
DEC A ; i--
STORE A 96 ; save new i
JMP add_increment
; 67 - ADD INCREMENT
add_increment:
LOAD A 97 ; read in cumulative value
LOAD B 112 ; read in increment
ADD A B ; cumulative = cumulative + increment
JERR exit ; if overflow, exit
STORE A 97 ; save new cumulative
JMP loop
; 255 - EXIT
exit:
HALT
; DATA
$80 6 4 ; x, y</code></pre>
</div>
<div class="c_and_img">
<div>
<h3>Assembled Program</h3>
<ul>
<li>final program more compact</li>
<li>visual code block distinction is harder</li>
<li>no ability to add annotation</li>
</ul>
<a href="q8.html#AwRgrMwExiIGwgKbACbDPS8DsoCGI0AZiPsHgqABwgDGMIALBlmWaItHsAEZTwYrOIWABmOpCnSZsufIWKly+VhYqNmrdp269+g4aPGTps7qA===">
<div class="img_container">
<img class="img_link" style="width: 90%;" src="asm_mult.gif">
</div>
</a>
</div>
</div>
</div>
</section>
<div class="asm-footer">
<h3>For those of you who've made it this far</h3>
<div class="asm-footer-banner">
<a href="q8a.html">Here's an Assembler</a>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="ie10-viewport-bug-workaround.js"></script>
<script src="jquery.easing.min.js"></script>
<script src="scrolling-nav.js"></script>
<link rel="stylesheet" href="prism.css">
<link href="tutorial_style.css" rel="stylesheet">
<script src="prism.js"></script>
</body>
<footer style="margin-top: 4em; padding-bottom: 4em; background-color: #555;"></footer>
</html>