Part 5 Low-level machine - Portlethen Academy

chantingrompΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 3 χρόνια και 4 μήνες)

71 εμφανίσεις

National  4  and  5
 
Computing  Science
 
 
 
 
Software  Design  and  Development  
 
Part  
5
 

 
Low
-­‐
level  Machine
 
 
Pupil  Notes
 
Name:  
 





























..
 
Class:
 













.
2
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
Foreword
 
 
This  set  of  notes  contains  the  information  that  you  are  expected  to  
know  to  pass  the  assessment  for  
Outcome  1
 of  the  
Software  
Design  and  Development  Unit  
of  the  
Computing  Science
 course  
at  
National  4
 and  
National  5
 levels.  There  is  also  a  section  that  
contains  advice  on  how  to  complete  the  investigation  that  forms  
the  last  part  of  this  unit  

 
Outcome  3
.
 The  materials  are
 believed  to  
be  in  accordance  with  the  Unit  Specifications  published  at  the  end  
of  April  2012.
 
 
The  material  does  
not
,  however,  contain  notes  on  how  to  complete  
Outcome  2
 of  the  Unit.  This  is  the  set  of  practical  exercises  that  
demonstrate  your  skill  in  actually  designing  and  developing  basic  
applications.  It  is  up  to  each  school  to  decide  which  development  
environment  to  use  to  achieve  this  outcome  rendering  inclusion  of  
these  impractical.  
 
 
A  vertical  line  drawn  down  the  outside  edge  indicates  material  that  
should  only  be  assessed  at  the  
National  5
 level.    This  does  not  
mean  that  those  studying  at  
National  4
 should  ignore  these  parts,  
just  that  they  should  not  be  assessed
 in  them!
 
 
Occasionally,  extra  pieces  of  information  have  been  added  to  the  
notes,  sometimes  as  a  warning  of  a  common  cause  of  an  error  when  
developing  software  or  just  some  additional  information.  Again  
these  should  not  be  assessed.  Such  extra  pieces  of  i
nformation  are  
surrounded  in  a  box  like  this.
 
 
There  are  exercises  scattered  throughout  the  materials.  You  should  
complete  these  t
o  demonstrate  that  you  understand  the  topic  that  
you  have  just  been  studying.  
T
he  
suggested  answers  to  these  
exercises  are  in  a  separate  booklet.
 
 
A  glossary  of  the  terms  that  you  
should
 know  for  the  assessment  
is  
also  
available  in  a  separate  booklet.
 
 
Finally  these  materials  are  copyright  ©  Eric  Forrester,  2012  and  
may  only  be  reproduced  within  the  establishment  that  purchased  
them.
 
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
3
 
Table  of  Conten
ts
 
 
Foreword
 
2
 
Table  of  C
ontents
 
3
 
Section  5  

 Low

level  Processing
 
4
 
 
Exercise
 16
 

 Computer  architecture
 
9
 
 
Exercise  1
7
 

 Integer  storage  
 
14
 
 
Exercise  1
8
 

 Real  numbers  storage
 
17
 
 
Exercise  1
9
 

 Character  storage
 
22
 
 
Exercise  
20
 

 Image  storage
 
26
 
 
Exercise  2
1
 

 Instruction  storage
 
28
 
 
Exercise
 22
 

 Compilers  and  interpreters
 
32
 
4
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
 
Section  5
 
Low
-­‐
level  Processing
 
 
By the end of this section you should


1.

Understand the binary number system.

2.

Appreciate why binary numbers are used in modern digital
computers

3.

Know the basic architecture of a computer

4.

Know the units of storage of computer memory

5.

Know how data is represented in a computer’s memory as
binary

6.

Know how program instructions are
stored in computer
memory
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
5
 
5.1

Understand the binary number system

Since  toddlers,  we  have  been  brought  up  to  count  using  the  decimal  
system  
-­‐
 that  is  using  the  numerals  0,  1,  2,  3,  4,  5,  6,  7,  8  and  9.  If  we  
want  to  represent  a  number  bigger  that  9  we  
start  combining  the  
numerals  to  give  23,  148  or  1037857563.  
 
Humans  use  decimal,  because,  with  most  of  us  having  10  fingers,  
we  can  use  them  to  help  us  count!
 
