Skip to content
Book 1: Theory Fundamentals

Book 1 · Chapter 4

Processor Fundamentals

§4.1§4.2§4.3Banker · ≈ 14.7 m · ↘B1·4

This chapter is in the ebook.

Read it in full on cswithzak.com. Every question has its mark scheme and every program is ready to run. The free practice for each section is below, with the short code the book prints beside it.

Open in the ebook

For the whole chapter

§4.1 CPU architecture · The fetch–execute cycle in register transfer notation; interrupts

Short code B1·4·1

§4.2 Assembly language

Short code B1·4·2

§4.3 Bit manipulation

Short code B1·4·3

The stored program: the Von Neumann model

Short code B1·4·10

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Registers

Short code B1·4·11

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

The processor's other parts: ALU, CU, clock and IAS

Short code B1·4·12

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

The three buses

Short code B1·4·13

for n in (8, 16, 20, 32):
    print(n, "wires:", 2 ** n, "addresses")
How many addresses an address bus of each width can carry: 2 to the power of the number of wires.

Output

8 wires: 256 addresses
16 wires: 65536 addresses
20 wires: 1048576 addresses
32 wires: 4294967296 addresses
Run and checked before printing

What makes a computer faster

Short code B1·4·14

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Ports: USB, HDMI and VGA

Short code B1·4·15

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

The fetch-execute cycle in register transfer notation

Short code B1·4·16

Output · 8 rows

StepPCMARMDRCIRACC
start100NULLNULLNULL0
MAR <- [PC]100100NULLNULL0
PC <- [PC] + 1101100NULLNULL0
MDR <- [[MAR]]101100LDD 150NULL0
CIR <- [MDR]101100LDD 150LDD 1500
MAR <- address in [CIR]101150LDD 150LDD 1500
MDR <- [[MAR]]10115042LDD 1500
ACC <- [MDR]10115042LDD 15042
Run and checked before printing

Interrupts

Short code B1·4·17

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Assembly language and machine code

Short code B1·4·18

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

The two-pass assembler

Short code B1·4·19

100        LDD COUNT
101 LOOP:  CMP #0
102        JPE DONE
103        LDM #42
104        OUT
105        LDD COUNT
106        DEC ACC
107        STO COUNT
108        JMP LOOP
109 DONE:  END
110 COUNT: 3
A program with labels. COUNT holds 3, so it outputs ***. It uses three labels, LOOP, DONE and COUNT, that the assembler must turn into addresses.
Run and checked before printing

The instruction set and its groups

Short code B1·4·20

100 LDD 300
101 ADD 301
102 STO 302
103 ADD #48
104 OUT
105 END
300 3
301 4
302 0
The first program in spread 20, run (online; the trace table is printed).

Output

OUTPUT: 7
LDD 300 | ACC=3 | IX=0 |  |
ADD 301 | ACC=7 | IX=0 |  |
STO 302 | ACC=7 | IX=0 | 302=7 |
ADD #48 | ACC=55 | IX=0 |  |
OUT | ACC=55 | IX=0 |  | 7
END | ACC=55 | IX=0 |  |
Run and checked before printing

Addressing modes

Short code B1·4·21

100 LDM #201
101 LDD 201
102 LDI 200
103 LDR #2
104 LDX 200
105 END
200 203
201 7
202 9
203 42
Four addressing modes on one memory (spread 21), run (online).

Output

OUTPUT:
LDM #201 | ACC=201 | IX=0 |  |
LDD 201 | ACC=7 | IX=0 |  |
LDI 200 | ACC=42 | IX=0 |  |
LDR #2 | ACC=42 | IX=2 |  |
LDX 200 | ACC=9 | IX=2 |  |
END | ACC=9 | IX=2 |  |
Run and checked before printing

Tracing a program

Short code B1·4·22

