UP | HOME

Mental Model
COP-3223H

Table of Contents

What is computation?

Desktop Calculator

desktop_calculator.png

An intuitive starting point is a desktop calculator. You can perform one arithmetic operation at a time.

One operation at a time

Online Calculator

Example usage:

  • 1 + 1
  • 2 * 7
  • 9 / 4

What about multiple operations?

Add two multiplications: 2*2 + 3*3

Listing operations

2
*
2
+
3
*
3
=

Adding memory

Online Calculator with Memory

We can improve ease of use by adding memory.

  • store the number, e.g., 2 M+
  • then recall twice and multiply, MR * MR
  • store 2
  • recall
2
store
clear
recall
*
recall
=

Use a calculator with a memory slot (m+, mr)

Use diagram with buttons that can be copied to show how they can be stored in memory slots.

Visually, if we could store the "buttons" (symbols for the buttons) in a list (more memory slots for instructions too), then make a machine that takes the symbols and uses them to press the buttons and automatically retrieve the next instruction, i.e., automate the user of the desktop calculator.

Multiple memory slots

Let's name them to keep track of them.

Imagine multiple memory slots (draw list of boxes)

Store multiple numbers, e.g., let's compute x^2 + y:

5
store x
3
store y

recall x
*
recall x
+
recall y

Leap to modern computers

Imagine we can also store the operations themselves in memory slots too.

Now we have a program.

Draw instructions inside the memory boxes.

Number the instruction memory boxes.

How do we run the program?

Track the next instruction to the run, called the program counter (PC), in memory.

recall pc
+
1
=
store pc

fetch-decode-execute cycle (greatly simplified)

Have a little machine that steps through the program and

  1. Fetches it from memory
  2. Execute the instruction
  3. Increment the program counter

Keep track of the current instruction, let's give it its own memory location, we'll label that location pc for program counter

Then this machine gets the instruction and inputs it to the calculator.

It reads each one then adds one to the program counter.

Now we have a stored program computer.

It can automatically fetch the next instruction.

After running a command we run something like this:

recall pc
+
1
=
store pc

This would need a separate working memory than the program to avoid conflicting with the program's working memory.

Repetition

The program counter is just a memory location, what happens if we store to it?

We can arbitrarily jump to any part of the program

Aside: Repetition in Music Notation

da_capo_al_coda.jpg

D.C (da capo, from the head) means repeat from the beginning. Al Coda (to the tail) is a branch to the end section.

Example: Exponent

What's a program to compute \(3^5\)?

recall 3
*
recall 3
*
recall 3
*
recall 3
*
recall 3
=

Branching

What if we could use repetition?

Write instructions that change the program counter:

Just store the line number of the program in memory

1
store pc

Let's make a new instruction to do this:

goto 1

Example: "Exponent" with Branch

1: recall 3
2: *
3: goto 1

What does this program do?

If we always repeat, we'll never end.

How can we repeat sometimes but not always?

Conditional Branch

Only run goto when condition is met

1: recall x 2: if x=0 goto 1

What will this program do?

Example: Exponent with Branch

1: 5
2: store e
3: 1
4: store result
----------------
5: recall result
6: *
7: 3
8: =
9: store result
10: recall e
11: -
12: 1
13: =
14: store e
15: if e>0 goto 5
-----------------------
16: recall result

Input and output

On the calculator

  • Input: the buttons
  • Output: the display

How we represent it

  • input a means read a number into memory location a
  • output display the most recent number on the display

Example of squaring a given number:

input a
recall a
*
recall a
=
output

Recreated a stored program computer

von_neumann.jpeg

Von Neumann architecture

Desktop calculator with more memory and a program counter that automatically runs the next instruction.

Language

Digits 1 2 3 4 5 6 7 8 9 0
Operations + - * /
Memory store recall
Branching goto ifgoto
I/O input output

Author: Paul Gazzillo

Created: 2026-01-14 Wed 11:02

Validate