Sunteți pe pagina 1din 59

LESSON ACTIVITIES FOR

Block 3: Compression & Encryption and Block 4: Computers &


Assembly Language Programming

Lesson 1 activities

Activity 1.1

Fill in this table to help you see what a difference compression makes to file size.

File A File B File C

How many characters does


the file contain?

What type of content does


the file contain?

What is its file size before


compression?

What is its file size after


compression?

What is its compression ratio


(decompressed
size/compressed file size)?

Which file compresses the most? Explain why.

1
Activity 1.2

Your teacher is going to read out a series of binary numbers. The first pair of binary
numbers represents a colour code as follows:
00 = blue
01 = white
10 = yellow
11 = green
The second set of binary numbers represents the run length of the colour. So, for
example, 00, 1101 represents 13 blue pixels.

Assuming each of the squares in the grid below represents one pixel, listen to the
series of binary numbers and shade the squares. The first line of pixels has been done
for you.
Line 1: 00 0001 01 0011 00 1100

2
Activity 1.3 (homework)

 Use four different colours to “draw” an image in the grid below.

 Now encode the image using a 2-bit binary number to represent the colour depth
and a 4-bit binary number to specify the run length of the pixels to be filled with that
colour.
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12

3
Line 13
Line 14
Line 15
Line 16

4
Lesson 2 activities

Activity 2.1

Use the image you encoded for your homework to complete these calculations.

How many bytes are required to


represent the uncompressed file?
Remember: number of squares in grid x
2/8

How many bytes are required to


represent the RLE encoded file?
Remember: number of codes x number
of bits in each code / 8

How much storage space have you


saved?

Extension
Imagine that an image:
 contains 1,024 pixels (a grid of 32 pixels by 32 pixels)
 contains 255 different colours (represented by 8 bits)
The image has been encoded using RLE, producing 116 binary codes comprising 8 bits
(to represent the 255 colours) and 5 bits (to represent the colour run length).
Using this information, calculate:

How many bytes are required to


represent the uncompressed file?

How many bytes are required to


represent the RLE encoded file?

How much storage space have you


saved?

5
Activity 2.2

Use the Run Length Encoding Calculator to encode these text strings.

Text string Answer

AAAABBBBBBBBBCADDDDEEFFFFFF
FF

ABCABCABCABCABCABCABCABCAB
CS

BBGGYYAACCFFEEBBGGYYAACCFF
EE

Which one compresses the most?

Why is this?

Describe in English the process the RLE


calculator follows to encode a piece of
text.

6
Activity 2.3

An RLE compression algorithm works by removing repeated data and replacing it with a
number representing the run length of that item.

 Fill in the gaps to complete this algorithm.

1. Start with the first character in the string.

2. Write down the number 1.

3. Compare the first character with the next character on the right.

4. If they are the same, ___________________________________.

5. If they are not the same, ________________________________.

6. Move on to the next character on the right.

7. Go back to step 2 and repeat until you reach the end of the string.

8. _____________________________________________________.

 Test out the algorithm using these data strings:

o AAAABBBBBBBBBCADDDDEEFFFFFFFF
o ABCABCABCABCABCABCABCABCABCS
o BBGGYYAACCFFEEBBGGYYAACCFFEE

Activity 2.4 (homework)

Write a program in Python to implement the RLE compression algorithm you completed
in Activity 2.3.

Activity 2.5 (extension)

Write a program in Python to decode a file compressed using RLE compression.

7
Lesson 3 activities

Activity 3.1

The wheels on the bus go round and round, round and round, round and round.
The wheels on the bus go round and round all day long.

How many characters, including spaces and


punctuation marks, are there in this song?

Assuming one byte is used to represent each


character, what is its file size?

Complete this table.

Word Number of times used Number of bytes in word

The 2 3

wheels 2 6

on 2 2

the 2 3

bus

go

round

and

all

day

long

8
Activity 3.2

 Complete this lookup table of all the words used more than once in the song.
