Presentation is loading. Please wait.

Presentation is loading. Please wait.

M150: Data, Computing and Information

Similar presentations


Presentation on theme: "M150: Data, Computing and Information"— Presentation transcript:

1 M150: Data, Computing and Information
Unit Six: The structure of hardware and software

2 1- Introduction The aims of this unit are:
Draw a distinction between hardware, software and firmware, and describe the computer as a system Describe the functions of the different components of a computer Explore the way in which different parts of a computer work together to translate and execute the instructions given in the form of a computer program Discuss some of the properties of the different types of programming languages in which computer programs may be written. Introduce you to the ways in which computer programs can be structured to control the order in which instructions in the program are executed Introduce you to a number of important developments in the history of computers and computing through ‘History snippets’ 2

3 2- Hardware, software and computer systems
A computer program: is a sequence of instructions for performing a certain task on a computer Hardware vs. Software Computer Hardware and Software components work together in order to execute computer program Hardware consists of the tangible parts of the computer system – ‘physical parts that can be touched’. Examples of hardware include the electronic circuits, the keyboard and hard disk. Software consists of sets of instructions that tell a computer how to perform a particular task. Examples of software are Microsoft Word, Explorer or Netscape. The terms software and computer program are often used synonymously, though it could be argued that software is generally made up of a number of programs. 3

4 2- Hardware, software and computer systems
Although software and hardware are very different in nature, they are also inextricably related. Any instruction performed by software can also be built directly into hardware, and instructions executed by hardware can often be simulated in software Example: multiplication of two numbers. One way of thinking about multiplication is to consider it as a number of additions (using electronic circuit or simple arithmetic instruction – ADD) It is possible to perform division by means of repeated subtraction, though the process is a little more complex than for multiplication The decision to implement some functions in hardware and others in software is based on factors such as speed, cost and reliability. 4

5 2- Hardware, software and computer systems
A book could be thought of as being made of paper and ink (analogous to hardware), or it could be thought of as being a collection of words and sentences (analogous to software). A CD-ROM is a piece of hardware. It is tangible (it can be picked up and held). The computer applications, programs or files that are stored on the CD-ROM are examples of software. They are sets of instructions that the computer can understand Firmware is refer to a sequence of instructions (software) etched into the read-only memory (ROM) of the computer, usually to perform some system function. Because these instructions are on a chip they form a permanent part of the computer and could be viewed as a combination of hardware and software

6 2- Hardware, software and computer systems
The computer as a system Information system is a machine that can solve problems by carrying out a sequence of instructions, usually on a given set of data (input). The solution produced is referred to as the output A computer is a device that accepts data and manipulates it by carrying out a sequence of instructions (a program), so as to produce some output. A computer also has the means of storing the input, the output and the program. 6

7 2- Hardware, software and computer systems
Input, output and instructions The input to a computer process can be words or numbers entered from a keyboard, Images or sound. Sometimes data will already be available in the computer as a file, in which case the input might be via mouse clicks or some other input device. All data, including the instructions that make up a computer program, are stored in the computer as binary digits (bits) – sequences of zeros and ones Binary logic (Boolean algebra) defines the rules governing the manipulation of entities with only two states, such as bits, In order to make the results readable by humans, the binary representations of the output need to be ‘translated’ back into an appropriate format. 7

8 3- The resources of a computer, and how they are managed
The heart of the computer – the central processing unit (CPU) – Processor The processor of a PC is usually on a single microchip, (or microprocessor) which contain several tens of millions of circuits. Consists of the ALU and the control unit along with their registers An arithmetic/logic unit (ALU): is the component of the computer in which the manipulation of binary data takes place (calculations and logical operations are performed) It contains a number of registers where data is held directly prior to and following processing. The ALU can add, subtract, multiply, divide compare (>,<,=,>=,<=,<>) and combine two values (And, Or, Not) Control unit: coordinated the movement of data (data flow) between the ALU and other parts of the computer through sending and receiving of control signals 8

