18
St. Benedict’s High School Computing Science Software Design & Development (Part 2 – Computer Architecture) National 5

Nat 5 SDD Notes - Part 2 Computer Architecturecomputing.homedns.org/Downloads/Course Notes/N5/Nat 5 SDD...Something to know about storing numbers on a computer is that a fixed number

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

St. Benedict’s High School

Computing Science

Software Design & Development

(Part 2 – Computer Architecture)

National 5

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

2 St.  Benedict’s  High  School

DATA REPRESENTATION

Numbers

Binary/Decimal Conversion Example To convert 69 into binary: write down the binary place value headings, then work out which headings add up to 69:

128 64 32 16 8 4 2 1

0 1 0 0 0 1 0 1

01000101 = (1 * 64 ) + (1*4) + (1*1) = 64 + 4 + 1 = 69 Using this method it is just as easy to convert from binary back to decimal as shown above. More examples

128 64 32 16 8 4 2 1 0 0 0 0 0 1 0 1 5

0 0 1 0 0 0 0 0 32

0 1 0 0 1 1 0 1 13

1 0 0 0 1 1 0 0 140

1 1 1 1 1 1 1 1 255

Something to know about storing numbers on a computer is that a fixed number of bits is always used. For simplicity our examples will always use just 8 bits as above. However, let’s say a computer uses 32 bits to store numbers, then

3 would be stored as: 00000000000000000000000000000011 324 564 046 stored as: 00010011010110000111010001001110

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

3 St.  Benedict’s  High  School

Floating Point Representation Real numbers and very large numbers are stored in the computer as floating point numbers. This is like the standard form or scientific notation used in maths except the computer does not store the point or the base. Decimal Example

93 000 000 in Standard Form: 9.3 x 107 93 000 000 in Floating Point: 93 8 The 93 is called the MANTISSA The 6 is called the EXPONENT So, in decimal… Mantissa x 10 Exponent

However, computers use binary, and in binary we express the exponent as a power of 2, so every binary floating point number is of the form:

Mantissa x 2 Exponent More about the mantissa and exponent... Computers use a fixed number of bits to store floating point numbers. For instance with 32 bits they might use 24 bits for the mantissa and 8 bits for the exponent. Or they could use 20 bits for the mantissa and 12 bits for the exponent. This has an effect on the ACCURACY of the numbers stored and the RANGE of values that can be stored.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

4 St.  Benedict’s  High  School

9 3 8

1 2 9 8

(Decimal examples) With our numbers imagine we have a calculator that can only display 3 digits for the mantissa and 1 digit for the exponent: With our numbers imagine we have a calculator that can only display 3 digits for the mantissa and 1 digit for the exponent: E 93 000 000 would be stored: 12 875 000 would be stored: Note the loss of accuracy. 2 340 000 000 cannot be stored at all. The point moves 10 places and this is out of our range. So the exponent determines the range of numbers that can be stored in floating point. Binary example The binary number 1101.0011011101 The decimal point cannot be stored so it is moved 4 places to the LEFT. So the number in floating point from will be : .11010011011101 x 2 4

which in binary, is .11010011011101 x 2 100

In this case the mantissa is 11010011011101

and the exponent is 100 .

Range & accuracy Increasing the length of the mantissa increases the accuracy of the number stored. Increasing the length of the exponent increases the range of numbers stored.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

5 St.  Benedict’s  High  School

Text

Representation of Characters. Input, output, backing storage and data communications devices store and manipulate data in character code. During processing, text data stays as character code but numerical data is converted to binary patterns following the convention already discussed. Programmers specify the type of data within their code and conversion is then carried out by hardware or software. The characters that can be represented by the computer is known as the character set. Many computers have the flexibility of using several character sets, but we will restrict our discussions to ASCII and Unicode.

ASCII American Standard Code for Information Interchange (ASCII) was first developed for teletypewriters and is now an internationally agreed standard for storing information. It is a character set which forms the basis for almost all other character sets. ASCII uses 7 bits per character, giving a possible 128 different characters (27 = 128). It has 96 displayable characters, enough to represent a letter or symbol of the English alphabet and numerical symbols. There are 32 special character codes known as control characters. A single code is used to represent each character which is stored in binary. When data is to be displayed or printed, the code is converted into an appropriate shape. The 7-bit table of ASCII codes is shown below.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

6 St.  Benedict’s  High  School

The Control Characters The first 32 ASCII values are non-printing control characters, such as Return and Line feed. You generate these characters on the keyboard by holding down the Control key while you strike another key. When IBM PCs were designed, they moved and stored data in 8-bit units. The extra bit increased the character set from 128 to 256 (28 = 256), producing an extended character set that could accommodate international dialects or alphabetic characters in foreign languages (French and German accented characters are examples).

Unicode An increase in worldwide communications brought a need to exchange information internationally. This presented a problem for Latin based character sets. Languages such as Japanese and Arabic, for example, do not use the Latin-based symbols of English, French or German and have entirely different symbol shapes. A Japanese symbol is shown. A solution to the problem of supporting multilingual text was to encode characters using 16 bits, thus providing 65,536 possible symbols (216 = 65,536). This is Unicode which is capable of including the characters from all known languages and alphabets in the world.