However,  any  number  can  be  used  as  a  base  for  counting.  The  most  
commonly  used  alternative  to  usi
ng  ten  numerals  is  to  use  just  two  
numerals,  0  and  1.  This  is  called  the  
binary
 (meaning  two)  number  
system.
 
Any  number  that  you  can  represent  in  decimal  can  also  be  
represented  in  binary.  
 
 
For  example:
 
 
Decimal
 
0
 
1
 
   2
 
   3
 
       4
 
       5
 
       6
 
       7
 
           8
 
9
 
 
 
Binary
 
0
 
1
 
10
 
11
 
100
 
101
 
110
 
111
 
1000
 
 
1001
 
 
You  will  learn  later
 how  to  convert  a  decimal  number  into  binary  
and  a  binary  number  into  decimal.
 
 
You  can  carry  out  calculations  in  binary,  just  as  you  can  in  decimal.
 

6
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
5.2

Appreciate why binary numbers
are used in modern
digital electronic computers


Engineers  like  to  use  what  they  call  the  KISS  principle  when  they  
are  asked  to  build  something  new.    KISS  stands  for…
 
 
 
 
K
eep
 
I
t
 
 
S
imple
 
 
S
tupid
 
 
The  simplest  number  system  is  Binary.
 
The  simplest  electronic
 component  is  a  switch.
 
Put  the  two  together  and  we  get  the  modern  electronic  digital  
computer!
 
If  a  switch  is  set  to  ‘on’  then  that  represents  a  ‘1’  in  binary.
 
If  the  switch  is  set  to  ‘off’  then  that  represents  a  ‘0’  in  binary.
 
With  enough  switches  you  
can  make  a  digital  computer.
 
However,  modern  computers  may  have  started  off  simple  but  
inside  they  are  now  made  up  of  billions  of  microscopic  switches  
called  transistors,  but  still  working  with  the  binary  number  system.
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
7
 
5.3

Know the basic architecture of a
computer

Modern  digital  computers  tend  to  follow  this  arrangement:
 
 
As  you  can  see  it  is  made  up  of  the  following  four  major  parts:
 
The  
Central  Processing  Unit
 (
CPU
)  

 which  fetches  and  
executes  the  instructions
 (in  binary)
 that  make  up  the  programs.
 
ROM
 

 
Read  Only  Memory
 

 permanent  memory  whose  
contents  cannot  be  changed  nor  lost  when  the  power  is  switched  
off.
 Often  the  program  that  starts  up  the  computer  when  i
t  is  
switched  on  (called  a  boot
strap  loader)  is  stored  here.
 
RAM
 

 
Random  Access  Memory
 

 memory  whose  contents  can  
be  changed  but  which  are  lost  when  the  power  is  switched  off.
 All  
programs  loaded  from  the  backing  store  are  stored  here  and  
most  data  that  they  will  use  is  also  stored  here
 when  they  are  
run
.
 
 
 
8
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
 
Interfaces
 

 used  to  match  the  signals  going  to  and  from  the  input,  
output  and  backing  storage  devices  to  the  processor.
 Without  the  
interfaces  the  signals  going  to  and  from  the  memory  and  the  
devices  would  be  going  too  fast  for  the  input,  output  or  backing  
stores  or  the  signals  from  the  input,  output  or  backing  stores  would  
be  at  the  wrong  voltage  and  may  damage  the  memory
 or  Central  
Processing  Unit.
 
These  four  parts  are  connected  together  through  bundles  of  wires  
called  the  
Address  Bus
,  the  
Data  Bus
 and  the  
Control  Bus
.  
 
The  
Address  Bus
 is  used  to  pick  out  an  
individual  
address  in  the  
memory
 and  interfaces
.
 No  two  location
s  can  have  the  same  
memory  address  in  the  computer.
 
The  
Data  bus
 is  used  to  transfer  data  between  the  
different  parts  
of  the  computer.
 
The  
Control  Bus
 is  used  to  make  sure  all  of  the  transfers  happen  in  
the  right  order  and  at  the  right  time.
 
 
You  will  go  into  
a  little  
more  detail  for  each  of  these  parts  in  the  
Information  Systems  Design  and  Development  Unit  when  you  look  
at  the  computer  hardware  needed  to  run  Information  Systems.
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
9
 
Exercise  16
 
Answer  each  of  the  questions  on  the  lines  that  
follow  them.
 
1.
 