9 3- The resources of a computer, and how they are managed
Registers: Are small numbers of memory locations which are used to hold single pieces of data or single instructions immediately before and after processing. There are different types of register, some located in the ALU, some in the control unit (each designed to hold a particular type of information) Individual pieces of data and instructions are moved from main memory into the registers. The registers are built from more efficient (and expensive) memory than main memory, thus allowing fast access and transfer of data. Processors come in ‘families’, such as the Pentium 4, Celeron, AMD Athlon XP. Each family of processors has what is termed an instruction set. This is the collection of basic instructions, called machine language instructions, which a particular processor understands 9

10 3- The resources of a computer, and how they are managed
Architecture for a computer: is the CPU together with the way in which memory, internal communications and input/output are organized Data may be transferred to and from main memory via disk storage rather than directly from and to input and output devices. 10

11 3- The resources of a computer, and how they are managed
Control Unit Is responsible for interpreting the instructions in a computer program and then sending appropriate control signals to the components that will carry them out. As soon as one instruction has been executed, the control unit moves on to deal with the next. Once processing of a program has started, there is no need for human intervention unless some interactive input is required. The control unit is in two-way communication with all the other devices in the system so that it may, for example, receive a mouse click, and then send a control signal to another device in order to execute an instruction. Typical desktop PC is likely to have about 256MB of main memory (RAM), but may have a 60GB hard disk. 11

12 3- The resources of a computer, and how they are managed
There are different types of memory (or data storage): Main memory (RAM): is used to store a program of instructions and the data needed by the program while it is running. Its contents are volatile (lost when the computer is switched off) Main memory is a large collection of sequentially ordered pigeon-holes, each of which can hold the same number of bits, equivalent to the word size of the computer. Read-Only memory (ROM) : the data in ROM is built into the memory chips during manufacture and is permanent (nonvolatile) It cannot be overwritten. It stores program called a boot program File storage memory, such as that provided by a hard disk: is memory that is used to store large amounts of data for use at some later date. It is non-volatile (the data is persistent – it is not lost when the computer is turned off). 12

13 3- The resources of a computer, and how they are managed
The word size refers to the number of bits that the CPU can manipulate at one time. It is determined by the size of the registers in the CPU and the number of bits that can be moved round the computer as a single unit. When people refer to computers as being ‘32-bit’ or ‘64-bit (8 byte)’ machines they are referring to word size. The addressable nature of main memory (random access memory -RAM) makes the retrieval of data much faster than if there was a need to search sequentially. Random access means that each memory location takes the same amount of time to access, regardless of its address. If the your computer has 128 KB of RAM with word size of 64 bits: Number of bytes is = 128 x 1024 = 131,072 bytes Number of words is = 131,072 / 8 = 16,384 since 64-bit word is equivalent to 8 byte 13

14 3- The resources of a computer, and how they are managed
Peripheral devices Is computer device that is not part of the essential computer (CPU and RAM) such as input and output devices, and storage devices. Some peripherals are usually mounted in the same case as the processor such as hard disks – (Storage device) Other peripherals are mounted physically outside the computer, and communicate with it via a wired or wireless connection, such as printer, monitor, speakers-(Output device), keyboard, mouse, scanner, microphone - (Input device) Most computers come with facilities to allow for future expansion by providing internal bays (can only be accessed by opening up the case) and external bays (can be accessed without opening the case) to facilitate fitting additional internal storage devices such as hard disks, zip drives or CD-ROM drives. PCs also have a number of external ports – connection points on the side of the computer’s case PCs usually have a number of expansion slots. 14