SUMMARY

• ASCII codes can be stored in using 7 or 8 bits per character and therefore requires less storage than Unicode.

• Unicode uses 16 bits per character and can therefore represent more characters than ASCII. Unfortuantely this requires more storage than ASCII.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

7 St.  Benedict’s  High  School

Graphics

Bit-mapped graphics For a graphic drawn in a painting type package, the computer stores the necessary information as a two dimensional array of pixels. In black & white images, each pixel is represented by one bit. For example,

Once drawn, each individual pixel can still be edited. Another example of storing a bit-mapped image:

This is a graphic of a flower. In a painting type program it is viewed by the computer as a bit pattern. Because EVERY pixel is stored, bit-mapped graphics require a large amount of storage.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

8 St.  Benedict’s  High  School

Using colour and bit-mapped graphics. The value of each pixel (whether it is filled in or not) is stored in one or more bits of data. For simple black & white images, one bit is sufficient to represent each pixel, but for colours, each pixel requires more than one bit of data. The more bits used to represent a pixel, the more colours that can be represented. The table below shows the way in which 2 bits can be used to store 4 different colours.

Bit Pattern Colour No of Bits

00 Black 2

01 White 2

10 Red 2

11 Yellow 2

Two Red pixels would therefore take 4 bits of storage. Table showing number of bits and corresponding number of colours represented:

No of bits per pixel No. of colours

1 2 (Black & white)

2 4

3 8

4 16

5 32

6 64

7 128

8 256

16 65536

24 16,777,216 (True Colour)

So, 2 no. of bits = no. of colours available.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

9 St.  Benedict’s  High  School

Advantages of bit-mapped graphic representation

• a bit mapped image can be edited at the pixel level. Thus a designer may apply particular colour values to a selected pixel area to produce shading or textured effects

• it is possible to create a wider range of irregular shapes and patterns by simply deleting or

editing pixels anywhere on the image Disadvantages of bit-mapped representation

• requires large amounts of storage space

• image becomes course (jagged) when scaled Resolution The density of the pixels, known as the resolution, determines how sharply the image is represented. This is often expressed in dots per inch (dpi ). A picture at 300dpi contains much more detail than a picture at 72dpi.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

10 St.  Benedict’s  High  School

Vector Graphics With vector graphics, images are stored as a series of attributes i.e. a description of how it is drawn. Any editing is done at the level of attributes. Editing an individual pixel is not possible. Examples

Rectangle

Start x,y position Length, breadth and angle of rotation Thickness & colour of line Colour fill etc.

Circle Centre x,y position Radius Thickness & colour of line Colour fill etc.

Advantages of vector graphic representation

• as values are not held for every pixel, less storage space required than a bit mapped image

• they do not lose their image quality on scaling - object attributes are simply recalculated Disadvantages of vector graphic representation

• individual pixels cannot be edited.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

11 St.  Benedict’s  High  School

Storage Requirements Calculating Storage Requirements - SCREEN You can calculate the storage requirements for a screen or a graphic on the screen using the formula:

No. of BITS required = Pixels across x Pixels down x bit depth Example 1: A 1280 by 800 screen using 8 bit colour depth needs:

1280 x 800 x 8 BITS = 8192000 bits /8 = 1024000 bytes /1024 = 1000 Kbytes

Example 2: Calculate the storage required for a screen using 1620 by 1280 pixels with 65 536 colours.

Bits = 1620 x 1280 x 16 (because 216 = 65 536) = 33177600 bits /8 = 4147200 bytes /1024 = 4050 Kbytes /1024 = 3.96 Mbytes

Note how the number of bits per pixel increases the file size. 24 bit colour produces a file 3 times larger than 8 bit colour.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

12 St.  Benedict’s  High  School

Calculating Storage Requirements – BIT-MAPPED FILE You can also calculate the storage requirements for a bit-mapped graphics file. The idea is basically the same as before but it takes a little longer to get there. As before we need to identify the number of pixels required and the bit-depth (no. of colours used). Calculating the storage requirements of a file requires a little extra detective work! Example:

This picture measures 2 inches by 3 inches, contains a possible 256 colours and was scanned at 72 dpi. First we have to work out the number of pixels: 2 inches x 3 inches at 72 d.p.i (dots per inch) = (2 x 72) x (3 x 72) = 31104 pixels Next, the bit depth: Bit depth = 8 (because 28 = 256)

So, our storage requirement is 31104 pixels at 8 bits each

31104 x 8 = 248832 bits /8 = 31104 bytes /1024 = 30.375 Kbytes

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

13 St.  Benedict’s  High  School

TRANSLATORS

Need for Translators High Level Languages Computers only understand binary. Unfortunately, humans are not so good at understanding this and so humans program computers in high level languages. High level languages use normal mathematical notation and English words to create instructions. Visual Basic is an example of a high level language. Because high level languages use English-like words programs are easy to write and edit. A translator is a special program that converts a program from a high-level language into machine code. The high-level program is called the source code. This is often created using a text editor. The translator turns this into object code which is usually the machine code (binary) of the computer being used. Translators can normally be put into two groups – compilers and interpreters.