What  are  the  four  main  components  that  make  up  a  simple  
computer  architecture?
 
 
 
2.
 
In  which  component  are  applications  stored  that  have  been  
loaded  
from  the  hard  disk
?
 
 
3.
 
What  kind  of  application  might  be  stored  in  ROM?
 
 
 
4.
 
Why  can  the  
keyboard,  mouse,  display  or  disk  drive  NOT  be  
connected  directly  to  the  computer  through  the  busses?
 
 
 
5.
 
What  would  happen  if  the  ar
chitecture  did  not  include  the  A
ddress  
bus?
 
 
 
6.
 
What  would  happen  if  the  architecture  only  included  the  Address  
and  Data  
busses?
 
 
 
10
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
5.4

Know the units of storage of computer memory

 
The  smallest  piece  of  memory  is  called  a  
bit
.
 
Bit  is  short  for  ‘binary  digit’  

 a  ‘1’  or  a  ‘0’.
 
8  bits  
 
 
=  
 
1  
byte
 
1024  bytes  
 
=  
 
1  
kilobyte
 or  Kb
 
1024  KB  
 
 
=  
 
1  
megabyte
 or  Mb
 
1024  MB  
 
=  
 
1  
gigabyte
 or  Gb
 
1024  GB  
 
 
=  
 
1  
terabyte
 or  Tb
 
1024  Tb
 
 
=
 
1  
petabyte
 or  Pb
 
1024  Pb
 
 
=
 
1  
exabyte
 or  Eb
 
1024  Eb
 
 
=
 
1  
zettabyte
 or  Zb
 
These  last  two  are  just  for  completion,  you  don’t  need  to  know  
them!
 
Modern  desktop  computers  
often
 have  at  least  1  Gb
 of  memory  

 
though  they  will  work  a  lot  better  with  more  than  this!
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
11
 
5.5

Know how data is represented in a computer

s memory
as binary

You  learned  in  5.4  that  the  smallest  unit  of  main  memory  is  a  
bit
 
and  that  it  can  only  hold  a  ‘
0
’  or  a  ‘
1
’.
 
This  means  that  
all
 
software
 

 programs  and  data  
-­‐
 are  stored  as  

1
’s  and  ‘
0
’s.    
 
All  software
 

 programs  and  data  are  stored  in  the  main  memory  of  
the  computer  as  
binary
.
 
After  we  type  in  a  number  or  a  sentence  or  draw  a  simple  picture  
on  the  screen,  the  
data  we  entered  is  converted  into  binary  to  store  
it  in  the  computer’s  main  memory.
 
Similarly,  when  data  in  main  memory  has  to  be  displayed  it  has  to  
be  converted  back  from  binary  into  text,  numbers,  pictures  or  
sounds.
 
In  addition,  all  of  the  instructions
 that  make  up  a  program  must  be  
converted  into  binary  for  storage  and  it  is  the  binary  instructions  
that  are  used  when  the  program  runs.
 
 
This  part  will  look  at  how  software  is  stored  as  binary.
 
12
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
1.
 
Storing  positive  whole  numbers  as  binary
 
A  decimal  number
 must  be  converted  into  binary  to  store  it  in  the  
computer’s  main  memory.
 
For  example  to  convert  the  decimal  number  37  to  binary:
 
Write  down  this  sequence  of  numbers:
 
 
128
 
64
 
32
 
16
 
8
 
4
 
2
 
1
 
By  adding  combinations  of  these  numbers  together  you  can  make  
any  d
ecimal  number  up  from  1  to  255  by  
only  using  each  number  
once
.
 
Decide  which  numbers  are  needed  to  make  up  our  number  37  and  
write  a  ‘1’  underneath  it  like  this:
 
 
128
 
64
 
32
 
16
 
8
 
4
 
2
 
1
 
 
 
 
1
 
 
 
1
 
 
1
 
That  is:  
 
37  =  32  +  4  +  1
 
Write  a  ‘0’  under  each  of  the  other
 numbers
 
 
128
 
64
 
32
 
16
 
8
 
4
 
2
 
1
 
 
0
 
0
 
1
 
0
 
0
 
1
 
0
 
1
 
That  is  it!
 
37
 in  binary  =
 00100101
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
13
 
2.
 
Converting  binary  numbers  into  decimal  numbers.
 
To  convert  a  binary  number  back  to  decimal  you  just  reverse  the  
process!
 