15 3- The resources of a computer, and how they are managed
The operating system It manages the processor, memory and peripheral devices to effectively coordinate and carry out all the computer’s tasks Common operating systems: Linux, Mac OS (for the Apple Macintosh) and the various versions of Windows, e.g. Windows 2000 and Windows XP. Operating system is a complex piece of software that acts as an interface between the user (or an application program) and the computer hardware. It essentially enables the user to carry out a variety of complex tasks on the computer, without the need to know about what goes on ‘inside the box’ Mainframes and minicomputers have powerful OS, including virtual memory, multiprogramming and multiprocessing, where many users can run different programs at the same time. Microcomputer OS focus on a single user. 15

16 3- The resources of a computer, and how they are managed
The functions of the Operating system include the following: Provision of user interface The user interface is the software that enables us to communicate with our computers. It provides us with a means of inputting data and instructions, and presents output The user interfaces of Dos were text based, but of the Microsoft window provides graphical user interface (GUI). Management of the memory Allocate an appropriately sized area of memory to each process, and to ensure that program instructions and data do not interfere with each other or with the data and instructions of other programs Coordination and control of peripheral devices. Coordinates all operations (input from keyboard and mouse..), ensuring that data is moved safely and efficiently between the components of the system 16

17 3- The resources of a computer, and how they are managed
Scheduling access for the processor Manages access to the processor, by prioritizing jobs to be run and ensuring that the processor is not idle Providing an Interface between application programs and the Hardware The operating system ensures that a ‘standard’ way of interacting with the hardware exists, and application programmers can then rely on this standard without worrying about the minutiae of the processor specifications Providing basic utilities Such as disk formatting facilities, file management systems and software installation wizard. Platform: the combination of a particular processor and a particular operating system 17

18 3- The resources of a computer, and how they are managed
Read-only memory (ROM) and bootstrapping When you switch on a computer, the first thing it needs to do is to load its operating system (which is stored on the hard disk) An important function of ROM is to store a program, called a boot program, which is automatically executed when the computer is first switched on. This small program will typically run a test of main memory and see what peripherals are connected to the system, before loading larger programs, such as the operating system. Bootstrapping is the process of to load a program 18

19 4- Running a program The fetch/ execute cycle
The steps carried out by the CPU in the execution of a computer program as follows: Get an instruction from the program; Find and transfer any data necessary to perform the instruction Carry out the instruction (which may involve saving a result for later use). The process of locating, transferring and carrying out a single instruction during execution is called fetch/execute cycle. 19

20 4- Running a program During each cycle the CPU must:
Locate the next (or if the execution has just started, the first) instruction in the program which is stored in main memory Transfer this instruction in to the processor by placing it into an appropriate register. Decode the instruction to see what it is to do. Locate (in main memory) any data the instruction refers to, and fetch it into processor by placing it into an appropriate register Do the processing on the data that the instruction requires. Place the result in an appropriate register. If necessary move the result back to the main memory to be used later. Update the program counter to hold the memory address of the next instruction (Increment the program counter by 1). 20

21 4- Running a program Buses
An electronic channel through which data and instructions travel between different components of the computer At least three categories of bus are needed to ensure that the fetch/execute cycle operates effectively. The address bus is used to carry information about the addresses in main memory to be accessed. The data bus transmits the data; the external data bus transmits data between the registers and main memory, and the internal data bus transmits data between the different registers within the processor. The control bus carries control signals sent by the control unit, as well as signals that report the status of various devices. Bus technology is also important for transferring data between the CPU and the input and output devices. 21

22 4- Running a program Processor clock
To enable events to be synchronized by the control unit, The length of time between pulses is called clock cycle time. Each instruction took at least one clock cycle to execute but advanced processors can now execute more than one instruction in a single cycle. The number of pulses per second, or frequency, of the clock is measured in megahertz (MHz), so a processor with a 900MHz clock sends 900,000,000 pulses per second. Computer with a high clock frequency (sometimes called clock speed) can execute more instructions per second than one with a lower clock frequency 22

