<s>
The	O
Hack	B-Device
Computer	I-Device
is	O
a	O
theoretical	O
computer	B-General_Concept
design	I-General_Concept
created	O
by	O
Noam	O
Nisan	O
and	O
Shimon	O
Schocken	O
and	O
described	O
in	O
their	O
book	O
,	O
The	O
Elements	O
of	O
Computing	O
Systems	O
:	O
Building	O
a	O
Modern	O
Computer	O
from	O
First	O
Principles	O
.	O
</s>
<s>
In	O
using	O
the	O
term	O
“	O
modern	O
”	O
,	O
the	O
authors	O
refer	O
to	O
a	O
digital	O
,	O
binary	O
machine	O
that	O
is	O
patterned	O
according	O
to	O
the	O
von	B-Architecture
Neumann	I-Architecture
architecture	I-Architecture
model	O
..	O
</s>
<s>
The	O
Hack	B-Device
computer	I-Device
is	O
intended	O
for	O
hands-on	O
virtual	O
construction	O
in	O
a	O
hardware	B-Architecture
simulator	O
application	O
as	O
a	O
part	O
of	O
a	O
basic	O
,	O
but	O
comprehensive	O
,	O
course	O
in	O
computer	B-General_Concept
organization	I-General_Concept
and	I-General_Concept
architecture	I-General_Concept
.	O
</s>
<s>
In	O
the	O
twelve	O
projects	O
included	O
in	O
the	O
course	O
,	O
learners	O
start	O
with	O
a	O
two	O
input	O
Nand	O
gate	O
and	O
end	O
up	O
with	O
a	O
fully	O
operational	O
virtual	O
computer	O
,	O
including	O
both	O
hardware	B-Architecture
(	O
memory	B-General_Concept
and	O
CPU	O
)	O
and	O
software	O
(	O
assembler	O
,	O
VM	O
,	O
Java-like	O
programming	O
language	O
,	O
and	O
OS	O
)	O
.	O
</s>
<s>
In	O
addition	O
to	O
the	O
hardware	B-Architecture
simulator	O
used	O
for	O
initial	O
implementation	O
of	O
the	O
computer	B-Architecture
hardware	I-Architecture
,	O
a	O
complete	O
Hack	B-Device
computer	I-Device
emulator	B-Application
program	O
and	O
assembler	O
that	O
supports	O
the	O
projects	O
described	O
in	O
the	O
book	O
and	O
the	O
on-line	O
course	O
is	O
also	O
available	O
at	O
the	O
author	O
's	O
web	O
site	O
.	O
</s>
<s>
The	O
Hack	B-Device
computer	I-Device
hardware	B-Architecture
consists	O
of	O
three	O
basic	O
elements	O
as	O
shown	O
in	O
the	O
block	O
diagram	O
.	O
</s>
<s>
There	O
are	O
two	O
separate	O
16-bit	B-Device
memory	B-General_Concept
units	O
and	O
a	O
central	B-General_Concept
processing	I-General_Concept
unit	I-General_Concept
(	O
CPU	O
)	O
.	O
</s>
<s>
Because	O
data	O
is	O
moved	O
and	O
processed	O
by	O
the	O
computer	O
in	O
16-bit	B-Device
words	O
,	O
the	O
Hack	B-Device
computer	I-Device
is	O
classified	O
as	O
a	O
16-bit	B-Device
architecture	I-Device
.	O
</s>
<s>
The	O
instruction	O
memory	B-General_Concept
,	O
implemented	O
as	O
read-only	B-Device
memory	I-Device
from	O
the	O
viewpoint	O
of	O
the	O
computer	O
and	O
designated	O
ROM	B-Device
,	O
holds	O
assembled	O
binary	O
program	O
code	O
for	O
execution	O
.	O
</s>
<s>
The	O
random	B-Architecture
access	I-Architecture
memory	I-Architecture
,	O
called	O
RAM	B-Architecture
,	O
provides	O
storage	O
for	O
an	O
executing	O
program	O
’s	O
data	O
and	O
provides	O
services	O
and	O
storage	O
areas	O
for	O
the	O
computer	O
’s	O
memory-mapped	B-Architecture
I/O	I-Architecture
mechanism	O
.	O
</s>
<s>
The	O
address	O
buses	O
(	O
15-bit	O
)	O
,	O
as	O
well	O
as	O
the	O
data	B-General_Concept
and	I-General_Concept
instruction	I-General_Concept
busses	I-General_Concept
(	O
16-bit	B-Device
)	O
for	O
the	O
ROM	B-Device
and	O
RAM	B-Architecture
units	O
are	O
completely	O
independent	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
Hack	O
design	O
follows	O
the	O
Harvard	B-Architecture
architecture	I-Architecture
model	O
with	O
respect	O
to	O
bus	O
communication	O
between	O
the	O
memory	B-General_Concept
units	O
and	O
the	O
CPU	O
.	O
</s>
<s>
All	O
memory	B-General_Concept
is	O
word	B-General_Concept
addressable	I-General_Concept
only	O
.	O
</s>
<s>
The	O
Hack	B-Device
computer	I-Device
’s	O
ROM	B-Device
module	O
is	O
presented	O
as	O
a	O
linear	O
array	O
of	O
individually	O
addressable	B-General_Concept
,	O
sequential	O
,	O
16-bit	B-Device
memory	B-General_Concept
registers	I-General_Concept
.	O
</s>
<s>
Since	O
the	O
memory	B-General_Concept
elements	O
are	O
sequential	O
devices	O
,	O
a	O
system	O
clock	O
signal	O
is	O
supplied	O
by	O
the	O
simulation	O
application	O
and	O
the	O
computer	B-Application
emulator	I-Application
application	O
.	O
</s>
<s>
The	O
ROM	B-General_Concept
address	I-General_Concept
bus	O
is	O
15	O
bits	O
wide	O
,	O
so	O
a	O
total	O
of	O
32,768	O
individual	O
words	O
are	O
available	O
for	O
program	O
instructions	O
.	O
</s>
<s>
The	O
address	O
of	O
the	O
currently	O
active	O
word	O
is	O
supplied	O
by	O
a	O
program	B-General_Concept
counter	I-General_Concept
register	O
within	O
the	O
CPU	O
(	O
see	O
below	O
)	O
.	O
</s>
<s>
The	O
value	O
in	O
the	O
ROM	B-Device
memory	I-Device
register	O
identified	O
by	O
the	O
address	O
placed	O
on	O
the	O
instruction	O
address	O
bus	O
in	O
a	O
particular	O
clock	O
cycle	O
is	O
available	O
as	O
the	O
"	O
current	O
"	O
instruction	O
at	O
the	O
beginning	O
of	O
the	O
next	O
cycle	O
.	O
</s>
<s>
There	O
is	O
no	O
instruction	B-General_Concept
register	I-General_Concept
;	O
instructions	O
are	O
decoded	O
in	O
each	O
cycle	O
from	O
the	O
currently	O
active	O
ROM	B-Device
register	O
.	O
</s>
<s>
Although	O
the	O
RAM	B-Architecture
module	O
is	O
also	O
viewed	O
as	O
a	O
continuous	O
linear	O
array	O
of	O
individually	O
addressable	B-General_Concept
sequential	O
,	O
read-write	O
,	O
16-bit	B-Device
memory	B-General_Concept
registers	I-General_Concept
,	O
it	O
is	O
functionally	O
organized	O
by	O
address	O
range	O
into	O
three	O
segments	O
.	O
</s>
<s>
Addresses	O
0	O
(	O
0x000	O
)	O
through	O
16383	O
(	O
0x3FFF	O
)	O
contain	O
conventional	O
16-bit	B-Device
,	O
read-write	O
registers	B-General_Concept
and	O
are	O
meant	O
for	O
use	O
as	O
general-purpose	O
program	O
data	O
storage	O
.	O
</s>
<s>
The	O
registers	B-General_Concept
at	O
addresses	O
16384	O
(	O
0x4000	O
)	O
through	O
24575	O
(	O
0x5FFF	O
)	O
are	O
essentially	O
like	O
data	O
RAM	B-Architecture
,	O
but	O
they	O
are	O
also	O
designated	O
for	O
use	O
by	O
a	O
built-in	O
screen	O
I/O	O
subsystem	O
.	O
</s>
<s>
If	O
a	O
program	O
does	O
not	O
require	O
screen	O
output	O
,	O
registers	B-General_Concept
in	O
this	O
range	O
may	O
be	O
used	O
for	O
general	O
program	O
data	O
.	O
</s>
<s>
The	O
final	O
address	O
in	O
the	O
RAM	B-Architecture
address	O
space	O
,	O
at	O
24576	O
(	O
0x6000	O
)	O
,	O
contains	O
a	O
single	O
one	O
word	O
register	O
whose	O
current	O
value	O
is	O
controlled	O
by	O
the	O
output	O
of	O
a	O
keyboard	O
attached	O
to	O
the	O
computer	O
hosting	O
the	O
Hack	O
emulator	B-Application
program	O
.	O
</s>
<s>
This	O
keyboard	O
memory	B-General_Concept
map	O
register	O
is	O
read-only	O
(	O
see	O
I/O	O
)	O
.	O
</s>
<s>
Data	O
memory	B-General_Concept
addresses	O
in	O
the	O
range	O
24577	O
(	O
0x6001	O
)	O
through	O
32767	O
(	O
0x7FFF	O
)	O
are	O
invalid	O
.	O
</s>
<s>
State	O
transitions	O
of	O
the	O
selected	O
RAM	B-Architecture
memory	I-Architecture
register	O
is	O
also	O
coordinated	O
by	O
the	O
system	O
clock	O
signal	O
.	O
</s>
<s>
As	O
illustrated	O
in	O
the	O
accompanying	O
diagram	O
,	O
the	O
Hack	B-Device
computer	I-Device
central	B-General_Concept
processing	I-General_Concept
unit	I-General_Concept
(	O
CPU	O
)	O
is	O
an	O
integrated	O
logic	O
unit	O
with	O
internal	O
structure	O
.	O
</s>
<s>
The	O
most	O
complex	O
element	O
of	O
the	O
CPU	O
is	O
the	O
arithmetic	B-General_Concept
logic	I-General_Concept
unit	I-General_Concept
(	O
ALU	O
)	O
which	O
provides	O
the	O
computational	O
functionality	O
of	O
the	O
computer	O
.	O
</s>
<s>
The	O
ALU	O
is	O
a	O
combinational	O
logic	O
device	O
having	O
two	O
16-bit	B-Device
input	O
operands	O
and	O
a	O
single	O
16-bit	B-Device
output	O
.	O
</s>
<s>
The	O
CPU	O
also	O
contains	O
two	O
16-bit	B-Device
registers	B-General_Concept
,	O
labeled	O
D	O
and	O
A	O
.	O
</s>
<s>
While	O
the	O
A	O
(	O
Address	O
)	O
register	O
may	O
also	O
provide	O
its	O
current	O
value	O
as	O
the	O
y	O
operand	O
to	O
the	O
ALU	O
when	O
so	O
directed	O
by	O
an	O
instruction	O
,	O
its	O
value	O
may	O
also	O
be	O
used	O
for	O
data	O
memory	B-General_Concept
addressing	I-General_Concept
and	O
as	O
a	O
target	O
address	O
in	O
instruction	O
memory	B-General_Concept
for	O
branching	O
instructions	O
.	O
</s>
<s>
To	O
facilitate	O
this	O
function	O
,	O
the	O
A	O
register	O
is	O
directly	O
associated	O
with	O
a	O
"	O
pseudo-register	O
"	O
designated	O
as	O
M	O
which	O
is	O
not	O
explicitly	O
implemented	O
in	O
hardware	B-Architecture
.	O
</s>
<s>
This	O
M	O
register	O
therefore	O
represents	O
the	O
value	O
contained	O
in	O
RAM	B-Architecture
having	O
the	O
address	O
of	O
the	O
current	O
value	O
contained	O
in	O
the	O
A	O
register	O
.	O
</s>
<s>
The	O
final	O
important	O
element	O
in	O
the	O
CPU	O
is	O
the	O
program	B-General_Concept
counter	I-General_Concept
(	O
PC	O
)	O
register	O
.	O
</s>
<s>
The	O
PC	O
is	O
a	O
16-bit	B-Device
binary	O
counter	O
whose	O
low	O
15	O
bits	O
specify	O
the	O
address	O
in	O
instruction	O
memory	B-General_Concept
of	O
the	O
next	B-General_Concept
instruction	I-General_Concept
for	O
execution	O
.	O
</s>
<s>
Unlike	O
many	O
actual	O
CPU	O
designs	O
,	O
there	O
is	O
no	O
program	O
accessible	O
hardware	B-Architecture
mechanism	O
provided	O
to	O
implement	O
CPU	O
external	O
or	O
internal	O
interrupts	O
or	O
support	O
for	O
function	O
calls	O
.	O
</s>
<s>
The	O
Hack	B-Device
computer	I-Device
employs	O
a	O
memory-mapped	O
approach	O
to	O
I/O	O
.	O
</s>
<s>
Bitmapped	O
,	O
black	O
and	O
white	O
output	O
to	O
a	O
virtual	O
256	O
x	O
512	O
screen	O
is	O
effected	O
by	O
writing	O
a	O
bitmap	O
of	O
the	O
desired	O
output	O
to	O
data	O
memory	B-General_Concept
locations	I-General_Concept
16384	O
(	O
0x4000	O
)	O
through	O
24575	O
(	O
0x5FFF	O
)	O
.	O
</s>
<s>
The	O
data	O
words	O
in	O
this	O
address	O
range	O
are	O
viewed	O
as	O
a	O
linear	O
array	O
of	O
bits	O
with	O
each	O
bit	O
value	O
representing	O
the	O
black/white	O
state	O
of	O
a	O
single	O
pixel	O
on	O
the	O
computer	B-Application
emulator	I-Application
's	O
virtual	O
screen	O
.	O
</s>
<s>
The	O
least	O
significant	O
bit	O
of	O
the	O
word	O
in	O
the	O
first	O
memory	B-General_Concept
address	I-General_Concept
of	O
the	O
screen	O
RAM	B-Architecture
segment	O
sets	O
the	O
pixel	O
in	O
the	O
upper	O
left	O
corner	O
of	O
the	O
screen	O
to	O
white	O
if	O
it	O
is	O
0	O
and	O
black	O
if	O
it	O
is	O
1	O
.	O
</s>
<s>
After	O
the	O
first	O
512-pixel	O
row	O
is	O
described	O
by	O
the	O
first	O
32	O
words	O
of	O
screen	O
memory	B-General_Concept
,	O
the	O
mapping	O
is	O
continued	O
in	O
the	O
same	O
fashion	O
for	O
the	O
second	O
row	O
with	O
the	O
next	O
32	O
words	O
.	O
</s>
<s>
Logic	O
external	O
to	O
the	O
computer	O
reads	O
the	O
screen	O
RAM	B-Architecture
memory	I-Architecture
map	O
segment	O
and	O
updates	O
the	O
virtual	O
screen	O
.	O
</s>
<s>
If	O
a	O
keyboard	O
is	O
attached	O
to	O
the	O
computer	O
hosting	O
the	O
CPU	O
emulator	B-Application
program	O
,	O
the	O
emulator	B-Application
puts	O
a	O
16-bit	B-Device
bit	O
scan	O
code	O
corresponding	O
to	O
a	O
key	O
depressed	O
during	O
program	O
execution	O
into	O
the	O
keyboard	O
register	O
at	O
RAM	B-Architecture
address	O
24576	O
(	O
0x6000	O
)	O
.	O
</s>
<s>
The	O
emulator	B-Application
provides	O
a	O
toggle	O
button	O
to	O
enable/disable	O
the	O
keyboard	O
.	O
</s>
<s>
Step-wise	O
operation	O
of	O
the	O
CPU	O
and	O
memory	B-General_Concept
units	O
is	O
controlled	O
by	O
a	O
clock	O
that	O
is	O
built-in	O
to	O
both	O
the	O
hardware	B-Architecture
simulator	O
and	O
the	O
computer	B-Application
emulator	I-Application
programs	O
.	O
</s>
<s>
At	O
the	O
beginning	O
of	O
a	O
clock	O
cycle	O
the	O
instruction	O
at	O
the	O
ROM	B-General_Concept
address	I-General_Concept
emitted	O
by	O
the	O
current	O
value	O
of	O
the	O
program	B-General_Concept
counter	I-General_Concept
is	O
decoded	O
.	O
</s>
<s>
Finally	O
,	O
the	O
program	B-General_Concept
counter	I-General_Concept
is	O
updated	O
to	O
the	O
value	O
of	O
the	O
next	O
required	O
program	O
instruction	O
.	O
</s>
<s>
If	O
no	O
branching	O
was	O
specified	O
by	O
the	O
current	B-General_Concept
instruction	I-General_Concept
,	O
the	O
PC	O
value	O
is	O
simply	O
incremented	O
.	O
</s>
<s>
If	O
branching	O
was	O
specified	O
,	O
the	O
PC	O
is	O
loaded	O
(	O
from	O
the	O
A	O
register	O
)	O
with	O
the	O
address	O
of	O
the	O
next	B-General_Concept
instruction	I-General_Concept
to	O
be	O
executed	O
.	O
</s>
<s>
Because	O
of	O
its	O
Harvard	O
memory	B-General_Concept
architecture	O
model	O
,	O
the	O
Hack	B-Device
computer	I-Device
is	O
designed	O
to	O
execute	O
the	O
current	B-General_Concept
instruction	I-General_Concept
and	O
“	O
fetch	O
”	O
the	O
next	B-General_Concept
instruction	I-General_Concept
in	O
a	O
single	O
,	O
two-part	O
clock	O
cycle	O
.	O
</s>
<s>
The	O
speed	O
of	O
the	O
clock	O
may	O
be	O
varied	O
by	O
a	O
control	O
element	O
in	O
both	O
the	O
hardware	B-Architecture
simulator	O
and	O
the	O
CPU	O
emulator	B-Application
.	O
</s>
<s>
Execution	O
of	O
a	O
program	O
loaded	O
in	O
ROM	B-Device
is	O
controlled	O
by	O
the	O
CPU	O
's	O
reset	O
bit	O
.	O
</s>
<s>
Setting	O
the	O
reset	O
bit	O
value	O
back	O
to	O
zero	O
then	O
begins	O
execution	O
of	O
the	O
current	O
program	O
at	O
the	O
first	O
instruction	O
;	O
however	O
,	O
RAM	B-Architecture
contains	O
the	O
values	O
from	O
any	O
previous	O
activity	O
on	O
reset	O
.	O
</s>
<s>
There	O
is	O
no	O
hardware	B-Architecture
or	O
machine	B-Language
language	I-Language
support	O
for	O
interrupts	O
of	O
any	O
kind	O
.	O
</s>
<s>
Values	O
stored	O
in	O
ROM	B-Device
memory	I-Device
must	O
represent	O
valid	O
Hack	O
machine	B-Language
language	I-Language
instructions	O
as	O
described	O
in	O
the	O
Instruction	B-General_Concept
Set	I-General_Concept
Architecture	I-General_Concept
section	O
.	O
</s>
<s>
Any	O
16-bit	B-Device
value	O
may	O
be	O
stored	O
in	O
RAM	B-Architecture
.	O
</s>
<s>
The	O
data	O
type	O
of	O
value	O
stored	O
in	O
RAM	B-Architecture
is	O
inferred	O
by	O
its	O
location	O
and/or	O
its	O
use	O
within	O
a	O
program	O
.	O
</s>
<s>
The	O
primary	O
hardware	B-Architecture
supported	O
data	O
type	O
is	O
the	O
16-bit	B-Device
signed	O
integer	O
,	O
which	O
is	O
represented	O
in	O
2	O
’s	O
complement	O
format	O
.	O
</s>
<s>
The	O
lower	O
15	O
bits	O
of	O
a	O
value	O
in	O
RAM	B-Architecture
may	O
also	O
represent	O
an	O
address	O
in	O
ROM	B-Device
or	O
RAM	B-Architecture
in	O
the	O
sense	O
of	O
a	O
pointer	O
.	O
</s>
<s>
For	O
values	O
in	O
the	O
RAM	B-Architecture
memory	I-Architecture
registers	B-General_Concept
assigned	O
for	O
screen	O
I/O	O
,	O
the	O
value	O
will	O
be	O
interpreted	O
as	O
a	O
16	O
pixel	B-General_Concept
map	I-General_Concept
of	O
the	O
256	O
row	O
x	O
512	O
column	O
virtual	O
screen	O
by	O
the	O
computer	O
's	O
independent	O
I/O	O
subsystem	O
if	O
the	O
screen	O
is	O
"	O
turned	O
on	O
"	O
.	O
</s>
<s>
The	O
code	O
value	O
in	O
keyboard	O
memory	B-General_Concept
may	O
be	O
read	O
programmatically	O
and	O
interpreted	O
for	O
use	O
by	O
a	O
program	O
.	O
</s>
<s>
There	O
is	O
no	O
hardware	B-Architecture
support	O
for	O
floating-point	B-Algorithm
types	O
.	O
</s>
<s>
The	O
Hack	B-Device
computer	I-Device
's	O
instruction	B-General_Concept
set	I-General_Concept
architecture	I-General_Concept
(	O
ISA	O
)	O
and	O
derived	O
machine	B-Language
language	I-Language
is	O
sparse	O
compared	O
to	O
many	O
other	O
architectures	O
.	O
</s>
<s>
Although	O
the	O
6	O
bits	O
used	O
to	O
specify	O
a	O
computation	O
by	O
the	O
ALU	O
could	O
allow	O
for	O
64	O
distinct	O
instructions	O
,	O
only	O
18	O
are	O
officially	O
implemented	O
in	O
the	O
Hack	B-Device
computer	I-Device
's	O
ISA	O
.	O
</s>
<s>
Since	O
the	O
Hack	B-Device
computer	I-Device
hardware	B-Architecture
has	O
direct	O
support	O
for	O
neither	O
integer	O
multiplication	O
(	O
and	O
division	O
)	O
or	O
function	O
calls	O
,	O
there	O
are	O
no	O
corresponding	O
machine	B-Language
language	I-Language
instructions	O
in	O
the	O
ISA	O
for	O
these	O
operations	O
.	O
</s>
<s>
Hack	O
machine	B-Language
language	I-Language
has	O
only	O
two	O
types	O
of	O
instructions	O
,	O
each	O
encoded	O
in	O
16	O
binary	O
digits	O
.	O
</s>
<s>
As	O
a	O
side-effect	O
,	O
the	O
RAM	B-Architecture
register	O
having	O
the	O
address	O
represented	O
by	O
that	O
value	O
is	O
enabled	O
for	O
subsequent	O
read/write	O
action	O
in	O
the	O
next	O
clock	O
cycle	O
.	O
</s>
<s>
The	O
Hack	B-Device
computer	I-Device
encoding	O
scheme	O
of	O
the	O
C-instruction	O
is	O
shown	O
in	O
the	O
following	O
tables	O
.	O
</s>
<s>
The	O
Hack	B-Device
computer	I-Device
has	O
a	O
text-based	O
assembly	O
language	O
to	O
create	O
programs	O
for	O
the	O
hardware	B-Architecture
platform	O
that	O
implements	O
the	O
Hack	B-Device
computer	I-Device
ISA	O
.	O
</s>
<s>
Each	O
of	O
these	O
line	O
types	O
has	O
a	O
specific	O
syntax	O
and	O
may	O
contain	O
predefined	O
or	O
user	O
defined	O
symbols	O
or	O
numeric	B-Algorithm
constants	O
.	O
</s>
<s>
All	O
text	O
following	O
the	O
comment	O
identifier	O
character	O
sequence	O
to	O
end	O
of	O
line	O
is	O
completely	O
ignored	O
by	O
the	O
assembler	O
;	O
consequently	O
,	O
they	O
produce	O
no	O
machine	B-Language
code	I-Language
.	O
</s>
<s>
A	O
symbol	O
may	O
be	O
any	O
sequence	O
of	O
alphabetic	O
(	O
upper	O
and	O
lower	O
case	O
)	O
or	O
numeric	B-Algorithm
digits	O
.	O
</s>
<s>
These	O
symbols	O
are	O
meant	O
to	O
represent	O
general	O
purpose	O
registers	B-General_Concept
and	O
the	O
symbols	O
values	O
therefore	O
represent	O
data	O
memory	B-General_Concept
addresses	O
0	O
through	O
15	O
.	O
</s>
<s>
Predefined	O
symbols	O
SCREEN	O
and	O
KBD	O
are	O
also	O
specified	O
to	O
represent	O
the	O
data	O
memory	B-General_Concept
address	I-General_Concept
of	O
the	O
start	O
of	O
memory-mapped	O
virtual	O
screen	O
output	O
(	O
16384	O
)	O
and	O
keyboard	O
input	O
(	O
24756	O
)	O
.	O
</s>
<s>
User	O
defined	O
symbols	O
may	O
be	O
created	O
in	O
an	O
assembly	O
language	O
program	O
to	O
represent	O
variables	O
;	O
that	O
is	O
,	O
a	O
named	O
RAM	B-Architecture
register	O
.	O
</s>
<s>
The	O
symbol	O
is	O
bound	O
at	O
assembly	O
to	O
a	O
RAM	B-Architecture
address	O
chosen	O
by	O
the	O
assembler	O
.	O
</s>
<s>
They	O
are	O
defined	O
on	O
a	O
separate	O
source	O
program	O
line	O
and	O
are	O
bound	O
by	O
the	O
assembler	O
to	O
the	O
address	O
of	O
the	O
instruction	O
memory	B-General_Concept
location	I-General_Concept
of	O
the	O
next	B-General_Concept
instruction	I-General_Concept
in	O
the	O
source	O
code	O
.	O
</s>
<s>
The	O
A-instruction	O
has	O
the	O
syntax	O
“	O
@xxxx	O
”	O
,	O
where	O
xxxx	O
is	O
either	O
a	O
numeric	B-Algorithm
decimal	O
constant	O
in	O
the	O
range	O
0	O
through	O
32767	O
,	O
a	O
label	O
,	O
or	O
a	O
variable	O
(	O
predefined	O
or	O
user	O
defined	O
)	O
.	O
</s>
<s>
When	O
executed	O
,	O
this	O
instruction	B-General_Concept
sets	I-General_Concept
the	O
value	O
of	O
the	O
A	O
register	O
and	O
the	O
M	O
pseudo-register	O
to	O
a	O
15-bit	O
binary	O
value	O
represented	O
by	O
“	O
xxxx	O
”	O
.	O
</s>
<s>
The	O
15-bit	O
value	O
is	O
left-zero	O
extended	O
to	O
16-bits	B-Device
in	O
the	O
A	O
register	O
.	O
</s>
<s>
It	O
is	O
the	O
only	O
means	O
to	O
introduce	O
a	O
(	O
non-negative	O
)	O
numeric	B-Algorithm
value	O
into	O
the	O
computer	O
under	O
program	O
control	O
;	O
that	O
is	O
,	O
it	O
may	O
be	O
used	O
to	O
create	O
program	O
constants	O
.	O
</s>
<s>
Secondly	O
,	O
it	O
is	O
used	O
to	O
specify	O
a	O
RAM	B-Architecture
memory	I-Architecture
location	O
using	O
the	O
M	O
pseudo-register	O
mechanism	O
for	O
subsequent	O
reference	O
by	O
a	O
C-instruction	O
.	O
</s>
<s>
C-instructions	O
direct	O
the	O
ALU	O
computation	O
engine	O
and	O
program	O
flow	O
control	O
capabilities	O
of	O
the	O
Hack	B-Device
computer	I-Device
.	O
</s>
<s>
The	O
jump	O
field	O
may	O
be	O
used	O
to	O
specify	O
the	O
address	O
in	O
ROM	B-Device
of	O
the	O
next	B-General_Concept
instruction	I-General_Concept
to	O
be	O
executed	O
.	O
</s>
<s>
If	O
the	O
field	O
is	O
omitted	O
,	O
along	O
with	O
the	O
“	O
;	O
”	O
delimiter	O
,	O
execution	O
continues	O
with	O
the	O
instruction	O
immediately	O
following	O
the	O
current	B-General_Concept
instruction	I-General_Concept
.	O
</s>
<s>
The	O
branch	O
address	O
target	O
,	O
in	O
ROM	B-Device
,	O
is	O
provided	O
by	O
the	O
current	O
value	O
of	O
the	O
A	O
register	O
if	O
the	O
specified	O
branch	O
condition	O
is	O
satisfied	O
.	O
</s>
<s>
If	O
the	O
branch	O
condition	O
fails	O
,	O
execution	O
continues	O
with	O
the	O
next	B-General_Concept
instruction	I-General_Concept
in	O
ROM	B-Device
.	O
</s>
<s>
Freely	O
available	O
software	O
supporting	O
the	O
Hack	B-Device
computer	I-Device
includes	O
a	O
command	O
line	O
assembler	O
application	O
.	O
</s>
<s>
The	O
assembler	O
reads	O
Hack	O
assembly	O
language	O
source	O
tiles	O
( *	O
.asm	O
)	O
and	O
produces	O
Hack	O
machine	B-Language
language	I-Language
output	O
files	O
( *	O
.hack	O
)	O
.	O
</s>
<s>
The	O
machine	B-Language
language	I-Language
file	O
is	O
also	O
a	O
text	O
file	O
.	O
</s>
<s>
Each	O
line	O
of	O
this	O
file	O
is	O
a	O
16-character	O
string	O
of	O
binary	O
digits	O
that	O
represents	O
the	O
encoding	O
of	O
each	O
corresponding	O
executable	O
line	O
of	O
the	O
source	O
text	O
file	O
according	O
to	O
the	O
specification	O
described	O
in	O
the	O
section	O
"	O
Instruction	B-General_Concept
set	I-General_Concept
architecture	I-General_Concept
(	O
ISA	O
)	O
and	O
machine	B-Language
language	I-Language
"	O
.	O
</s>
<s>
The	O
file	O
created	O
may	O
be	O
loaded	O
into	O
the	O
Hack	B-Device
computer	I-Device
emulator	B-Application
by	O
a	O
facility	O
provided	O
by	O
the	O
emulator	B-Application
user	O
interface	O
.	O
</s>
<s>
This	O
program	O
illustrates	O
all	O
of	O
the	O
features	O
of	O
the	O
“	O
documented	O
”	O
assembly	O
language	O
capabilities	O
of	O
Hack	B-Device
Computer	I-Device
except	O
memory-mapped	B-Architecture
I/O	I-Architecture
.	O
</s>
<s>
The	O
Hack	O
machine	B-Language
code	I-Language
produced	O
by	O
the	O
assembler	O
is	O
shown	O
in	O
the	O
last	O
column	O
with	O
the	O
assigned	O
ROM	B-General_Concept
address	I-General_Concept
in	O
the	O
preceding	O
column	O
.	O
</s>
<s>
Note	O
that	O
full-line	O
comments	O
,	O
blank	O
lines	O
,	O
and	O
label	O
definition	O
statements	O
generate	O
no	O
machine	B-Language
language	I-Language
code	O
.	O
</s>
<s>
The	O
assembler	O
output	O
,	O
shown	O
in	O
the	O
last	O
column	O
,	O
is	O
a	O
text	O
string	O
of	O
16	O
binary	O
characters	O
,	O
not	O
16-bit	B-Device
binary	O
integer	O
representation	O
.	O
</s>
<s>
The	O
A-instruction	O
specifies	O
a	O
constant	O
or	O
memory	B-General_Concept
address	I-General_Concept
that	O
is	O
used	O
in	O
the	O
subsequent	O
C-instruction	O
.	O
</s>
<s>
Since	O
line	O
4	O
(	O
@cnt	O
)	O
contains	O
the	O
first	O
appearance	O
of	O
the	O
user-defined	O
variable	O
"	O
cnt	O
"	O
,	O
this	O
statement	O
binds	O
the	O
symbol	O
to	O
the	O
next	O
unused	O
RAM	B-Architecture
address	O
.	O
</s>
<s>
Also	O
,	O
the	O
M	O
pseudo-register	O
also	O
now	O
references	O
this	O
address	O
,	O
and	O
RAM[16]	O
is	O
made	O
the	O
active	O
RAM	B-Architecture
memory	I-Architecture
location	O
.	O
</s>
<s>
Here	O
the	O
instruction	O
loads	O
the	O
bound	O
label	O
value	O
,	O
representing	O
an	O
address	O
in	O
ROM	B-Device
memory	I-Device
,	O
into	O
the	O
A	O
register	O
and	O
M	O
pseudo-register	O
.	O
</s>
<s>
The	O
subsequent	O
unconditional	O
branch	O
instruction	O
in	O
line	O
22	O
(	O
0	O
;	O
JMP	O
)	O
loads	O
the	O
M	O
register	O
value	O
into	O
the	O
CPU	O
's	O
program	B-General_Concept
counter	I-General_Concept
register	O
to	O
effect	O
control	O
transfer	O
to	O
the	O
beginning	O
of	O
the	O
loop	O
.	O
</s>
<s>
The	O
Hack	B-Device
computer	I-Device
provides	O
no	O
machine	B-Language
language	I-Language
instruction	O
to	O
halt	O
program	O
execution	O
.	O
</s>
<s>
The	O
final	O
two	O
lines	O
of	O
the	O
program	O
(	O
@END	O
and	O
0	O
;	O
JMP	O
)	O
create	O
an	O
infinite	O
loop	O
condition	O
which	O
Hack	O
assembly	O
programs	O
conventionally	O
use	O
to	O
terminate	O
programs	O
designed	O
to	O
run	O
in	O
the	O
CPU	O
emulator	B-Application
.	O
</s>