For  example  to  convert  the  binary  number  
1101010  to  decimal  you  
would  do  this:
 
If  the  binary  number  has  less  than  8  digits  then  add  0s  to  the  front  
of  the  number  to  make  it  up  to  8  digits  long.  E.g.  01101010
 
Write  down  the  same  sequence  of  numbers
 
 
128
 
64
 
32
 
16
 
8
 
4
 
2
 
1
 
Beneath  this  write  down  the
 binary  number  you  want  to  convert:
 
 
128
 
64
 
32
 
16
 
8
 
4
 
2
 
1
 
 
0
 
1
 
1
 
0
 
1
 
0
 
1
 
0
 
This  means  that  the  decimal  number  is  made  up  of:
 
 
64  +  32  +  8  +  2  =  106
 
Simple!
 
 
01101010  =  106  
in  decimal
 
Note
:  negative  
whole  
numbers  are  a  little  harder  to  deal  with  so  
they  are
 left  to  Higher  Computing!
 
14
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
Exercise 17

Answer  each  question
 o
n  the  
line
 that  follows  it.
 
1.

How  many  digits  are  there  in  the  decimal  number  system?
 
 
2.

How  many  digits  are  there  in  the  binary  number  system?
 
 
3.

What  must  happen  to  a  decimal  number  before  it  can  be
 stored  in  
a  computer’s  main  memory?
 
 
4.

Convert  the  following  numbers  from  decimal  to  binary.
 
a)

13
 
 
b)

29
 
 
c)

92
 
 
 
d)

115
 
 
5.

Convert  the  following  numbers  from  binary  to  decimal
 
a)

1011
 
 
 
b)

101011
 
 
c)

11101110
 
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
15
 
3.
 
Converting  real  decimal  numbers  to  binary
 
An  example  of  a  real  
decimal  number  might  be  174.029
 
You  have  seen  how  whole  numbers  can  be  converted  into  binary,  
but  how  can  real  numbers  be  converted?
 
The  first  problem  is  dealing  with  the  decimal  point  (.)!  
 
With  only  ‘
0
’  and  ‘
1
’  available  there  is  no  way  to  store  the  deci
mal  
point  in  binary  
-­‐
 so  we  don’t!
 
The  first  step  in  storing  a  real  decimal  number  
in
 binary  is  to  
convert  it  into  its  ‘scientific  form’  which  always  puts  the  decimal  
point  in  the  same  place  
-­‐
 so  we  don’t  have  to  store  it.
 
So  174.029  becomes  0.174029  x  10
3
 
 
The  first  part  of  the  number  (0.174029)  is  called  the  
mantissa
.
 
The  
power
 of  10  (3)  is  called  the  
exponent
.
 
Real  numbers  are  stored  by  taking  the  mantissa  and  converting  it  
to  binary,  and  then  taking  the  exponent  and  converting  it  to  binary  
as  well.
 
The  two  parts  are  then  
stored
 together...
 
 
 
 
 
Mantissa
 
Exponent
 
 
So  174.029  would  be  saved  as...        
0.174029
 
3
 
   only  as  binary!
 
 
16
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
Using  this  technique  it  is  possible  to  store  very  large  numbers  as  
binary  in  the  computer’s  memory,  without  taking  up  a  lot
 of  bytes.
 
There  are,  however,  some  down  sides  to  storing  numbers  this  
way...
 
1.

Much  more  processing  is  needed  to  turn  a  decimal  number  into  
a  binary  real  number  in  mantissa  and  exponent  and  back  again.  
This  slows  a  program  down.
 
 
2.

Similarly  carrying  out  
calculations  with  binary  real  numbers  in  
mantissa  and  exponent  takes  far  longer  than  with  whole  
numbers.  Similarly,  this  slows  a  program  down.
 
 
3.

The  number  of  bytes  that  are  used  to  store  the  mantissa  
determines  how  accurately  the  number  is  stored.  Too  smal
l  a  
mantissa  and  the  error  in  
all
 calculation
s
 
gets
 bigger!  (There  
are  never  any  errors  in  storing  and  doing  calculations  with  
whole  numbers  in  binary!)
 
There  is  one  up
-­‐
side  to  storing  numbers  this  way...
 
