Book 1 · Chapter 4
Processor Fundamentals
B1·4This 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.
For the whole chapter
- Topic pageProcessor Fundamentals
B1·4·T - QuizProcessor Fundamentals
B1·4·Q1 - LabAssembler & CPU simulator
B1·4·X1 - LabFetch–execute in RTN + interrupts
B1·4·X2 - LabBit masks & shifts
B1·4·X3
§4.1 CPU architecture · The fetch–execute cycle in register transfer notation; interrupts
Short code B1·4·1
- FlashcardsFlashcards §4.1: CPU architecture, registers & FDE with RTN
B1·4·F1 - Past-paper questionsPast-paper questions §4.1 (cpu-architecture)
- Past-paper questionsPast-paper questions §4.1 (the-fetch-execute-cycle-in-register-transfer-notation-interr)
§4.2 Assembly language
Short code B1·4·2
- FlashcardsFlashcards §4.2: Assembly language & addressing modes
B1·4·F2 - Past-paper questionsPast-paper questions §4.2 (assembly-language)
B1·4·2
§4.3 Bit manipulation
Short code B1·4·3
- FlashcardsFlashcards §4.3: Bit manipulation — shifts & masks
B1·4·F3 - Past-paper questionsPast-paper questions §4.3 (bit-manipulation)
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")Output
8 wires: 256 addresses 16 wires: 65536 addresses 20 wires: 1048576 addresses 32 wires: 4294967296 addresses
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
| Step | PC | MAR | MDR | CIR | ACC |
|---|---|---|---|---|---|
| start | 100 | NULL | NULL | NULL | 0 |
| MAR <- [PC] | 100 | 100 | NULL | NULL | 0 |
| PC <- [PC] + 1 | 101 | 100 | NULL | NULL | 0 |
| MDR <- [[MAR]] | 101 | 100 | LDD 150 | NULL | 0 |
| CIR <- [MDR] | 101 | 100 | LDD 150 | LDD 150 | 0 |
| MAR <- address in [CIR] | 101 | 150 | LDD 150 | LDD 150 | 0 |
| MDR <- [[MAR]] | 101 | 150 | 42 | LDD 150 | 0 |
| ACC <- [MDR] | 101 | 150 | 42 | LDD 150 | 42 |
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***. It uses three labels, LOOP, DONE and COUNT, that the assembler must turn into addresses.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 0Output
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 | |
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 42Output
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 | |
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 2Output
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 | |
Writing programs: input, output and loops
Short code B1·4·23
100 IN
101 SUB #32
102 OUT
103 ENDg and the program outputs G (103 − 32 = 71, the code of G).100 IN
101 CMP #35
102 JPE 105
103 OUT
104 JMP 100
105 ENDH, I, # and the program outputs HI, then stops at the #.IN
SUB #32
OUT
ENDq (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 | |
IN
INC ACC
OUT
END5 (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 | |
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))Output
start 1011 0101 logical L2 1101 0100 logical R2 0010 1101 arithmetic R2 1110 1101 cyclic L2 1101 0110 cyclic R2 0110 1101
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)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
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')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
100 LDD 400
101 OR B00100000
102 AND B10111111
103 XOR B00010000
104 STO 400
105 END
400 B11011000Output
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 | |
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 B01000000Output
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 | |
100 LDD 400
101 OR B00100000
102 STO 400
103 LDD 400
104 AND B10111111
105 STO 400
106 END
400 B01000001Output
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 | |
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.