Lookup table
0. The
1. wheels
2. on
3. the
4.
5.
6.
7.

 Use the lookup table you have completed to encode the song, replacing repeated
words with the number representing their position in the table.

9
Activity 3.3

A lookup table has been used to encode this text:

Encoded text 0. Lossy


0 1 2 3 generally more effective 1. data
than 4 1 2 in reducing 5 size 6 7.
However, whereas 4 2 allows 5 8 2. compression
1 9 10 perfectly reconstructed 3. is
from 5 compressed 1, 11 2
causes some 6 5 8 1 9 10 4. lossless
permanently lost. 5. the
0 1 2 3 most often 12 for media 6. of
7, i.e. music, pictures 13 videos.
This type 6 1 3 intended 9 10 12 7. files
14 humans whose brains are 8. original
capable 6 ‘filling in 5 gaps’
9. to
created 14 11 2.
MP3 uses 11 1 2 9 compress 10. be
audio 7 for use on portable media 11. lossy
players where space 3 limited.
12. used
PNG 13 GIF use 4 1 2 9 reduce 5
13. and
size 6 image 7.
14. by

Decode the text.

10
‘Short and Sweet’

Complete the worksheet activity ‘Short and Sweet’ from Computer Science Unplugged.

‘Extra for Real Experts’

Complete the worksheet activity ‘Extra for Real Experts’ from Computer Science
Unplugged.

11
Lesson 4 activities

Activity 4.1

Use an image editor, such as pixlr’s photo editor online, to experiment with
compression. Start with an uncompressed BMP file. Fill in this table.

Original BMP image JPEG with 100% quality

[Insert image here] [Insert image here]

File size: File size:

Image quality: Image quality:

JPEG with 50% quality JPEG with 25% quality

[Insert image here] [Insert image here]

File size: File size:

Image quality: Image quality:

12
Activity 4.2

Use a media player such as iTunes to experiment with music compression by encoding
a music file using different bit rates.

Original uncompressed WAV file Higher quality MP3


(around 192kbps)

[Insert sound file here] [Insert sound file here]

Sound quality: Number of kbps:

Number of kbps: File size:

File size:

High quality MP3 Good quality MP3


(around 160kbps) (around 128kbps)

[Insert sound file here] [Insert sound file here]

Number of kbps: Number of kbps:

File size: File size:

13
Activity 4.3

Lossless and lossy compression summary sheet

Explain what is meant by lossless


compression.

What type of data can be


compressed using a lossless
compression algorithm?

Describe how a lossless RLE


algorithm works.

Some lossless compression


algorithms use a lookup table.
Explain what the lookup table is
for.
Explain how lossy compression
differs from lossless compression.

Explain why lossy compression is


usually used for media files.

Outline the process of


compressing an audio file using a
lossy compression algorithm.

Outline the process of


compressing a bitmap image using
a lossy compression algorithm.

14
Lesson 5 activities

Activity 5.1

Crack this code!

WKH WUHDVXUH LV KLGGHQ XQGHU WKH SDOP WUHH

Hint: H = E and W = T

Activity 5.2

Who uses encryption and what do they use it for what?

Users of encryption What they use encryption for

Businesses

Individuals

Governments

E-traders

The military

15
Activity 5.3 (homework)

Create your own cipher and then use it to encrypt a secret message. Make sure you
keep a note of the key to cracking your cipher, so that you (or someone else) can
decode the message later!

16
Lesson 6 activities

Activity 6.1

Use a Caesar cipher to decode and encode these messages.

Plain text Shift Encrypted text

THE ENIGMA MACHINE WAS +3


INVENTED BY THE
GERMANS

COLOSSUS WAS THE +4


WORLD’S FIRST DIGITAL
COMPUTER

+5 YMJ HFJXFW HNUMJW NX FS


JCFRUQJ TK WTRFS NSLJSZNYD

