0% found this document useful (0 votes)
27 views

Introduction To Components of A Computer System

The document introduces programming and basic computer concepts. It discusses hardware components like the CPU, memory and storage. It also covers software concepts like operating systems, applications and programming languages. The document provides an overview of how computers work and how programming allows computers to perform tasks.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Introduction To Components of A Computer System

The document introduces programming and basic computer concepts. It discusses hardware components like the CPU, memory and storage. It also covers software concepts like operating systems, applications and programming languages. The document provides an overview of how computers work and how programming allows computers to perform tasks.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 32

INTRODUCTION TO

PROGRAMMING
 Programs can also be called software.
 Software refers to the computer programs that a computer uses to complete a task.

 Hardware refers to the physical components that a computer is made of.


 A computer is not one device, but a system of devices working in tandem.
 Each device plays a part.
 Major components:
 Central Processing Unit
 Main Memory
 Secondary Storage Devices
 Input Devices
 Output Devices
 The CPU is the heart and brain of the computer.
 The CPU continuously does the following things:
1. Fetch an instruction
2. Follow the instruction
3. Produce some resulting data
 The CPU has two parts:
 Control Unit
 Coordinates the computer’s operations
 Determines where to get the next instruction
 Regulates the other major components of the computer
 Arithmetic and Logic Unit (ALU)
 Designed to perform mathematical operations
 Main memory holds information that the CPU needs to access quickly.
 Namely, the instructions to be executed.

 When a program is running, some or all of its instructions are in main memory.
 Memory is divided into sections called bytes that hold equal amount of data.
 Each section is made up of 8 bits.
 A Bit is the most basic unit of information a computer can hold. It is a switch that is either
on (1) or off (0)
 Each byte is assigned and can be accessed by its address.
 A Memory Address is a unique identifying number associated with a byte in memory.

 Main memory typically is volatile.


 Volatile Memory – is memory that when it loses power, the contents are erased.
 Secondary Storage is memory that can hold data for a long period of time.
 Programs are usually stored in secondary storage and loaded into main memory as
needed.
 This forms a hierarchy typically called the memory hierarchy.

 Common forms of secondary storage:


 Hard Drive
 Disk Drive
 Solid State Drive
 Removable Storage
 Floppy Disk
 CD-ROM
 USB Drives

 Other files can be stored in secondary storage:


 Documents
 Pictures
 Whatever else you save on your computer
 Input is any data the computer collects from the outside world.
 An Input Device is anything that collects data and sends it to the
computer.
 Common Input Devices:
 Keyboard
 Mouse
 Scanner
 Digital Camera
 Disk Drive
 USB Drive
 Output is any data the computer sends to the outside world.
 An Output Device formats data and presents it to the outside world.
 Common Output Devices:
 Monitor
 Printer
 Disk Drive
 USB Drive
 Software refers to the programs that run on a computer.
 Two main categories (for this class):
 Operating System (OS)
 A set of programs that manages a computer’s hardware devices and controls their
processes.
 Most modern operating systems are capable of running multiple programs at once.
 UNIX, Linux, Mac OS X, and Windows are examples
 Application Software
 Programs that make the computer useful for the user
 Solve specific problems or supply a service
 Word processors, spreadsheets, databases, etc.
 This is what we will be developing in this class.
 Computers are used for many different purposes in many different
situations.
 But, how can they be so versatile?
 Answer: They can be programmed

 The ability for a computer to be programmed allows it to do whatever


their programs tell them what to do.
 A program is a set of instructions that tell a computer what to do.
 A computer cannot do anything unless it has a program to tell it what to
do.
 Many programmers follow a sequence of Steps to create their programs.

1. Analyze – Define the Problem


 Make sure that you understand what the program should do. What should
the user be able to enter? How? How does the program come up with an
answer? What does the program output? How?
 User – a person who uses a computer program.
 End User – the user that the program was made for.

2. Design – Plan a Solution for the Problem


 Develop a PRECISE sequence of steps to solve the problem
 An algorithm is a precise sequence of steps to solve a problem.
 Imagine you want a program that tells a user how many stamps they
need in order to mail a certain number of pages.
 You need one stamp for every 5 pages
 6 pages = 2 stamps
 12 pages = 3 stamps
 …

 Write an algorithm (the steps needed) to solve this problem


 Typically a program follows three general steps
1. Input
2. Processing (Formulas)
3. Output
 Are those three steps enough?
 What about if the user enters “Banana” instead of a number of sheets?
 The program does not know how to find the number of stamps required to mail “Banana”
number of sheets
 In order for the program to run without crashing, our algorithm must make sure that the
user inputs some valid data.
 There are two main ways of doing this:
1. Prevention – Making sure that the user is not physically able to enter in invalid data.
2. Validation – Allowing the user to enter invalid data, but checking it to make sure it is valid before
processing.

 So, there are really 4 general steps most programs follow:


