K11 Computer
K11 Computer
What is a computer?
Definitions?
Wikipedia
A computer is a machine that can be instructed to carry out sequences of
arithmetic or logical operations automatically via computer programming.
Processor
ALU
(Arithmetic Control unit
Logic Unit)
Data bus
Input and
Memory
output
devices
8 Bit vectors contain no explicit information about the type they are
representing. Their interpretation must be derivable from the context
they are used in.
Memory
1 Bit = Information: 0 or 1 Input/output devices
1 Byte = 8 Bit = Words like Display, printer, ...
00101001 Keyboard, mouse, ...
Numbered cells sized 1 Byte Also: network, internet, ...
Different techniques: hard
drives, CD, DVD, ... Control unit
Program counter: current
Data bus instruction
Transfers data between Responsible for loading
components instructions and data into
Electric current either exists the ALU...
or it does not
Electric circuits
Electric circuits
A computer knows two possible states: there either exists electric
current or there does not.
A computer can control the flow of electric charge by opening or
closing switches.
1
Emitter Switch Collector
Electric circuits
Electric circuits
A computer knows two possible states: there either exists electric
current or there does not.
A computer can control the flow of electric charge by opening or
closing switches.
1
Emitter Switch Collector
Transistors
How can a computer operate a switch?
Solution: transistors are electric switches
Electric switches
Element with 2 inlets and 1 outlet:
If electric current is registered at the control inlet c, then the signal of the
other inlet is transmitted to the outlet. Otherwise, not.
Emitter Mass
1 0
1 T
Emitter Collector
Transistor
Transistors
How can a computer operate a switch?
Solution: transistors are electric switches
Electric switches
Element with 2 inlets and 1 outlet:
If electric current is registered at the control inlet c, then the signal of the
other inlet is transmitted to the outlet. Otherwise, not.
Emitter Mass
1 0
1 T
Emitter Collector
Transistor
Input A Input B
A B
AND c c
1 T T
Output
Input A Input B
A B
AND c c
1 T T
Output
Input A Input B
A B
AND c c
1 T T
Output
Input A Input B
A B
AND c c
1 T T
Output
Logic gates: OR
Input A Input B
A B
c
OR
T
1 c
T Output
Logic gates: OR
Input A Input B
A B
c
OR
T
1 c
T Output
Logic gates: OR
Input A Input B
A B
c
OR
T
1 c
T Output
Logic gates: OR
Input A Input B
A B
c
OR
T
1 c
T Output
Half adder
Adding 2 bits
A B C S
We want to add 2 bits
0 0 0 0
Note: Carry (C) is an AND 0 1 0 1
S is also known as XOR (Symbol ⊕) 1 0 0 1
Realization of ⊕ → exercises 1 1 1 0
A AND C
B XOR S
Full adder
Adding 3 bits
A B Cold Cnew S
Usually, we have to add 3 bits:
number 1, number 2 and carry. 0 0 0 0 0
0 1 0 0 1
Carry and sum are still logical
1 0 0 0 1
operations.
1 1 0 1 0
S = A ⊕ B ⊕ Cold 0 0 1 0 1
Cnew = (A ∧ B) ∨ (A ∧ Cold ) ∨ (B ∧ 0 1 1 1 0
Cold ) 1 0 1 1 0
Circuit diagram → exercises 1 1 1 1 1
Strategy
A and B are bit vectors, i.e. A = (an , ..., a1 ) with ai ∈ {0, 1}.
We are seeking bit vector S = A + B of length n + 1.
Leading zeros are allowed in all numbers.
We are now performing addition by hand:
Machine language
Program instructions are binary strings (what else?).
The control unit decodes the instructions so they can be executed by
the respective system.
Common instructions are:
1 Move the contents of a memory cell
2 Instruct the ALU to perform some operation
3 Alter the program counter (jump instruction)
Assembly language
Assembly language is basically the same thing as machine language –
except that binary instructions are replaced by more comprehensible
instructions like ADD and GOTO.
Components
Memory: consisting of 32 cells with 8 bits each, numbered from 0-31.
Each cell contains either an instruction or a positive integer between 0
and 28 − 1 in binary representation.
Program counter: Which of the 32 cells contains the current
instruction? Starts at 0 and is incremented by 1 after each instruction.
ALU: can add / subtract two binary numbers.
Accumulator (Acc): provides 16 bit of memory for arithmetic results.
The result of an operation is always stored in the acc.
Instructions
Our machine is capable of a few instructions of 8 bit length: The first 3
bits encode the instruction while the last 5 bits specify the memory cell.
List of instructions
Code Abbr. Outcome
001 LOAD Load the cell’s content into the acc.
010 SAVE Save the acc’s content into the cell.
100 ADD Add the cell’s content onto the acc.
101 SUB Subtract the cell’s content from the acc.
110 GOTO Set program counter to given constant.
111 IFGT Content of acc = 0: Set counter to constant
000 EXIT Terminate the execution of the program.
Examples
10010001 = ADD 10001 = Add the content of cell 17 onto the
accumulator.
11100010 = IFGT 00010 = If the accumulator’s content is 0, then set
the program counter to 2.
Calculate 5 * 3: Iteration 1
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
0 – – - 2 SAVE 11
1 0 LOAD 11 0 3 LOAD 10
2 1 ADD 9 5 4 SUB 12
3 2 SAVE 11 5 5 SAVE 10
4 3 LOAD 10 3 6 IFGT 8
5 4 SUB 12 2 7 GOTO 0
6 5 SAVE 10 2 8 EXIT
7 6 IFGT 8 2 9 5
8 7 GOTO 0 2 10 3
11 0
12 1
Calculate 5 * 3: Iteration 1
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
0 – – - 2 SAVE 11
1 0 LOAD 11 0 3 LOAD 10
2 1 ADD 9 5 4 SUB 12
3 2 SAVE 11 5 5 SAVE 10
4 3 LOAD 10 3 6 IFGT 8
5 4 SUB 12 2 7 GOTO 0
6 5 SAVE 10 2 8 EXIT
7 6 IFGT 8 2 9 5
8 7 GOTO 0 2 10 3
11 0
12 1
Calculate 5 * 3: Iteration 1
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
0 – – - 2 SAVE 11
1 0 LOAD 11 0 3 LOAD 10
2 1 ADD 9 5 4 SUB 12
3 2 SAVE 11 5 5 SAVE 10
4 3 LOAD 10 3 6 IFGT 8
5 4 SUB 12 2 7 GOTO 0
6 5 SAVE 10 2 8 EXIT
7 6 IFGT 8 2 9 5
8 7 GOTO 0 2 10 3
11 0
12 1
Calculate 5 * 3: Iteration 1
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
0 – – - 2 SAVE 11
1 0 LOAD 11 0 3 LOAD 10
2 1 ADD 9 5 4 SUB 12
3 2 SAVE 11 5 5 SAVE 10
4 3 LOAD 10 3 6 IFGT 8
5 4 SUB 12 2 7 GOTO 0
6 5 SAVE 10 2 8 EXIT
7 6 IFGT 8 2 9 5
8 7 GOTO 0 2 10 3
11 5
12 1
Calculate 5 * 3: Iteration 1
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
0 – – - 2 SAVE 11
1 0 LOAD 11 0 3 LOAD 10
2 1 ADD 9 5 4 SUB 12
3 2 SAVE 11 5 5 SAVE 10
4 3 LOAD 10 3 6 IFGT 8
5 4 SUB 12 2 7 GOTO 0
6 5 SAVE 10 2 8 EXIT
7 6 IFGT 8 2 9 5
8 7 GOTO 0 2 10 3
11 5
12 1
Calculate 5 * 3: Iteration 1
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
0 – – - 2 SAVE 11
1 0 LOAD 11 0 3 LOAD 10
2 1 ADD 9 5 4 SUB 12
3 2 SAVE 11 5 5 SAVE 10
4 3 LOAD 10 3 6 IFGT 8
5 4 SUB 12 2 7 GOTO 0
6 5 SAVE 10 2 8 EXIT
7 6 IFGT 8 2 9 5
8 7 GOTO 0 2 10 3
11 5
12 1
Calculate 5 * 3: Iteration 1
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
0 – – - 2 SAVE 11
1 0 LOAD 11 0 3 LOAD 10
2 1 ADD 9 5 4 SUB 12
3 2 SAVE 11 5 5 SAVE 10
4 3 LOAD 10 3 6 IFGT 8
5 4 SUB 12 2 7 GOTO 0
6 5 SAVE 10 2 8 EXIT
7 6 IFGT 8 2 9 5
8 7 GOTO 0 2 10 2
11 5
12 1
Calculate 5 * 3: Iteration 1
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
0 – – - 2 SAVE 11
1 0 LOAD 11 0 3 LOAD 10
2 1 ADD 9 5 4 SUB 12
3 2 SAVE 11 5 5 SAVE 10
4 3 LOAD 10 3 6 IFGT 8
5 4 SUB 12 2 7 GOTO 0
6 5 SAVE 10 2 8 EXIT
7 6 IFGT 8 2 9 5
8 7 GOTO 0 2 10 2
11 5
12 1
Calculate 5 * 3: Iteration 1
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
0 – – - 2 SAVE 11
1 0 LOAD 11 0 3 LOAD 10
2 1 ADD 9 5 4 SUB 12
3 2 SAVE 11 5 5 SAVE 10
4 3 LOAD 10 3 6 IFGT 8
5 4 SUB 12 2 7 GOTO 0
6 5 SAVE 10 2 8 EXIT
7 6 IFGT 8 2 9 5
8 7 GOTO 0 2 10 2
11 5
12 1
Calculate 5 * 3: Iteration 2
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
9 0 LOAD 11 5 2 SAVE 11
10 1 ADD 9 10 3 LOAD 10
11 2 SAVE 11 10 4 SUB 12
12 3 LOAD 10 2 5 SAVE 10
13 4 SUB 12 1 6 IFGT 8
14 5 SAVE 10 1 7 GOTO 0
15 6 IFGT 8 1 8 EXIT
16 7 GOTO 0 1 9 5
10 2
11 5
12 1
Calculate 5 * 3: Iteration 2
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
9 0 LOAD 11 5 2 SAVE 11
10 1 ADD 9 10 3 LOAD 10
11 2 SAVE 11 10 4 SUB 12
12 3 LOAD 10 2 5 SAVE 10
13 4 SUB 12 1 6 IFGT 8
14 5 SAVE 10 1 7 GOTO 0
15 6 IFGT 8 1 8 EXIT
16 7 GOTO 0 1 9 5
10 2
11 5
12 1
Calculate 5 * 3: Iteration 2
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
9 0 LOAD 11 5 2 SAVE 11
10 1 ADD 9 10 3 LOAD 10
11 2 SAVE 11 10 4 SUB 12
12 3 LOAD 10 2 5 SAVE 10
13 4 SUB 12 1 6 IFGT 8
14 5 SAVE 10 1 7 GOTO 0
15 6 IFGT 8 1 8 EXIT
16 7 GOTO 0 1 9 5
10 2
11 10
12 1
Calculate 5 * 3: Iteration 2
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
9 0 LOAD 11 5 2 SAVE 11
10 1 ADD 9 10 3 LOAD 10
11 2 SAVE 11 10 4 SUB 12
12 3 LOAD 10 2 5 SAVE 10
13 4 SUB 12 1 6 IFGT 8
14 5 SAVE 10 1 7 GOTO 0
15 6 IFGT 8 1 8 EXIT
16 7 GOTO 0 1 9 5
10 2
11 10
12 1
Calculate 5 * 3: Iteration 2
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
9 0 LOAD 11 5 2 SAVE 11
10 1 ADD 9 10 3 LOAD 10
11 2 SAVE 11 10 4 SUB 12
12 3 LOAD 10 2 5 SAVE 10
13 4 SUB 12 1 6 IFGT 8
14 5 SAVE 10 1 7 GOTO 0
15 6 IFGT 8 1 8 EXIT
16 7 GOTO 0 1 9 5
10 2
11 10
12 1
Calculate 5 * 3: Iteration 2
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
9 0 LOAD 11 5 2 SAVE 11
10 1 ADD 9 10 3 LOAD 10
11 2 SAVE 11 10 4 SUB 12
12 3 LOAD 10 2 5 SAVE 10
13 4 SUB 12 1 6 IFGT 8
14 5 SAVE 10 1 7 GOTO 0
15 6 IFGT 8 1 8 EXIT
16 7 GOTO 0 1 9 5
10 1
11 10
12 1
Calculate 5 * 3: Iteration 2
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
9 0 LOAD 11 5 2 SAVE 11
10 1 ADD 9 10 3 LOAD 10
11 2 SAVE 11 10 4 SUB 12
12 3 LOAD 10 2 5 SAVE 10
13 4 SUB 12 1 6 IFGT 8
14 5 SAVE 10 1 7 GOTO 0
15 6 IFGT 8 1 8 EXIT
16 7 GOTO 0 1 9 5
10 1
11 10
12 1
Calculate 5 * 3: Iteration 2
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
9 0 LOAD 11 5 2 SAVE 11
10 1 ADD 9 10 3 LOAD 10
11 2 SAVE 11 10 4 SUB 12
12 3 LOAD 10 2 5 SAVE 10
13 4 SUB 12 1 6 IFGT 8
14 5 SAVE 10 1 7 GOTO 0
15 6 IFGT 8 1 8 EXIT
16 7 GOTO 0 1 9 5
10 1
11 10
12 1
Calculate 5 * 3: Iteration 3
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
17 0 LOAD 11 10 2 SAVE 11
18 1 ADD 9 15 3 LOAD 10
19 2 SAVE 11 15 4 SUB 12
20 3 LOAD 10 1 5 SAVE 10
21 4 SUB 12 0 6 IFGT 8
22 5 SAVE 10 0 7 GOTO 0
23 6 IFGT 8 0 8 EXIT
24 8 EXIT 0 0 9 5
10 1
11 10
12 1
Calculate 5 * 3: Iteration 3
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
17 0 LOAD 11 10 2 SAVE 11
18 1 ADD 9 15 3 LOAD 10
19 2 SAVE 11 15 4 SUB 12
20 3 LOAD 10 1 5 SAVE 10
21 4 SUB 12 0 6 IFGT 8
22 5 SAVE 10 0 7 GOTO 0
23 6 IFGT 8 0 8 EXIT
24 8 EXIT 0 0 9 5
10 1
11 10
12 1
Calculate 5 * 3: Iteration 3
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
17 0 LOAD 11 10 2 SAVE 11
18 1 ADD 9 15 3 LOAD 10
19 2 SAVE 11 15 4 SUB 12
20 3 LOAD 10 1 5 SAVE 10
21 4 SUB 12 0 6 IFGT 8
22 5 SAVE 10 0 7 GOTO 0
23 6 IFGT 8 0 8 EXIT
24 8 EXIT 0 0 9 5
10 1
11 15
12 1
Calculate 5 * 3: Iteration 3
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
17 0 LOAD 11 10 2 SAVE 11
18 1 ADD 9 15 3 LOAD 10
19 2 SAVE 11 15 4 SUB 12
20 3 LOAD 10 1 5 SAVE 10
21 4 SUB 12 0 6 IFGT 8
22 5 SAVE 10 0 7 GOTO 0
23 6 IFGT 8 0 8 EXIT
24 8 EXIT 0 0 9 5
10 1
11 15
12 1
Calculate 5 * 3: Iteration 3
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
17 0 LOAD 11 10 2 SAVE 11
18 1 ADD 9 15 3 LOAD 10
19 2 SAVE 11 15 4 SUB 12
20 3 LOAD 10 1 5 SAVE 10
21 4 SUB 12 0 6 IFGT 8
22 5 SAVE 10 0 7 GOTO 0
23 6 IFGT 8 0 8 EXIT
24 8 EXIT 0 0 9 5
10 1
11 15
12 1
Calculate 5 * 3: Iteration 3
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
17 0 LOAD 11 10 2 SAVE 11
18 1 ADD 9 15 3 LOAD 10
19 2 SAVE 11 15 4 SUB 12
20 3 LOAD 10 1 5 SAVE 10
21 4 SUB 12 0 6 IFGT 8
22 5 SAVE 10 0 7 GOTO 0
23 6 IFGT 8 0 8 EXIT
24 8 EXIT 0 0 9 5
10 0
11 15
12 1
Calculate 5 * 3: Iteration 3
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
17 0 LOAD 11 10 2 SAVE 11
18 1 ADD 9 15 3 LOAD 10
19 2 SAVE 11 15 4 SUB 12
20 3 LOAD 10 1 5 SAVE 10
21 4 SUB 12 0 6 IFGT 8
22 5 SAVE 10 0 7 GOTO 0
23 6 IFGT 8 0 8 EXIT
24 8 EXIT 0 0 9 5
10 0
11 15
12 1
Calculate 5 * 3: Iteration 3
Cell Content
0 LOAD 11
Iteration Counter Instruction Acc 1 ADD 9
17 0 LOAD 11 10 2 SAVE 11
18 1 ADD 9 15 3 LOAD 10
19 2 SAVE 11 15 4 SUB 12
20 3 LOAD 10 1 5 SAVE 10
21 4 SUB 12 0 6 IFGT 8
22 5 SAVE 10 0 7 GOTO 0
23 6 IFGT 8 0 8 EXIT
24 8 EXIT 0 0 9 5
10 0
11 15
12 1
res = 0
for (i in 1:3)
res = res + 5
Programming paradigms
Imperative programming I
Imperative programming II
Procedural programming
Until now: A program is a long sequence of instructions.
Now: Divide it into subroutines that can call upon each other.
Every subroutine possesses well-defined input and output parameters.
In theory, it can be realized through jump instructions.
Structural programming
Refrains from using jump instructions as they are incomprehensible.
Instead, looping and branching statements are used.
Object-oriented programming
Object
Example
Object: My cat Midna
Data: Position, size, weight, color, ...
Methods: Running, eating, napping, ...
Objects can communicate with each other, i.e. exchange data and call
functions.
Daniel Horn & Sheila Görz FPR Summer Semester 2022 35 / 41
Programming paradigms
Class
Example
Midna is an instance of the class cat. Her sister Phai is too.
Both have a weight, but each has their own specific weight.
Example: Multiplication
1 a×0=0
2 a × b = a + (a × (b − 1))
Functional programming
The entire program is a (nested) function call.
Functions are just like all other data objects. For example, they can be
the input or output of another function.
Interpreter
A program is running in the background, the so-called interpreter.
Program code is executed directly at runtime (one instruction at a
time).
Cons
Increased effort: Slow, since some code
Requires new chunks need to be
compilation after each interpreted multiple
modification times (loops)
Makes error search The interpreter itself
more complicated needs resources