23 4- Running a program Simple computer program (written in assembly language) Each instruction comes in two parts: Operator: which identifies the instruction (LDA) Operand: which specifies a memory location (501) The memory locations contain binary representations of the data and the instructions Memory Location Instruction Comment 701 LDA 501 Load the content of memory location 501 into accumulator 702 ADD 502 Add to the accumulator the contents of memory location 502 (results in the accumulator holding the result of addition) 703 STO 503 Store the contents of the accumulator in memory location 503 704 HLT 000 End the program (halt) 501 2 502 3 503 ? 23

24 4- Running a program Registers Is very expensive but fastest access
Accumulator Used to store any intermediate values during a calculation Program counter (or next instruction pointer) Sometimes called the next instruction pointer (NIP), is located in the control unit and holds the memory address of the next instruction to be executed. In simple sequential program, this register is incremented by 1 each time an instruction is carried out Instruction register (IR) Located in the control unit, holds the instruction that is currently being executed. It is responsible for decoding the instruction (separating the instruction into its operator and operand, and interpreting the meaning of the operator) 24

25 4- Running a program Memory address register (MAR)
Holds the address of a main memory location that needs to be accessed. Memory data register (MDR) Is a temporary holding area for either data or instructions that are being transferred between main memory and the other registers. Status registers Hold information about the current status of an instruction. One use of a status register is to flag up or signal a problem. For example, the status register could contain a special code to indicate that the programmer has inadvertently tried to do something impossible, such as divide by zero. General-purpose registers are used for different purposes. 25

26 4- Running a program Storing and locating data and instructions in main memory The main memory consists of a number of addressable (uniquely identifiable) locations, each capable of holding a certain number of bits. The memory addresses are numeric and start with location 0 When the control unit needs to access a particular address it first sends a signal to store the address in the memory address register (MAR). The relevant memory location is then addressed directly, via the address bus, and its contents transmitted to or from the processor (in units of one word), using the external data bus. A computer with a large word size can process more data in each instruction cycle than a computer with a small word size. 26

27 4- Running a program Virtual memory
Computers tend to have lots of cheap, but slow hard disk storage memory and fast, but expensive register memory. Main memory can be supplemented by a technique whereby an area of the disk storage memory (hard disk) can be used to simulate additional capacity during processing. This technique is known as Virtual memory (increase the effective size of the main memory) The transfer of blocks of data (called pages) between the main memory and the hard disk is managed by the operating system. Data in virtual memory becomes inaccessible once the computer loses power because information on the location of the data on disk is held in main memory, it is lost once the computer loses power The usual size of the virtual memory is 1.5 times the amount of RAM. 27

28 4- Running a program Cache memory
Cache memory – faster than main memory, but slower than the registers. (intermediate in cost) Cache memory is ‘fed’ from main memory before the data is finally moved to the registers. When an instruction calls for data, the processor first checks to see if the required data is in the cache. If it is, it takes the data from the cache instead of fetching it from main memory. A typical PC will have several hundred kilobytes of cache memory 28

29 4- Running a program Program controlled input and output
The lower speed of input and output relative to data flow within the processor has slowed down the speed at which a computer can process data. A local input/output bus (I/O bus) is a high-speed bus that connects performance-critical devices, such as video cards, modems and network interface cards, to the main memory and the processor. The most common local I/O bus is the peripheral component interconnect bus (PCI). PCI technology allows the processor to be bypassed altogether when transferring data to and from main memory , resulting in very fast transfer speeds 29

30 5- Types of programming language
Low-level language: any computer programming language with one-to-one correspondence (including the machine language itself) High-level languages: programming languages in which one instruction may be equivalent to many machine language instructions such as JavaScript, Java, C++ and Smalltalk Low-Level languages Machine language Wrote instructions in a form that could be directly understood by the hardware (processor) Each instruction in machine language is a long stream of 1s and 0s Machine language programs are the ‘purest’ kind of program because the programmer is literally writing in the language of the processor without any intervening interpreters or translators (exploit the capabilities of the processor to the full). 30