Using  just  1  byte  for  the  exponent,  it  is  possible  
to  hold  numbers  up  
to  10
38
!  That  is  a  1  with  38  zeros  after  it!  So  very  large  numbers  can  
be  stored  without  using  very  much  memory.  
Sometimes
,  just  3  
bytes  are  assigned  to  the  mantissa  and  1  byte  to  the  exponent.
 
Too much? Don’t worry! Converting a real de
cimal number into
its binary mantissa and exponent is way beyond this course!

Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
17
 
Exercise 18

Answer  each  question  o
n  the  
line
 that  follows  it.
 
1.

What  is  5.3746  in  scientific  notation?
 
 
2.

What  is  1645685.578  in  scientific  notation?
 
 
3.

What  is  the  mantissa  of  
0.4565335  x  10
5
?
 
 
4.

What  is  the  exponent  of  0.987595  x  10
23
?
 
 
5.

How  is  the  number  0.725648  x  10
18
 stored  as  its  mantissa  and  
exponent?
 
 
6.

What  effect  on  processing  speed  does  the  use  of  real  numbers  have  
on  a  computer  program  when  it  is  running?
 
 
7.

What  effect  doe
s  assigning  too  few  bytes  to  hold  the  mantissa  have  
on  calculations?
 
 
8.

Why  are  real  numbers  stored  using  a  mantissa  and  an  exponent  in  
a  computer’s  memory?
 
 
 
18
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
4.
 
Storing  text  as  binary
 
To  convert  text  into  binary,  the  processor  takes  each  character  of  
the  text  as  it  is  entered  and  looks  up  a  table  of  binary  numbers  to  
represent  that  character
.    
 
This  binary  number  is  then  stored  in  its  memory,  usually  one  
character  number  to  a  single  byt
e.  
 
The  table  of  numbers  that  is  often  used  is  called  the  American  
Standard  Code  for  Information  Interchange  or  
ASCII
.
 
 
Note:  ASCII  is  being  replaced  by  a  system  called  UTF
-­‐
8,  which  has  
all  of  t
he  same  characters  as  ASCII.
 
Opposite  is  the  table  of  ASCII  codes  used.    
 
Such  a  table  forms  part  of
 a  
character  set
.    It  lists  all  of  the  
characters  the  computer  will  use.
 
 
(Note:  You  don’t  have  to  remember  this  table!)
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
19
 
 
!
20
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
If  you  count  up  the  number  of  characters  shown  in  the  table  
you  
will  find  it  only  comes  to  96!
 
The  ASCII  code  actually  defines  128  codes.  
 
The  missing  32  codes  are  called  
control  codes
 or  
non

printing
 
codes.    These  are  used  for  such  things  as…  
 
 
 
return;
 
 
 
line  feed;
 
 
 
tab;
 
 
 
 
page  feed  or  clear  screen;
 
 
 
move  the  
cursor  up  a  line;
 
 
 
move  the  cursor  left  one  character;
 
 
 
move  the  cursor  right  one  character;
 
 
 
move  the  cursor  down  a  line.
 
Control  characters  can  all  be  accessed  by  using  the  ‘
ctrl
’  key  on  the  
keyboard,  for  example  
ctrl  

 M
 is  the  same  as  pressing  the  ‘
return
’  
key.
 
Notice  that  the  ASCII  code  is  very  useful  for  exchanging  data  
-­‐
 
provided  you  use  American  English.    It  was  never  designed  for  any  
other  language.
 
Notice  also,  that  the  eighth  bit  in  the  code  is  always  0,  so  only  128  
codes  are  actually  defined.
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
21
 
Computer  manufacturers  have  taken  advantage  of  this  fact  and  
used  all  256  of  the  codes.  
 
Every  group  of  these  256  characters  is  called  its  
character  set
.    
There  are  thousands  of  such  character  sets,  each  one  different  from  
the  others.
 
The  128  extra  codes
 are  used  for  storing  characters  that  ‘foreign’  
languages  might  use  such  as  å;  ç;  é;  π;  ß;  etc.,  or  symbols  £,  ©;  ¥  etc.
 
These  extra  codes  are  not  fixed,  so  every  manufacturer  uses  them  
for  different  characters.    
 
The  ‘
Alt
’  key  is  used  to  access  these  addi
tional  characters.    
However,  you  must  know  which  combination  of  keys  produces  
which  characters.  This  becomes  very  confusing  because  the  
combination  is  different  for  every  character  set  used!
 