100 LDM #0      ; total ← 0
101 STO 320
102 LDR #0      ; IX ← 0
103 LDX 300     ; ACC ← [300 + IX]
104 ADD 320     ; + total
105 STO 320
106 INC IX      ; next reading
107 LDD 321     ; readings left
108 DEC ACC
109 STO 321
110 CMP #0      ; none left?
111 JPN 103     ; no: repeat
112 END
300 18
301 21
320 0
321 2
Adding two readings with indexed addressing (spread 22), run (online).

Output

OUTPUT:
LDM #0 | ACC=0 | IX=0 |  |
STO 320 | ACC=0 | IX=0 | 320=0 |
LDR #0 | ACC=0 | IX=0 |  |
LDX 300 | ACC=18 | IX=0 |  |
ADD 320 | ACC=18 | IX=0 |  |
STO 320 | ACC=18 | IX=0 | 320=18 |
INC IX | ACC=18 | IX=1 |  |
LDD 321 | ACC=2 | IX=1 |  |
DEC ACC | ACC=1 | IX=1 |  |
STO 321 | ACC=1 | IX=1 | 321=1 |
CMP #0 | ACC=1 | IX=1 |  |
JPN 103 | ACC=1 | IX=1 |  |
LDX 300 | ACC=21 | IX=1 |  |
ADD 320 | ACC=39 | IX=1 |  |
STO 320 | ACC=39 | IX=1 | 320=39 |
INC IX | ACC=39 | IX=2 |  |
LDD 321 | ACC=1 | IX=2 |  |
DEC ACC | ACC=0 | IX=2 |  |
STO 321 | ACC=0 | IX=2 | 321=0 |
CMP #0 | ACC=0 | IX=2 |  |
JPN 103 | ACC=0 | IX=2 |  |
END | ACC=0 | IX=2 |  |
Run and checked before printing

Writing programs: input, output and loops

Short code B1·4·23

100 IN
101 SUB #32
102 OUT
103 END
Type g and the program outputs G (103 − 32 = 71, the code of G).
Run and checked before printing
100 IN
101 CMP #35
102 JPE 105
103 OUT
104 JMP 100
105 END
Type H, I, # and the program outputs HI, then stops at the #.
Run and checked before printing
IN
SUB #32
OUT
END
The Mark Ladder's answer in spread 23, run with the input q (online; not printed).

Output

OUTPUT: Q
IN | ACC=113 | IX=0 |  |
SUB #32 | ACC=81 | IX=0 |  |
OUT | ACC=81 | IX=0 |  | Q
END | ACC=81 | IX=0 |  |
Run and checked before printing
IN
INC ACC
OUT
END
The faded twin's answer in spread 23, run with the input 5 (online; not printed).

Output

OUTPUT: 6
IN | ACC=53 | IX=0 |  |
INC ACC | ACC=54 | IX=0 |  |
OUT | ACC=54 | IX=0 |  | 6
END | ACC=54 | IX=0 |  |
Run and checked before printing

Binary shifts

Short code B1·4·24

def b(v):
    s = format(v & 0xFF, '08b')
    return s[:4] + ' ' + s[4:]
x = 0b10110101
s = x - 256          # its two's complement value
print('start        ', b(x))
print('logical L2   ', b(x << 2))
print('logical R2   ', b(x >> 2))
print('arithmetic R2', b(s >> 2))
print('cyclic L2    ', b(x << 2 | x >> 6))
print('cyclic R2    ', b(x >> 2 | x << 6))
The five shifts of the diagram, worked out by Python on 1011 0101.

Output

start         1011 0101
logical L2    1101 0100
logical R2    0010 1101
arithmetic R2 1110 1101
cyclic L2     1101 0110
cyclic R2     0110 1101
Run and checked before printing
def b(v):
    s = format(v & 0xFF, '08b')
    return s[:4] + ' ' + s[4:]
print('6 left 1:', b(6 << 1), '=', 6 << 1)
print('6 right 1:', b(6 >> 1), '=', 6 >> 1)
x = 0b11101000
s = x - 256
print('start:', b(x), '=', s)
print('arithmetic right 1:', b(s >> 1), '=', s >> 1)
print('logical right 1:', b(x >> 1), '=', x >> 1)
The shift examples in the text of spread 24, checked (online; not printed).