-3 QEB HBV FP EFAABK RKABO QEB


CILTBO MLQ

Activity 6.2

With a partner, produce a step-by-step guide to using a Caesar cipher to produce an


encoded message.

Activity 6.3 (homework)

Produce a step-by-step guide to decrypting messages that have been encoded using a
Caesar cipher.

17
Lesson 7 activities

Activity 7.1

A function caesar_cipher_encrypt has two arguments: a string ‘message’ and an


integer ‘key’ and returns a string ‘encrypted_message’.
All the characters that can be encrypted are stored in a list ‘letters’. Any characters in
‘message’ that are not in list ‘letters’ cannot be encrypted.
 Load and run the function to see for yourself what it does. First, open Activity7.1.py
in IDLE, then click Run > Run Module. Once the Python shell has loaded remember
that to run the function you need to call it and enter its arguments.
 Try different messages and different keys. What happens when a message includes
a character that can’t be encrypted? What happens when the character to be
encrypted is a ‘z’?
 Add comments to the Python code to explain how it works. You should add a
comment after every # in the Python code.
 Amend the function so that the digits 1–9 can also be encrypted.

Activity 7.2

 In pairs, make a new version of the function called caesar_cipher_decrypt that


decrypts text encrypted using a Caesar cipher.
 Add comments to the Python code to explain how this function differs from the
original.

Hint: The inputs to the function should be the text to be decrypted and the shift to be
applied.
Hint: The function should return the decrypted message.

Activity 7.3

There is really no need to have separate functions to encrypt and decrypt messages.
Produce a new function caesar_cipher that does both.

Hint: The function will need a third argument: a string ‘action’ to determine whether the
message has to be encrypted or decrypted.

18
Activity 7.4

Write a user interface for the caesar_cipher you produced in Activity 7.3. It should ask
the user to select whether they want to encrypt a message, decrypt a message or exit
the program.

19
Lesson 9 activities

Activity 9.1

List as many different types of digital computers as you can. Look for computers both in
the past as well as the present, and for objects that contain embedded computers.

Activity 9.2

Sort the things in this list according to whether they are hardware or software.
 Mouse
 Computer program
 Web browser
 Microphone
 CPU
 Hard disk drive
 Digital camera
 Windows operating system
 DVD drive
 Touch screen
 Word processor
 Speakers
 Spreadsheet
 Printer
 Mobile phone app
 Android operating system
 SD memory card
20
Hardware Software

Activity 9.3 (homework)

Answer these questions to summarise what you have learned in this lesson.
What is a digital computer?

Define computer hardware.

Give an example of computer


hardware.
Define computer software.

Give an example of computer


software.

21
Lesson 10 activities

Activity 10.1

 Write a computer program that asks the user to type in three numbers, adds them
up and then displays the answer on the screen.
 Explain your program using the input-process-output model.

INPUT PROCESS OUTPUT

Activity 10.2 (homework)

Select two actions you complete regularly and describe them in terms of the input-
process-output model.

Examples could be:


 Running a mobile phone app
 Uploading an image to a social networking profile

INPUT PROCESS OUTPUT

INPUT PROCESS OUTPUT

22
Lesson 11 activities

Activity 11.1

Use the function to identify the hardware component.

Function Hardware component

A temporary storage area for data and program


instructions while a program is running

A microprocessor which carries out the instructions in


computer programs by performing arithmetic and
logic operations, and controls inputs and outputs

A persistent data storage area for data and program


instructions

To provide connections to the input and output peripherals


such as printers, mouse, keyboard, touch screen,
speakers, networks, and so on

Activity 11.2

This diagram represents the way in which buses connect the main hardware
components in a digital computer. Copy and complete the diagram using these labels:
 CPU
 Memory
 Input/output devices
 Data, control and address bus

23
Activity 11.3

From the function given, identify and insert the name of the correct bus.
Function Type of bus

Sends and receives signals that control the CPU and


other parts of the computer system