Note:  in  UTF
-­‐
8  these  extra  128  characters  are  fixed
 amongst  all  t
he  
manufacturers
 which  makes  much  more  sense
 and  makes  writing  
applications  that  depend  on  
the  extra  characters
 much  easier.
 
IN  ASCII,  (and  UTF8)  each  character,  printing  and  non
-­‐
printing  is  
stored  in  1  byte.
 
256  codes  are  not  really  enough,  so  the  major  m
anufacturers  have  
developed  a  single,  super  set  of  characters  called  ‘
Unicode
’,  which  
includes  most  current  written  languages  and  most  often  used  
graphic  characters  (up  to  65,536  characters!).    Two  bytes  are  used  
to  store  each  character  when  Unicode  is  use
d.
 
All  modern  operating  systems,  such  as  Windows,  Mac  OS,  
IOS,  
Android,  Linux,  
Unix,  
etc  now  use  Unicode  characters.
 
22
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
Exercise 19
 
Answer  each  question  o
n  the  
line
 that  follows  it.
 
1.
 
How  is  each  character  in  a  text  message  stored  in  a  computer’s  
main  
memory?
 
 
2.
 
What  does  ASCII  stand  for?
 
 
3.
 
Use  the  table  to  write  your  first  name  in  ASCII.
 
 
4.
 
What  other  use  is  made  of  ASCII?
 
 
5.
 
Give  two  examples  of  non
-­‐
printing  codes.
 
 
6.
 
What  is  the  disadvantage  of  ASCII?
 
 
7.
 
What  is  Unicode?
 
 
 
8.
 
What  is  the  disadvantage  of  Unicode  
compared  to
 ASCII?
 
 
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
23
 
5.
 
Storing  black  and  white  bit
-­‐
mapped  graphics
 
The  picture  you  see  on  the  computer  screen  is  made  up  of  

pixels
’  or  
picture  elements
.    These  pixels  are  also  
represented  inside  the  computer  as  
binary  numbers.
 
In  a  simple  ‘black  and  white’  
(or  monochrome)  
display,  each  
pixel  is  represented  by  one  bit:
 
 
 
a  ‘1’  turns  the  pixel  ‘on’  making  it  white
 
 
a  ‘0’  turns  the  pixel  ‘off’  making  it  black
 
A  special  section  of  memory  called  the  ‘screen’  memory  or
 
‘video’  memory  holds  the  pattern  of  1’s  and  0’s  that  make  up  
the  picture.
 
 
For  example:
 
 
 
 
 
 
 
On  the  monitor  
you  see
 
While  in  the  memory  
you  have
 
0000000000000000000000000000
 
0010001110001100011100111100
 
0101001001010010010010100000
 
0111001110010000010010110000
 
010
1001001010010010010100000
 
0101001110001100011100111100
 
0000000000000000000000000000
 
24
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
Graphics or pictures are also represented this way, for
example:







It should be obvious that the bigger the image, the greater the
amount of memory needed to store it.

If a colour
image has to be stored then each pixel is stored as a
number (in binary) that represents the colour the pixel is to
show.

Colour photographs typically use 24 bits (or 3 bytes) to store
each pixel,
which is why colour
pictures tend to take up a lot
of memory to display them on the screen. (You will learn
more about dealing with colour images in the Information
Systems Design and Development Unit).

11111111111111111111111111111111
 
11111111100011111111111111111111
 
11111111111011111111111111111111
 
11111111100000111111111111111111
 
11111111101110111111111111111111
 
11111111100000111111111111111111
 
11000000000000000000000000000111
 
10000001100001100001100001100001
 
11000000000000000000000000000111
 
11111111111111111111111111111111
 
On  the  monitor  
you  see
 
While  in  the  memory  
you  have
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
25
 
6.
 
Storing  vector  graphics
 
Storing  graphics  pixel  by  pixel
 works  great  for  photographs,  
but  it  is  terrible  for  ‘technical’  drawings  like  plans.  
 
Drawings  are  made  up  of  a  collection  of  different  shapes  
-­‐
 
lines,  rectangles,  circles,  etc.  This  is  called  a  
vector  graphic
.
 

 
 
 
 
 
 
Instead  of  storing  the  finished  drawing,  the  computer  stores  
the  
instructions
 that  describe  how  to  draw  the  vector  graphic...
 
 