1. Input
1. Read Input
2. Validate Input
2. Process
3. Output
 One good algorithm developed could look like this:
1. Request the number of sheets of paper from the user; call it Sheets
(Input/Read)
2. Make sure Sheets is a positive whole number (Input/Validation)
3. Divide Sheets by 5 (Processing)
4. Round the result from step 3 up to the highest whole number; call it
Stamps (Processing)
5. Reply with the number Stamps (Output)
PROGRAMMING: A WAY OF
THINKING
 The single most important skill for a computer scientist is problem
solving. Problem solving means the ability to formulate problems, think
creatively about solutions, and express a solution clearly and accurately.
 There are several ways to think about computation:
 a set of instructions to be executed
 a set of expressions to be evaluated
 a set of rules to be applied
 a set of objects to be arranged
 a set of messages to be sent and received
 Procedural
 examples: C, Pascal, Basic, Fortran

 Functional
 examples: Lisp, ML

 Object-oriented
 examples: C++, Java, Smalltalk

 Rule-based (or Logic)


 example: Prolog
 Most important: the choice of paradigm (and therefore language)
depends on how humans best think about the problem
 Other considerations:
 efficiency
 compatibility with existing code
 availability of translators
 RAM machine
 procedural

 directed acyclic graphs


 Smalltalk model of O-O

 partial recursive functions


 Lisp and ML

 Markov algorithms
 Prolog is loosely based on these
 There are many programming languages out there
 Lots of other PL-like objects
 document languages, e.g. LaTeX, Postscript
 command languages, e.g. bash, MATLAB
 markup languages, e.g. HTML and XML
 specification languages, e.g. UML
 Can it be understood by people and processed by machines?
 although translation may be required

 Sufficient expressive power?


 can we say what needs to be said, at an appropriate level of abstraction?
– Machine Language
• Uses binary code
• Machine-dependent
• Not portable
 Assembly Language
 Uses mnemonics
 Machine-dependent
 Not usually portable
 High-Level Language (HLL)
 Uses English-like language
 Machine independent
 Portable (but must be compiled for different platforms)
 Examples: Pascal, C, C++, Java, Fortran, . . .
 The representation of a computer program which is actually
read and understood by the computer.
 A program in machine code consists of a sequence of machine
instructions.
 Instructions:
 Machine instructions are in binary code
 Instructions specify operations and memory cells involved in the
operation
Example: Operation Address

0010 0000 0000 0100

0100 0000 0000 0101

0011 0000 0000 0110


 A symbolic representation of the machine language of a specific
processor.
 Is converted to machine code by an assembler.
 Usually, each line of assembly code produces one machine
instruction (One-to-one correspondence).
 Programming in assembly language is slow and error-prone but
is more efficient in terms of hardware performance.
 Mnemonic representation of the instructions and data
 Example:
Load Price
Add Tax
Store Cost
 A programming language which use statements consisting of
English-like keywords such as "FOR", "PRINT" or “IF“, ... etc.
 Each statement corresponds to several machine language
instructions (one-to-many correspondence).
 Much easier to program than in assembly language.
 Data are referenced using descriptive names
 Operations can be described using familiar symbols
 Example:

Cost := Price + Tax


 Syntax:
 The structure of strings in some language. A language's syntax
is described by a grammar.
 Examples:
 Binary number
<binary_number> = <bit> | <bit> <binary_number>
<bit> =0|1
 Identifier
<identifier> = <letter> {<letter> | <digit> }
<letter> =a|b|...|z
<digit =0|1|...|9
 Semantics:
 The meaning of the language
 Syntax descriptions for a PL are themselves written in a formal
language.
 E.g. Backus-Naur Form (BNF)

 The formal language is not a PL but it can be implemented by a


compiler to enforce grammar restrictions.
 Some PLs look more like grammar descriptions than like instructions.
 Compiler

 A program that converts another program from some source language (or
high-level programming language / HLL) to machine language (object code).

 Some compilers output assembly language which is then converted to


machine language by a separate assembler.

 Is distinguished from an assembler by the fact that each input statement, in


general, correspond to more than one machine instruction.
Source Assembly
Program Compiler Language

Assembly Assembler Machine


Language Language
 Source program

 The form in which a computer program, written in some formal


programming language, is written by the programmer.

 Can be compiled automatically into object code or machine code or


executed by an interpreter.

 Pascal source programs have extension ‘.pas’


 Object program

 Output from the compiler

 Equivalent machine language translation of the source program

 Files usually have extension ‘.obj’

 Executable program

 Output from linker/loader

 Machine language program linked with necessary libraries & other files

 Files usually have extension ‘.exe’


 A program that pulls other programs together so that
they can run.
 Most programs are very large and consist of several
modules.
 Even small programs use existing code provided by the
programming environment called libraries.
 The linker pulls everything together, makes sure that
references to other parts of the program (code) are
resolved.

You might also like