Carries the address of memory locations used to


store data and program instructions

Transfers the binary data around the computer

Activity 11.4

Label the following on the picture of the Raspberry Pi:


 SD card (memory)
 CPU processor and RAM memory
 Ethernet network connection
 2 USB connectors (mouse and keyboard)
 HDMI connector for monitor
 Audio
 Power supply

24
Lesson 12 activities

Activity 12.1

Windows is an example of an operating system. List as many other operating systems


as you can. Aim for a list of at least five operating systems. Discuss with other class
members or use an internet search if you need to.

e.g. Windows

Activity 12.2

Assuming that the user is the outer circle, use the labels ‘hardware’, ‘application
software’ and ‘operating system’ for the other circles to show the role of the operating
system.

_______
_______
_______
user

25
Activity 12.3

Using a non-networked computer and the operating system of your choice, do the
following:

 make a hierarchy of directories and files


 remove files and directories
 rename files and directories
 change the current working directories
 view the current working directory.

Here is a list of useful Raspbian (Unix) and Command Line Interpreter (LX Terminal) file
and directory commands.

Commands Function

pwd Print working directory – display the current directory

cd directory Change directory

mkdir Make a new directory


directory

rm file Remove a file

touch file Create a new empty file

cat file Catalogue a file – list the contents of a file

ls -l List the files in the current working directory displaying all the
details about the files

Activity 12.4

 Bring up the task manager in whatever operating system you are using (in
Windows, control/alt/del).
 Find the networking information within the task manager (in Windows, choose the
networking tab).
 What happens when the user accesses the network, for example by opening a web
page or accessing information on a server?

26
Activity 12.5

 Bring up the task manager in whatever operating system you are using (in
Windows, control/alt/del).
 Find the user information within the task manager (in Windows, choose the user
tab).
 List the users who are using your computer. What information can you find out
about them?

27
Lesson 13 activities

Activity 13.1

 Open up the operating system’s task manager (in Windows, control/alt/delete) and
find the list of applications running (in Windows, choose the Applications tab).
 Now find the information on the processes running (in Windows, choose the
Processes tab). Scroll up and down the list to see how many processes it takes to
run the operating system and any applications you currently have open.
 Now open up a few applications, e.g. a web browser, word processor, spreadsheet
software, a graphics package.
 Answer these questions:
1. What happens to the list of applications?
2. What happens to the number of processes running on the computer?
3. Try to explain why there are more processes running than applications
running.

Activity 13.2

Your teacher will run this activity. The instructions are here for information only.

Process scheduling – an “unplugged” activity to simulate the scheduling of


processes

Requirements
 Large stick notes
 White board
 Two tables
 Area for process queue
 Stop watch
 Pens
 Two students who represent the operating system (“OS1” will allocate the process
ID and time slots, “OS2” will send the next process to the CPU)
 One student who represents the “CPU”
 One student who represents the “user” who is running the programs
 Sixteen other students who represent the programs and applications and who will
be the “processes” (just add more programs/applications depending of number of
students in group)