Output

6 left 1: 0000 1100 = 12
6 right 1: 0000 0011 = 3
start: 1110 1000 = -24
arithmetic right 1: 1111 0100 = -12
logical right 1: 0111 0100 = 116
Run and checked before printing

Masks: AND, OR and XOR

Short code B1·4·25

def b(v):
    s = format(v & 0xFF, '08b')
    return s[:4] + ' ' + s[4:]
ctrl = 0b11011000
print('CTRL now     ', b(ctrl))
ctrl = ctrl | 0b00100000
print('OR  0010 0000', b(ctrl), 'pump on')
ctrl = ctrl & 0b10111111
print('AND 1011 1111', b(ctrl), 'heater off')
ctrl = ctrl ^ 0b00010000
print('XOR 0001 0000', b(ctrl), 'lamp flipped')
fan = ctrl & 0b10000000
print('AND 1000 0000', b(fan), 'fan test: not 0')
The greenhouse masks, step by step. Each line starts from the result of the line before.

Output

CTRL now      1101 1000
OR  0010 0000 1111 1000 pump on
AND 1011 1111 1011 1000 heater off
XOR 0001 0000 1010 1000 lamp flipped
AND 1000 0000 1000 0000 fan test: not 0
Run and checked before printing
100 LDD 400
101 OR B00100000
102 AND B10111111
103 XOR B00010000
104 STO 400
105 END
400 B11011000
Pump on, heater off, lamp toggled, stored back (spread 25), run (online).

Output

OUTPUT:
LDD 400 | ACC=216 | IX=0 |  |
OR B00100000 | ACC=248 | IX=0 |  |
AND B10111111 | ACC=184 | IX=0 |  |
XOR B00010000 | ACC=168 | IX=0 |  |
STO 400 | ACC=168 | IX=0 | 400=168 |
END | ACC=168 | IX=0 |  |
Run and checked before printing

Testing and setting bits to control a device

Short code B1·4·26

100 LDD 401
101 AND B01000000
102 CMP #0
103 JPE 107
104 LDD 400
105 OR B00100000
106 STO 400
107 END
400 B10001000
401 B01000000
Test the soil bit, then set the pump bit (spread 26), run (online).

Output

OUTPUT:
LDD 401 | ACC=64 | IX=0 |  |
AND B01000000 | ACC=64 | IX=0 |  |
CMP #0 | ACC=64 | IX=0 |  |
JPE 107 | ACC=64 | IX=0 |  |
LDD 400 | ACC=136 | IX=0 |  |
OR B00100000 | ACC=168 | IX=0 |  |
STO 400 | ACC=168 | IX=0 | 400=168 |
END | ACC=168 | IX=0 |  |
Run and checked before printing
100 LDD 400
101 OR B00100000
102 STO 400
103 LDD 400
104 AND B10111111
105 STO 400
106 END
400 B01000001
The Mark Ladder (pump on) and its faded twin (heater off) in spread 26, run on CTRL = 0100 0001 (online; not printed).

Output

OUTPUT:
LDD 400 | ACC=65 | IX=0 |  |
OR B00100000 | ACC=97 | IX=0 |  |
STO 400 | ACC=97 | IX=0 | 400=97 |
LDD 400 | ACC=97 | IX=0 |  |
AND B10111111 | ACC=33 | IX=0 |  |
STO 400 | ACC=33 | IX=0 | 400=33 |
END | ACC=33 | IX=0 |  |
Run and checked before printing

Workbook 1: Processor Fundamentals

Short code W1·4 · Theory Fundamentals Workbook

The write-in workbook for this chapter has drills, exam-style practice, trace tables, fix-the-mistake and mark-it-yourself pages. Its full mark schemes and an interactive version arrive here with the chapter.

Ask Z about Processor Fundamentals
Buy ZAK's books — WhatsApp the books desk: Buy the booksPrint or ebook