Triangle(100,100;  200,0;  300,100;  red)
 
 
Rectangle(100,100;  300,100;  300,200;  100,200;  blue)
 
If  any  object  in  a  vector  graphic  has
 to  be  moved,  only  its  
description  needs  to  be  changed.  Similarly  to  change  an  
obj
e
ct’s  
colour,  only  its  description  needs  to  be  changed.  By  
changing  the  order  of  the  instructions,  objects  can  be  moved  in  
front  of,  or  behind  other  objects.
 
26
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
NOTE:  the  instr
uctions  that  make  up  a  vector  graphic  are  still  stored  in  
the  computer’s  memory  in  
binary
!
 

Exercise
20

Answer  e
ach  of  the  following  questions  o
n  the  
line
 that  follows  it.
 
1.

How  are  black  and  white  images  stored  in  a  computer’s  main  
memory?
 
 
2.

How  many  bits  are  used  to  store  each  pixel  in  a  colour  
photograph?
 
 
3.

What  are  drawings  like  plans  made  up  of?
 
 
4.

What  would  need  to  be  changed  to  make  a  square  object  in  a  
vector  graphic  into  a  rectangular  object?
 
 
5.

What  would  need  to  be  changed  to  make  a  circ
ular  object  in  a  
vector  graphic  bigger?
 
 
6.

What  would  need  to  be  changed  to  make  a  red  object  into  a  yellow  
object?
 
 
7.

How  are  the  instructions  that  make  up  a  vector  graphic  stored  in  a  
computer’s  memory
 
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
27
 
7.
 
Storing  Programs  in  main  memory
 
 
Not  only  is  all  
data  stored  in  the  computer’s  main  memory  as  
binary,  but  the  programs  must  be  stored  as  binary  as  well.
 
 
Fortunately  the  Central  Processing  Unit  (CPU)  can  only  deal  with  
very  simple  instructions  such  as:  
 
 


LOAD  data  from  the  memory  to  the  processor
 
 


ADD  
the  next  byte  in  memory  to  the  byte  held  in  the  processor
 
 


STORE  the  result  back  in  memory.
 
 
 
However,  processors  do  not  actually  understand  ‘human’  
commands  like  LOAD  and  STORE.    All  the  processor  understands  
are  patterns  of  bits  (1s  and  0s)
 
 
For  example:
 
 
 
 
10010111
 
might  mean  LOAD
 
 
 
10011001  
 
might  mean  ADD
 
 
 
10011010
 
might  mean  STORE.
 
 
The
 pattern  of  bits  that  the  processor  understands  as  instructions  
is  called  its  
machine  code
.
 
28
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
Unfortunately,  every  make  and  model  of  processor  understands  
different  patterns  of  bits  
-­‐
 so  one  set  of  bits  for  one  processor  might  
mean  ADD,  while  for  another  the  same  set  of  bits  might  mean  
STORE!  
 
 
Therefore  the  machine  code  for  one  processor  will  rare
ly  work  
with  another  processor.
 
 
 
Exercis
e  21
 
Answer  each  of  the  questions  o
n  the  
lines  that  follow  
them
.
 
1.

What  is  machine  code?
 
 
 
2.

How  is  machine  code  stored  in  a  computer’s  main  memory?
 
 
 
3.

Why  will  machine  code  written  for  one  computer  rarely  work  on  
another  one?
 
 
 
4.

Why  then  will  machine  code  for  an  Intel  i3  run  on  an  Intel  i5?
 
 
 
5.

Why  might  machine  code  for  an  Intel  i3  not  run  on  an  ARM  
processor?
 
 
 
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
29
 
When  you  have  been  writing  your  programs,  you  either  used  
graphical  building  blocks  and  wrappers  or  you  
entered  your  
program  as  text.
 
Both
 are  examples  of  ‘High  Level  
Programming  
Languages’  and  
their  
programs  must  be  translated  into  binary
 machine  code
 before  
they  can  be  executed.
 
Some  
translators
 (called  
compilers
)  convert  all  of  the  high  level  
program  code
 into  binary  and  store  it  as  a  separate  binary  

executable
’  file  before  any  of  the  code  is  executed.  This  is  how  
commercial  programs  are  produced.  When  you  buy  a  game  or  a  
music  program,  you  are  buying  a  copy  of  the  binary  executable  file.  
 