Starting positions
 The “CPU” should sit at a table with a pen and stop watch.
 “OS1” needs a pen and an empty process table drawn on a whiteboard (add more
rows as required:
Process ID Name of program or application

28
 Allocate a queue area where the “processes” will stand in order while they wait to
be “executed” after they have been allocated a process ID.
 The “user” sits at table with a pen and sticky notes.

Running the programs


 The “user” starts by writing on a sticky note the name of a program or application, in
the order given in the table below. The “user” must write program and application
names in the same order as they appear in the table below.

Word processor
Web browser
Sound program
Myprog.py
Sort.py
Word processor
Myprog.py
Spreadsheet
Sort.py
Word processor
Spreadsheet
Web browser
Sound program
Web browser
Sound program
Sort.py

 The “user” hands the sticky note on which he/she has written a program or
application name to a student who will be that “process”.
 The “process” goes to “OS1” who allocates the next free process ID from the
process table. “OS1” also allocates the correct number of time slots needed to
complete the process, according to the table below:

Type of process Time slots


word processor 1 2 3
myprog.py 1 2
sort.py 1
spreadsheet 1 2 3 4
web browser 1 2 3
sound program 1 2 3 4 5

 So, if the “process” hands “OS1” a sticky note that says “Word processor”, “OS1”
adds a process ID and three time slots “1, 2, 3” to the stick note and hands it back
to the “process”. “OS1” must also update the process table on the whiteboard.
 The “process” joins the back of the queue holding up their sticky note.

29
 “OS2” is constantly looking at the queue waiting for a process with a process ID.
They send the “process” at the top of the queue to the “CPU” table.
 Each “process” gets 10 seconds to execute with the “CPU” – when the “process”
arrive at the table, “CPU” starts the stop watch, crosses one time slot off the sticky
note and then says “Time’s up” after 10 seconds. At this point, the “process” must
return to the back of the queue.
 The “process” should check their sticky note. If all their time slots have been
crossed off, they should shout their process ID and “Finished” and then sit down.
 When “OS1” hears that a process has finished, they should remove that process
from the process table
 If the “process” still has time slots left they go to the back of the queue.
 Repeat until all the processes have finished.

Alternatives
 Change the length of the time slice (make it more or less than 10 seconds)
 Add more or different programs/applications
 Give the processes a priority which alters their position in the queue

30
Lesson 14 activities

Activity 14.1

The speed of a computer system is measured in frequency (cycles per second) using
the units hertz (Hz). One hertz is one cycle per second. This means that one instruction
is executed per second.

For many years computers were measured in megahertz (MHz).

1 megahertz = 1,000 hertz or 1,000 instructions per second.

Modern computers are so fast they are measured in gigahertz (GHz).

1 gigahertz = 1,000,000,000 hertz or 1,000,000,000 instructions per second.

Find the speed of the processor in the computer systems you use and calculate how
many instructions they can process each second.

Type of computer Clock speed Instructions per second

Activity 14.2

Your teacher will run this activity. The instructions are here for information only.

Resources

 A class of pupils
 A room such as a hall or an open space
 On/off card

Explain that the class is going to act out the role of transistors in a CPU. When they are
on they stand up (show ON) and when they are off they sit down (show OFF). (This
works best if they are on the floor not on seats).

The pupils should stand apart from each other (stretch arms out so they cannot touch
each other). Show the ON and OFF cards slowly to start with, then speed up. Ask how
warm the class is feeling (they should be getting warmer just like a CPU).

Then explain that more and more transistors are being placed closer together to make
computers faster and able to perform more calculations.

31
Get the class to stand closer to each other. Then repeat the process getting faster and
faster. Ask how warm the class is feeling now.

This demonstrates how CPUs generate heat from the switching of thousands of
transistors.

Activity 14.3 (homework)

Watch all of the Royal Institution lecture ‘Breaking the speed limit’:
http://www.youtube.com/watch?v=FTpdAjre8LU and then answer these questions.

1. What is a semi-conductor?
2. What is a transistor?
3. Why are “bunny suits” used when manufacturing microprocessors?
4. What is meant by parallel processing?

32
Lesson 15 activities

Activity 15.1

Check the system settings or search online for the technical specifications of the digital
computers that you use. Note down the name and speed of the CPU in each device, as
well as whether the CPU is a single core or multi-core processor.

Type of computer Name of CPU Speed (Hertz) Single core or


multi-core?

Activity 15.2

Take a screen shot showing the CPU usage. (On Windows 7 select Task Manager
(control-alt-del) and select the Performance tab then click on the “Resource Monitor…”
button then click on CPU). Label the number of cores and the amount of CPU usage.

33
Lesson 16 activities

Activity 16.1

The main memory (or RAM) is made up of memory locations. Each memory location
has a unique address assigned to it. Data and instructions are stored in memory when
programs and applications run.
Place the following data and instructions into the memory location at the correct
address:
 At address 0011 store the ASCII binary for ‘c’
 At address 0100 store the ASCII binary for ‘a’
 At address 0101 store the ASCII binary for ‘t’
 At address 1001 store the binary value for 4
 At address 1100 store the binary value for 65
 At address 1110 store the binary value for 201
 Store the first three letters of your name starting at address 0000

Address Memory location


1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001
0000

34
Activity 16.2

Calculating the maximum capacity of main memory:


A processor with a 4 bit address bus can create 24 (or 16) addressable memory
locations
A processor with an 8 bit address bus can create 28 (or 256) addressable
memory locations

Calculate the maximum number of addressable memory locations for address buses of
the following sizes.

Size of Maximum number of


address bus addressable memory locations
4 bit 16
8 bit 256
16 bit
32 bit
64 bit

Activity 16.3

This activity gives you an opportunity to find out how much memory there is in the
computers you use.
Either check the system settings or search online for the technical specifications of your
computers and complete the table below. Add more rows if you need to.

Type of computer Main memory

35
Activity 16.4

Sort the stages of a memory read into the correct order:


 Processor sets the read line on the control bus
 Contents of the memory location are conveyed along the data bus into the
processor
 Processor places the address of the required memory location on the address bus

Step 1
Step 2
Step 3

Sort the stages of a memory write into the correct order:


 Processor places the data to be written to memory on the data bus
 Processor places the address of the required memory location on the address bus
 The data is conveyed along the data bus to the memory location
 Processor sets the write line on the control bus

Step 1
Step 2
Step 3
Step 4

Activity 16.5

Type of computer Type of Maximum


secondary capacity
storage device

36
Activity 16.6 (homework)

Search online for companies that sell memory (such as http://www.crucial.com/). Find
three further facts about memory that you can share with the class.

Fact 1
Fact 2
Fact 3

37
Lesson 17 activities

Activity 17.1

Sort the following devices according to whether they are input or output devices.
 Mouse
 Speakers
 Monitor
 Touch screen
 Keyboard
 LED
 Sensor
 Microphone
 Scanner
 Printer
 Web cam
 Digital camera

Input devices Output devices

38
Activity 17.2

In your group, identify all the input devices found on the digital computer you have been
assigned.

Digital computer you have been assigned:

Activity 17.3

Complete the table below to create a reference sheet for yourself.

Input device How does it work? (2 or 3 sentences) Image


Optical mouse The optical mouse uses a light emitting
diode (LED) as a light source, a small
camera and a small processor. The light
from the LED illuminates the surface
and the camera takes pictures, which
are compared by the program in the
processor to determine how far the
mouse has travelled. This information is
then conveyed to the main CPU.
Keyboard The computer keyboard uses an
arrangement of keys to input characters
to the computer. Keyboards use a range
of different switching technologies to
send a code which represents the key
that has been pressed to the CPU.
Touch screen
Web cam
Scanner
Sensors
Microphone

39
Lesson 18 activities

Activity 18.1

In your group, identify all the output devices found on the digital computer you have
been assigned.

Digital computer you have been assigned:

Activity 18.2

Complete the table below to create a reference sheet for yourself.

Output How does it work? (2 or 3 sentences) Image


device
LCD screen
Speakers
Projector
Inkjet printer
Laser printer

40
Lesson 19 activities

Activity 19.1

Check the system settings of your digital computers or search online for their technical
specifications to find out the type of storage you are using.

Type of computer Type of storage Maximum storage Magnetic, optical


device capacity or solid state?

Activity 19.2

 Do the following:
o Save a file onto the magnetic hard disk drive.
o Burn a file on to a CD or DVD.
o Save a file on to a solid state drive or a memory stick.

 Now describe in your own words how the data in the file was stored on each of
these types of storage.

Magnetic storage,
e.g. hard disk drive

Optical storage, e.g.


CD / DVD drive

Solid state storage,


e.g. memory stick

41
Lesson 20 activities

Activity 20.1

Use the labels below to complete the diagram.

 Memory
 Control unit
 Arithmetic and logic unit (ALU)
 Registers

PROCESSOR
Control bus

Address bus

Data bus

Draw lines to match the parts of the processor with the correct function.

Accumulator register Sends out signals to other parts of the


computer system and fetches, decodes and
executes instructions

Control unit Carries out arithmetic and logic operations

Registers Individual storage locations which hold an


instruction, data or address of a memory
location

Arithmetic and logic unit Holds the instruction that is currently being
(ALU) executed by the processor

Program counter register Holds the accumulated total of results


performed in the ALU

Instruction register Holds the address of the main memory


location storing the next instruction

42
Lesson 21 activities

Activity 21.1

The first column of the table contains some assembler instructions for the ARM1176JZ-
S processor. Match each assembler instruction with the correct action and underline the
part of the action that helped you know which assemble instruction it relates to. One
has been done for you.

Assembler instruction Action


ADD Load from memory address into a register
SUB Branch to a marked position in the program
MUL Move data to a register
MOV Store values in a register
CMP Subtract data in registers
LDR Compare values in registers
B Multiply data in registers
STR Add data in registers

Activity 21.2

Use the labels below to complete the diagram on the next page. The diagram shows
how high level programs are translated into machine code so that they can be run by
the CPU.

Labels

 Python (high level language)


 Machine code
 Compiler
 Assembly language (low level language)
 Assembler

43
MOV R1, #50

MOV R2, #60

ADDS R0, R1, R2

MOV R7, #1

1111000011110000

1011100011100010

1010010010010100

44
Lesson 22 activities

Activity 22.1

Complete this diagram of the fetch-decode execute cycle using the labels below.

Labels

 FETCH
 DECODE
 EXECUTE
 Fetches the next instruction from memory and increments program counter
 Decodes the bit pattern (machine code) into the instruction to be executed
 Executes the instruction and stores the results in memory or registers

45
Activity 22.2

Guess how many fetch-decode-execute cycles are happening in the classroom at this
moment! Write your guess here:

Now you’re going to do a proper estimate!

 Estimate the number of digital computers (desktops, laptops, tablets, mobile


phones, etc.) in the room:
 Assuming a clock speed of 1 GHz for each digital computer and that each fetch-
decode-execute cycle takes 10 instructions, calculate the number of fetch-decode-
execute cycles taking place per second.

Activity 22.3

Sort these stages of the fetch-decode-execute cycle into the correct order:

Increment the program counter to point to the next instruction

Decode the instruction

Store results in a register

If the instruction uses data from memory, identify the memory addresses and fetch the
data from memory

Fetch the next instruction from main memory using the memory address in the
program counter register

Execute the instruction

46
FETCH

1.
2.

DECODE

3.
4.

EXECUTE

5.
6.

47
Lesson 23 activities

Activity 23.1

Label or colour code this assembly language instruction to show the opcode, and the
destination and input operands.

SUB R0, R1, R2

What does this instruction ask the processor to do?

What is an immediate value?

Write the instruction to add the


immediate value 8 to the contents
of register R2 and store the result
in register R4.

Write the instruction to multiply the


contents of register R1 by the
contents of register R2 and store
the result in register R0.

What does this instruction ask the


processor to do?
MOV R5, #1

48
Activity 23.2

ADD R0, R1, R2


In this instruction there are three
operands: registers R0, R1 and
R2.
Explain how a register differs from
memory.

How many general-purpose


registers does the ARM11
processor have?

Show the contents of the registers as each instruction is executed.

Hint: the MOV command actually puts a copy of the data in the specified register. The
original stays where it is.

R0 R1 R2
0 5 3

MOV R0, R1 5 5 3

MOV R1, R2 5 3 3

MOV R2, R0

R0 R1 R2

9 5 3

MOV R0, #0 0 5 3

ADD R0, R0, R1

SUB R0, R0, R2

MUL R0, R1, R2

49
R0 R1 R2

4 2 2

MUL R0, R1, R2

MUL R1, R0, R2

MUL R0, R1, R2

R0 R1 R2

0 7 5

SUB R0, R1, #3

ADD R2, R2, #1

SUB R0, R1, R2

Write an assembly language program to compute 3x + 6x. Assume that the value of x is
stored in register R5. Add comments to your code to make it easier to understand.
Hint: the MUL command can only have registers as operands so you will need to store
the immediate values 3 and 6 in registers.

50
Activity 23.3 (homework)

Summarise what you have learnt so far.

List five different types of 1.


computer devices that use an 2.
ARM processor. 3.
4.
5.
ARM processors are designed to
keep energy consumption to a
minimum.
Explain why this is desirable.

Explain why every processor type


has its own instruction set.

Explain how machine code differs


from assembly language.

What is a mnemonic?

List three assembly language 1.


mnemonics and state what they
2.
do.
3.
Each assembly language
instruction consists of an opcode
and one or more operands.
Operands can be one of two sorts.
What are they?
The ARM11 has a 32-bit address
bus.
Describe the function of the
address bus.
How many unique memory
locations does a 32 bit address
bus provide?
51
Explain what this command does.

MUL R1, R0, R3

What do these mnemonics stand  CMP


for?
 MOV
 LDR
 B
 SUB
 MUL
The ARM11 instruction set has Data manipulation
three groups of instructions: ‘data 
manipulation’, ‘load and store’ and 
‘branch’. 
Put these instructions into the 
correct group: 
 ADD
 LDR
 B
 SUB
 MUL Load and store
 CMP 
 STR 
 BL Branch
 MOV


Which component of the processor
carries out data manipulation
instructions?

Load and store instructions are


used to access memory. How is
data transferred between memory
and the registers?

52
Lesson 24 activities

Activity 24.1

Write comments for these two lines of code.

ADD R0, R1, R2

ADDEQ R0, R1, R2

Explain what this piece of code does.

CMP R0, R1
MOVGT R2, R0

Write comments for each line of this program.

MOV R0, #5

MOV R2, #6

CMP R0, R2

MOVEQ R3, R0

MOVNE R3, R2

What will be the outcome of executing this piece of code if register R0 holds the value 9
and register R1 holds the value 15?
CMP R0, R1
SUBGT R0, R0, R1
SUBLT R1, R1, R0

What will be the outcome of executing this piece of code if register R0 held the value 3
and register R1 held the value 3?
CMP R0, R1
ADDGT R0, R0, R1
ADDLT R1, R1, R0

53
Write an assembly language program to swap the contents of register R1 and register
R2 if the value in R1 is greater than the value in R2. Add comments to your code to
make it easier to understand.

Write an assembly language program to set the contents of register R1 to #1 if the


contents of register R5 is less than or equal to 100. Add comments to your code to
make it easier to understand.

54
Activity 24.2

ARM processors have a load-store architecture. Explain what this means.

Explain what this piece of code does.

LDA R0, [R2]


LDA R1, [R3]
ADD R0, R0, R1
STR R0 [R2]

55
Activity 24.3 (homework)

Draw a flowchart to illustrate what this piece of code does.

start MOV R0, #0


MOV R1, #10
loop ADD R0, R0, R1
SUB R1, Rl, #1
CMP R1, #0
BNE loop
STR R0, [R3]
stop B stop

56
Draw a flowchart to illustrate what this piece of code does.

start LDA R0, [R3]


LDA R1, [R4]
loop
CMP R0, R1
SUBGT R0, R0, R1
SUBLT R1, R1, R0
BNE loop
stop B stop

57
Write an assembly language program to implement this algorithm.

58
59

S-ar putea să vă placă și