Hexidecimal, CPU, and the Toy Computer (Week 4) Flashcards

1
Q

Definition : Byte

A

A byte is a sequence of 8 bits

It encodes 256 distinct values (0 to 255)

Each distinct value represents a unique sequence of 8 bits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Definition : Hexidecimal Numbers

A

Hexadecimal numbers use 16 symbols per digit: numerals 0-9 and letters A-F (base-16).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why use hexadecimal?

A

Because binary numbers rapidly grow too large to be read effectively by humans, e.g. 2021(decimal) equals 111 1110 01012(binary)

To represent binary numbers in a compact format, hexadecimal numbers are particularly suitable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How many bits is one Hexidecimal digit?

A

1 hexadecimal digit represents exactly 4 binary digits (no more, no less)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Convert Hexidecimal to Decimal :
A

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Convert Hexidecimal to Decimal :
B

A

11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Convert Hexidecimal to Decimal :
C

A

12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Convert Hexidecimal to Decimal :
D

A

13

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Convert Hexidecimal to Decimal :
E

A

14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Convert Hexidecimal to Decimal :
F

A

15

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Convert Hexidecimal Digits to Bits :
1

A

0001

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Convert Hexidecimal Digits to Bits :
7

A

0111

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Convert Hexidecimal Digits to Bits :
3B

A

00111011

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Convert Hexidecimal to Decimal :
4B

A

75

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Convert Hexidecimal to Decimal :
A7

A

167

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Convert Hexidecimal to Decimal :
FF

A

255

17
Q

Convert Hexidecimal to Decimal :
EC

A

236

18
Q

How is color encoded?

A

In Hexidecimal eg.
ffffff
000000
00ff00

19
Q

How many bits are 7 bytes?

A

56

20
Q

What does a CPU do?

A

The CPU controls all other parts of a computer (by sending out signals on the bus)

Examples of what CPU controls: RAM, storage devices and peripherals (e.g. mouse, printer, etc.)

21
Q

What can a CPU do?

A

CPUs can execute only up to a few dozen (sometimes up to a few hundred) of quite basic instructions

  1. Arithmetic: add, subtract, multiply, divide, etc. different types of numbers
  2. Move data around (fetch instructions and data from RAM, store results back in RAM, move date from and to Input/Output devices)
  3. Instructions to control the flow of execution, i.e. instructions that decide what to do next based on previous computation results
22
Q

What is the CPU instruction cycle?

A

CPUs perform billions of operations per second (e.g. 3 billion per second if your CPU runs at 3 GHz clock speed)

An instruction cycle features the following (simplified and) ever repeating steps:
1. Clock cycle 1: Fetch next instruction from RAM
2. Clock cycle 2: Decode what to do
3. Clock cycle 3: Execute it

23
Q

What is a Toy Computer?

A

The toy computer is a tool to simulate a highly simplified Computer/CPU in order to demonstrate how it works in principle.

It can run simple computer programs made of very basic instructions (similar to instructions of real CPUs).

The “Toy” uses one accumulator => storage area inside the CPU with capacity of one data item

24
Q

Process of the Toy Computer?

A

Programs are stored in RAM
* Each line represents one memory location
* Each location stores an instruction or data item

The CPU executes one instruction after another starting at the top.

25
Q

What do the following commands do?

	GET
	PRINT
	STOP
A

Answer :

	GET	get a number from keyboard into accumulator

	PRINT	print contents of accumulator

	STOP	stop running
26
Q

What do the following commands do?

	LOAD Val
	STORE M
	ADD Val
	SUB Val
M	Num
A

Answer :

	LOAD Val	load accumulator with Val (Val unchanged)

	STORE M	store contents of accumulator into memory location called M (accumulator unchanged)

	ADD Val	add Val to contents of accumulator (Val unchanged)

	SUB Val	subtract Val from contents of accumulator (Val unchanged)

M	Num	before program runs, set this memory location (called M) to numeric value Num
27
Q

What do the following commands do?

	GOTO L
	IFPOS L
	IFZERO L
A

Answer :

	GOTO L	go to instruction labeled L

	IFPOS L	go to instruction labeled L if accumulator is >= zero

	IFZERO L	go to instruction labeled L if accumulator is zero
28
Q

Determine the Output of the following Toy Computer code :

1	GET (3)
2	PRINT
3	END
A

Output :

error: invalid instruction 'end' at line 3
29
Q

Determine the Output of the following Toy Computer code :

1	GET (3)
2	PRINT
3	STOP
A

Output :

3
30
Q

Determine the Output of the following Toy Computer code :

1 Top	GET (7, 9, 2, 0)
2	PRINT
3	GOTO Top
4	IFZERO End
5 End	STOP
A

Output :

error: infinite loop
31
Q

Determine the Output of the following Toy Computer code :

1 Top	GET (3, 7, 0)
2	IFZERO Bot
3	ADD sum
4	STORE sum
5	GOTO Top
6 Bot	LOAD sum
7	PRINT
8	STOP
9 sum
A

Output :

10
32
Q

Determine the Output of the following Toy Computer code :

1 Top	GET (3, 7, 0)
2	IFZERO Bot
3	ADD sum
4	STORE sum
5	GOTO Top
6 Bot	LOAD sum
7	PRINT
8	STOP
A

Output :

line 3 error: there is no instruction labeled sum
line 4 error: there is no instruction labeled sum
line 3 error: there is no instruction labeled sum
line 4 error: there is no instruction labeled sum
line 6 error: there is no instruction labeled sum
33
Q

Determine the Output of the following Toy Computer code :

1 Top	GET (0, 3, 7)
2	IFZERO Bot
3	ADD sum
4	STORE sum
5	GOTO Top
6 Bot	LOAD sum
7	PRINT
8	STOP
9 sum
A

Output :

0
34
Q

What value(s) of GET would cause an error?

1	GET
2 Loop	Sub 1
3	PRINT
4	IFZERO Exit
5	GOTO Loop
6 Exit	STOP
A

If 0 or less (0,-1,-2, -3, …) is the input, the program will loop infinitely.

error: infinite loop
35
Q

What value(s) of GET would cause an error?

1	GET
2 Loop	PRINT
3	Sub 1
4	IFPOS Loop
5	STOP
A

None. All numbers will eventually be subtracted below zero, and even letters will be considered not positive.

36
Q

Determine the Output of the following Toy Computer code :

1	GET (8)
2	STORE length
3	GET (4)
4	GOTO Top
5 End	LOAD perimeter	
6	ADD length
7	STORE perimeter
8	LOAD width
9 Top	SUB 1
10	STORE width
11	IFPOS End
12	LOAD perimeter
13	PRINT
14	STOP
15 length	
16 width	
17 perimeter	0
A

Output :

32
37
Q

How to check if this (or any other) program works correctly?

A

Testing: run the program and see if it works

Enter unexpected input data
* a negative or a floating-point number, e.g. 1.25
* a character, e.g. T

Above all else, programmers should test “edge cases”
* Does the program work with no input or only one number as input?
* Does it work with very small or very large numbers?
* If it works with 3 and with 1000 numbers as input, it is likely to work with 5 or 777 numbers (or anything in between) as well.