A  
compiler
 work
s  like  this:
 
1.

Translate  all  of  the  source  code  into  machine  code
 
2.

Save  the  machine  code  as  a  separate  file
 
3.

Run  the  separate  machine  code  file.
 
You  should  note  that…
 


Once  compiled,  the  machine  code  file  can  be  used  without  the  
original  code  in  the  High  Level  Programming  Language,  its  
editor  
or
 the  compiler.  
 


When  it  runs,  none  of  these  are  required  anymore  so  
executable  binary  files  allow  the  application  to  run  at  its  
maximum  speed.
 
 


It  also  means  that  users  can’t  change  the  applications  by  
accident  or  on  purpose!
 
 
30
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
Other  translators  (called  
interpreters
)  onl
y  convert  a  single  line  of  
the  High  Level  P
rogram  code  into  binary  just  before  it  has  to  be  
executed.  The  binary  code  it  produces  is  never  stored,  so  each  time  
the  program  line  has  to  be  executed  again,  it  must  be  translated  
again.  This  constant  translation  considerably  slows  down  the  speed  
of  a  pr
ogram.  However,  they  are  useful  when  developin
g
 new  
applicati
ons
 as  some  errors  are  much  easier  to  find  with  
interpreted  programs  than  with  compiled  programs.
 
An  
interpreter
 works  like  this:
 
1.

Fetch  the  next  line  of  source  code
 
2.

Translate  it  into  machine
 code
 
3.

Is  it  the  halt  instruction?
 
3.1

No!
 
 
i.

execute  the  code
 
ii.

throw  it  away
 
iii.

return  to  the  step  1
 
3.2
 
Yes!
 
i.
 
Stop.
 
You  should  note  that…
 


A  
program  written  with  a  High  Level  Programming  Language  
that  must  be  
interpreted  to  run,  
must  also  have  the  original  
code  in
 the  High  Level  Programmi
ng  Lan
guage,  
its  editor  and  
the  interpreter  on  their  computer!
 
 


The  user  can  change  applications  that  depend  on  an  
interpreter  to  run.
Pupil  Notes  ©  
E  Forrester
 2012,  distributed  by  AOK  Learning
 
31
 
There  are  thousands  of  High  Level  Programming  Languages  
available  for  the  programmer  to  choose  from,  each  with  its  
own  advantages  and  disadvantages.  
 
Some  examples  of  commonly  used  High  Level  Programming  
Languages  that  you  might  come  across  or  use  are...
 
B
ASIC  (lots  of  variations  avail
a
ble:  
MicroSoft  Visual  Basic,  
TrueBASIC,  REAL  Basic,  TinyBASIC,  SmallBASIC  etc.)
 
C  (lots  of  variations  as  well.  e.g  C,  C
++
,  C
#
,  Objective  C,  etc.)
 
Java
 
Python
 
ADA
 
LiveCode
 
You  may  also  see  programming  languages  that  have  been  
developed  for  use  with  the  World  Wide  Web  such  as...
 
Perl,  Caml,  JavaScript
,  php
.
 
Other  languages  have  been  developed  for  printing...
 
PostScript.
 
Some  have  even  been  developed  to  make  programming  easier...
 
Scratch,  AppInventor,  StencylWorks,  Kodu  Game  Lab
 
As  technology  changes  the  programming  languages  change  as  well  
to  keep  them  up  to  date  and  new  languages  are  invented.
 
32
 
National  4  and  5  Computing  Science  

 
Software  Design  
and  Development
 

 Part  5
 
Exercise  22
 
 
Answer  each  of  the  questions  on  the  lines  that  follow  them.
 
 
1.
 
Why  must  High  Level  Languages  be  translated  into  machine  co
de  
before  their  instructions  can  be  carried  out?
 
 
 
2.
 
What  part  of  the  software  development  environment  is  responsible  
for  converting  
a  High  Level  Language  into  machine  code?
 
 
3.
 
Briefly  describe  how  a  Compiler  works.
 
 
 
 
 
 
4.
 
List  three  differences  between
 how  a  Compiler  and  an  Interpreter  
convert  High  Level  Languages  into  machine  code.
 
 
 
 
5.
 
How  can  you  tell  if  the  programming  language  that  you  are  using  is  
a  Compiler  or  an  Interpreter?