31 5- Types of programming language
All programs, regardless of what language they are written in, must be translated into machine language before they can be executed Disadvantages to read and write programs in machine language Machine language programs are slow and difficult for humans to read and write (hard to memorize instruction codes) Memory references are given as actual location numbers (keep track of what has been stored where, and which locations are still available). It is difficult to understand machine language programs without a great deal of annotation (very difficult to modify). Each family of processors understands only its own machine language. The command to move data from the processor’s accumulator into main memory address is: 31

32 5- Types of programming language
Assembly language Is a language in which each instruction exactly corresponds to one hardware operation of the processor Assembly language take advantage of all the features and instructions available on the processor. This is not the case with high-level languages Source code is the instructions in the original program A program is written in a language other than machine language, need to be converted into equivalent machine language instructions. Translator is a program that convert the source code into machine language Assembler is a program that convert the assembly language program and generates and saves an equivalent program in machine language. 32

33 5- Types of programming language
The advantage of the assembly language programs: In assembly languages, mnemonic names (names that give a clue as to the function of the instruction, such as ADD and SUB) are given to the operations. Some assembly languages allow the use of symbolic names for memory locations (avoiding the need for the programmer to deal directly with memory management and addressing) An assembly language may allow the programmer to provide data in forms other than binary – ordinary decimal numbers or characters Most assemblers include a facility to print a listing of the source program (in assembly language) as well as a list of its machine language equivalent Assemblers usually notify the programmer of errors in the usage of the assembly language. 33

34 5- Types of programming language
The disadvantages of assembly language An assembly language program can only run on one family of processors. (high-level languages can potentially be run on many machines.) Although slightly easier to read than machine language, assembly language programs are still difficult to understand by anyone other than the programmer, and so are difficult to modify or update. Programs written in assembly language tend to be very long. A programming language must be readable by humans and computers, but that the needs of these two parties are so diverse that it is difficult to conceive of a language that would be equally suited to both. Solution: High level language 34

35 5- Types of programming language
High level language: Easier for humans to use A single high level language instruction is usually equivalent to several machine language level instructions It is closer to English and other natural language This lead to increased programmer productivity Easier to debug and to modify Two different mechanisms by which a program written in a high-level language may be translated into machine language: Compilation: The compiler translates the source program (written in the high-level language) into a program written in the machine language (object code) understood by the processor. The machine language version is then saved, and it is this machine language program that is executed every time the program is run (next time, program executes faster) 35

36 5- Types of programming language
Compilation (Cont.) When you buy computer software, you have an executable program, which has already been compiled from the source code. Languages such as C, C++ and Java are designed to be compiled Interpretation: interpreter translates each instruction in the source code into machine language as the program is running, and then immediately executes it. There is never a complete translation of the whole of the source code into machine language, and so no machine language program is generated or saved. The disadvantage is that the translation process must take place every time a program is run, resulting in a slower execution process. Languages, such as JavaScript, Perl and Basic are especially designed to be interpreted. The advantage of an interpreter language is that programs are easier to develop. 36

37 5- Types of programming language
Five Generations of Programming Languages GENERATION NAME SAMPLE STATEMENT First Machine Second Assembly ADD A, B JMP L Third Procedural and structural Overtime:= 5 0; Fourth Object oriented FIND NAME "JONES“ Fifth Natural IF patient is dizzy, THEN check temperature and blood pressure Procedural languages are programming languages with names like BASIC, Pascal, C, COBOL, and FORTRAN. They are called “procedural” because they are designed to express the logic—the procedures—that can solve general problems. 37

38 6- The structure of computer programs
All programs can be built from three logical building blocks Sequential – instructions are executed in the order in which they appear in the program Selection – refers to the process of deciding between two or more action, whether to execute the next instruction (or block of instructions) or skip over it to do the instruction (s) that follow it. Repetition – the decision determines whether or not one or more instructions are repeated Control instruction (Selection and repetition) is an instruction that changes the default sequential order (jump to an instruction later in the program, skipping over the instructions in between, or jump to an earlier instruction). 38