Interpreters v Compilers Interpreter An interpreter translates and executes a program one statement at a time. Advantages

• When syntax errors are made by the user, they are highlighted immediately. • Speeds up the software development process

Disadvantages

• Interpreted programs are slow to run • Every time the program is run, each line of code must be translated again. • Statements inside a loop have to be translated every time round the loop.

The interpreter must also be in memory as the program is running. Thus the RAM demands of an interpreted program are greater.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

14 St.  Benedict’s  High  School

Compiler A compiler is a program that translates your entire high-level source program into your computer’s machine code. It produces a machine code program that is saved to disk and which can be executed by itself. This version of the program is known as object code. The source code will only be used again if the program needs to be updated or bugs fixed. Should this happen, an updated version of the object code is produced by using the compiler again. Advantages

• A compiled program runs faster than an interpreted program as the whole source is translated to machine code.

• The compiler only needs to be in memory while translation is taking place - more economic memory usage than interpreter

Disadvantage

• Syntax errors in the source code are only identified when the program is compiled.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

15 St.  Benedict’s  High  School

COMPUTER ARCHITECTURE

The Processor The "very fast idiot" The processor is the "brain" of the computer system. It does all the hard work and calculations etc. It can do billions of these calucaltions per second! A computer is able to process huge amounts of data (number crunching) very fast, but it can't think for itself - it can only do what we tell it to do. There is a saying in Computer Science: "Garbage in, garbage out!" Inside The Processor The processor is made up of a number of very important parts as follows: The Control Unit This is the nerve centre of the computer. It controls the sequencing of all operations both within the CPU and in connection with INPUT, OUTPUT and BACKING STORAGE devices. The ALU (Arithmetic & Logic Unit) The two main functions of the ALU are:

1. To carry out the arithmetic required by the system (ADD, SUBTRACT, DIVIDE and so on).

2. To perform certain 'logical operations'. e.g. To test if one data item is larger than another

and then to perform some action depending on the result of this test. Registers Registers are temporary memory locations within the processor itself used to hold data being processed. Because they are inside the processor, they are very fast to access.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

16 St.  Benedict’s  High  School

Memory There are two types of memory: RAM and ROM. Random Access Memory (RAM)

• RAM is for storing user's programs and data while they work.

• The contents of RAM are temporary - it's

contents may be changed.

• The contents of RAM are lost when the computer is switched off.

• Adding more RAM allows the user to run programs at the same time without slowing the machine down.

Read Only Memory (ROM)

• The contents of ROM are permanent - it's contents cannot be changed.

• The contents of ROM are not lost when the computer is switched off.

• Data stored in ROM loads much faster than RAM.

Memory Addresses When the processor fetches instructions and data from the memory it must know where to find them. In a single RAM module there may be millions of memory locations each one containing a program instruction or item of data. In order to find each memory location they are all numbered. Each memory location has it's own unique address. The processor uses the addresses to select the location which contains the program instruction or data to process next. The concept of memory locations, each with its own unique address is called addressability.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

17 St.  Benedict’s  High  School

Buses Moving Data Between Processor and Memory Data and instructions have to be transferred backwards and forwards between memory and the processor and this is done by buses. A bus is an electronic highway used to transmit binary patterns. There are three buses:

• the address bus which is used by the processor to pinpoint the memory location needed. This is a one-way (uni-directional) bus.

• the data bus which is used to transfer the data. It's size will usually match the word size i.e.

the size of the memory locations. This is a two-way (bi-directional) bus.

• the control bus which is used to initiate and control what is happening.

Memory Read

1. The address bus is used to select the address of the desired memory location.

2. The control bus sends a signal to activate the transfer.

3. The data in the selected location is sent along the data bus to the processor. Memory Write

1. The address bus is used to select the desired memory location.

2. The control bus sends a signal to activate the transfer.

3. The data is sent along the data bus to the selected memory location.

 Software  Design  &  Development  Pt2  –  Computer  Systems    

     

18 St.  Benedict’s  High  School

Interfaces Data exchange with peripherals So far we have looked at the internal parts of a typical computer system. But what about the peripheral devices we connect our computers to? How do these extra pieces of hardware connect to our systems? Peripheral devices connect to computer systems via slots on the back of the computer. Such devices include printers, scanners, digital cameras, digital video recorders, mice, keyboards, mp3 players etc. They also include storage devices such as disk drives. Each device has its own operational speed, uses its own language and deals with different amounts of data at a time.

Interfaces In order for peripheral devices to communicate with the CPU they need to be ‘interfaced’. An interface is a unit that sits between the CPU and a peripheral device and compensates for the differences in speed, codes and other characteristics, to ensure compatibility. Basic functions of an interface

• Control Signals. Transmit and receive signals to/from the CPU in order to synchronise the movement of data in an organised manner.

• Input/Output. Transfer data between the computer itself and the external device.

• Data Conversion. Convert data to/from the format understood by the peripheral to the

format understood by the processor. The main task of an interface is to transfer data so that the processor is delayed as little as possible and therefore system performance does not suffer unnecessarily.