-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
186 lines (161 loc) · 7.76 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
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/prism">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>The Little Man Stack Machine</title>
</head>
<body>
<main>
<h1 class="massivetext">🙋 The Little Man Stack Machine</h1>
<nav>
<p class="tool-bar">
<a href="index.html">Intro</a>
<a href="assembly.html">Assembly & Execution</a>
<a href="functions.html">Functions</a>
<a href="firth.html">Firth</a>
<a href="emulator.html">Emulator</a>
<a href="https://github.com/bigskysoftware/littlemanstackmachine.org">Github</a>
</p>
</nav>
<h1>Introduction</h1>
<p>
The Little Man Stack Machine (LMSM) is a backwards-compatible extension of the venerable and excellent
<a href="https://en.wikipedia.org/wiki/Little_man_computer">Little Man Computer</a> (LMC) teaching computer model.
It is designed to be a teaching aid, to show people how various aspects of computing work in an easy and approachable
manner:
</p>
<ul>
<li>The operations of a basic Von Neumann style computer</li>
<li>How assembly works</li>
<li>How assembly can be converted to machine code</li>
<li>How function calls can be implemented using basic hardware</li>
<li>How recursive function calls work</li>
<li>How stack-based languages work</li>
<li>How a high-level programming language can be compiled to assembly</li>
</ul>
<p>
The LMSM is simple enough that someone interested should be able to build an LMSM emulator,
an assembler and a compiler from a high-level language to assembly in a short amount of time, such as
within a single quarter or semester.
</p>
<p>
Like the LMC, the LMSM models a simple <a href="https://en.wikipedia.org/wiki/Von_Neumann_architecture">Von
Neumann</a> computing machine and the execution cycle is identical to the LMC. In order to better support
more computational topics that the LMC did, the LMSM adds the following functionality:
</p>
<ul>
<li>
The memory space of the LMSM is doubled from 100 slots to 200 slots.
</li>
<li>
Two new registers are available:
<ul>
<li>
The <code>stack_pointer</code> register that points to the top of the <em>value stack</em>.
</li>
<li>
The <code>return_address_pointer</code> register that points to the top of the <em>return address
stack</em>.
</li>
</ul>
</li>
<li>
A new <code>LDI</code> <a href="https://en.wikichip.org/wiki/immediate_value">"immediate"</a> instruction
is added for loading immediate values directly into the accumulator.
</li>
<li>
A new set of stack-related instructions are available for working with the two stacks available on the
LMSM.
</li>
<li>
Two "virtual" assembly instructions are available to make assembly coding on the LMSM a bit more pleasant.
</li>
</ul>
<h2>System Diagram</h2>
<p>
Below is a system diagram of the LMSM:
</p>
<img src="img/lmsm_architecture.png">
<h3>Overall System Description</h3>
<p>
Like the LMC, the LMSM works only in terms of integers between the values -999 and 999. These integers can
be interpreted as either data or as instructions, depending on the context they are used in. The LMSM
follows a simple <a href="https://en.wikipedia.org/wiki/Von_Neumann_architecture">Von Neumann</a> style
<a href="https://en.wikipedia.org/wiki/Instruction_cycle">Instruction Cycle</a>: it loads an instruction from
memory, bumps the program counter, executes the instruction and then repeats.
</p>
<p>
More detail on the execution cycle can be found on the <a href="assembly.html">Assembly & Execution</a> page.
</p>
<h3>Registers</h3>
<p>
The LMSM has a total of five registers (two more than the LMC). The registers are as follows:
</p>
<ul>
<li>
The <code>program_counter</code> register - a register that points to memory location of the next instruction to execute.
This register starts with the value 0.
</li>
<li>
The <code>accumulator</code> register - a register that is used to "accumulate" values by, for example, an instruction
adding a value in memory to the value already in the accumulator. This register starts at value 0.
</li>
<li>
The <code>current_instruction</code> register - a register that holds the currently executing instruction.
This register starts at value 0.
</li>
<li>
The <code>stack_pointer</code> register - a register that points to the memory location at the "top" of the
value stack. This pointer starts at value 200 (meaning that the value stack is empty) and is <em>decremented</em> as the
value stack grows.
</li>
<li>
The <code>return_address_pointer</code> register - a register that points to the memory location at the "top" of the
return address stack. This pointer starts at value 99 (meaning that the return address stack is empty) and it
is <em>incremented</em> as the return address stack grows.
</li>
</ul>
<h3>Memory</h3>
<p>
The LMSM has a total of 200 memory slots, double that of the LCM. The memory is split into two sections: "lower"
and "upper" segments. Traditional LMC instructions such as <code>ADD</code> operate on the lower memory segment,
while the new stack instructions of the LMSM operate on the upper section of memory.
</p>
<h2>The Stacks & Function Calls</h2>
<p>
A major goal of the LMSM is to provide hardware infrastructure for implementing
<a href="https://en.wikipedia.org/wiki/Function_(computer_programming)">function calls</a> so that students
can see how the function call abstraction can be implemented on top of raw registers and memory. This is a crucial
concept in computer science, allowing us to build far more sophisticated pieces of software than raw assembly
does.
</p>
<p>
The function invocation mechanism in the LMSM is very simple when compared with real-world computers, but it
demonstrates the core concepts of using stacks to hold function-call related values and recursive function calls.
</p>
<p>
See <a href="functions.html">Functions</a> for a detailed look at function calls on the LMSM.
</p>
<h2>Firth</h2>
<p>
While the LMC is great for introducing students to assembly and how low level computation works, it
does not provide enough infrastructure for easily creating a high-level programming language.
</p>
<p>
By offering a slightly more sophisticated CPU model the LMSM makes it possible to create a simple
<a href="https://en.wikipedia.org/wiki/Forth_(programming_language)">Forth</a>-inspired language in a relatively
short amount of time. This "high-level" language can then be compiled down to LSMS assembly code fairly easily.
</p>
<p>
The language includes functions, loops, conditionals and so, er, forth: the basics of higher-level programming.
</p>
<p>
See <a href="firth.html">Firth</a> for more information on this language.
</p>
</main>
<footer>
</footer>
</body>
</html>