39 6- The structure of computer programs
Selection Selection (branching) occurs in a computer program when the instruction or instructions to be executed depend on the situation (conditions that can be either true or false) True and false are referred to as Boolean values Boolean expression: condition that can be evaluated true or false Only one of the two instructions is executed The if branch is executed if the condition is true, and the else branch is executed if the condition is false Selecting between two alternatives if (condition) statement1 else statement2 39

40 6- The structure of computer programs
A single possibility Selection can be applied to a situation where there is a single action that we either wish to carry out or not, based on a given condition if (condition) statement More than two alternative More complicated selection structures allow a programmer to test two or more conditions, leading to more than two possible branches. It known as nesting (nested if … else clauses) statement1 else statement2 statement3 40

41 6- The structure of computer programs
Repetition Repetition, or looping, occurs when we have an instruction (s) that we might want to execute more than once. There is a condition that control what happens Loop body: the instructions to be repeated A while loop: when the start of a while loop is encountered in a program the condition is evaluated; if it is true, the instructions in the loop body are executed. Then the condition is evaluated again and, if it is true, the loop body is executed again. This process continues until the condition evaluates to false, at which point the looping stops, and the instruction following the loop body (if there is one) is executed. High level programming languages have more than one looping structure 41

42 6- The structure of computer programs
It is possible that the condition may evaluate to false the first time round, and that the sequence of statements in the body of the loop will not be executed at all. Infinite loop: designing a loop structure is that if care is not taken to ensure that the condition eventually becomes false, the loop body will repeat forever. Trace tables Another way of working out what a program does It is a table that shows what’s going on as each instruction is executed. Trace tables are not formal structures 42

43 6- The structure of computer programs
Example: (1) set the initial value of count to 3 (2) while (NOT( count is 0 )) (3) write out the value of count in the output window (4) move to the next line in the output window (5) reduce count by 1 (6) write ‘blast off’ 43

44 6- The structure of computer programs
44

45 6- The structure of computer programs
Not In programming languages the ‘not’ appears either before or after the complete Boolean expression to make it quite clear what we are negating NOT is called a Boolean operator because it operates on a Boolean expression. NOT is an example of a unary operator, which means that it operates on a single value Truth table: The effects of applying Boolean operators to different Boolean values shown in tables. 45

46 6- The structure of computer programs
Compound conditions: A condition that is made up of two or more conditions Condition involving OR Two quite separate conditions, joined with OR the resulting expression evaluates to true if the first or the second (or both) is true, and false if both the first and the second are false. it is a called a binary operator: operates on two values. 46

47 6- The structure of computer programs
Compound conditions involving AND When two conditions are joined with the AND operator the resulting Boolean expression is only true if both of the separate conditions are true. If one or the other (or both) is false, the compound condition is false. And is a binary operator because it operates on two values 47

48 6- The structure of computer programs
Compound conditions involving NOT NOT A AND NOT B always produces an identical result to NOT (A OR B) NOT A OR NOT B NOT (A AND B) are always equivalent. These two equivalencies are known as De Morgan’s Laws The precedence rules: parentheses first (always evaluate their contents first) then unary operators (NOT) then binary operators (AND, OR) The precedence of OR and AND varies from programming language to programming language so it is wise always to include parentheses in such conditions so as to make your meaning absolutely clear. 48

49 6- The structure of computer programs
Examples If (The shape is a circle) OR (The shape is filled in) true OR true Result is: true Number is 8 If (The number is 3 or greater) OR (The number is 7 or less) true OR false Result is: true A female of 65 If ((gender = "male" and age > 64) charge reduced rate else charge full rate Result : false 49

50 6- The structure of computer programs
Example NOT ((The shape is circle) OR (The shape is filled in)) gives the same result as NOT (The shape is circle) AND NOT (The shape is filled in) false false false 50


Download ppt "M150: Data, Computing and Information"

Similar presentations


Ads by Google