0% found this document useful (0 votes)
18 views6 pages

Lecture01 Ho

Uploaded by

hxg285b5w2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

Lecture01 Ho

Uploaded by

hxg285b5w2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2

Topics
• Introduction
• Hardware and Software
CN101 • How Computers Store Data
• How a Program Works
Lecture 1
• Using Python
Introduction to Computers and
Programming

3 4

Introduction Hardware and Software


• Computers can be programmed • Hardware: The physical devices that make up a
• Designed to do any job that a program tells them to computer
• Program: set of instructions that a computer follows to • Computer is a system composed of several components that
all work together
perform a task
• Commonly referred to as Software • Typical major components:
• Central processing unit
• Programmer: person who can design, create, and test
• Main memory
computer programs
• Secondary storage devices
• Also known as software developer
• Input and output devices

5 6

The CPU
• Central processing unit (CPU): the part of the computer
that actually runs programs
• Most important component
• Without it, cannot run software
• Used to be a huge device
• Microprocessors: CPUs located on small chips
7 8

Main Memory Secondary Storage Devices


• Main memory: where computer stores a program while • Secondary storage: can hold data for long periods of
program is running, and data used by the program time
• Known as Random Access Memory or RAM • Programs normally stored here and loaded to main memory
when needed
• CPU is able to quickly access data in RAM
• Volatile memory used for temporary storage while program is • Types of secondary memory
running • Disk drive: magnetically encodes data onto a spinning circular
• Contents are erased when computer is off disk
• Solid state drive: faster than disk drive, no moving parts,
stores data in solid state memory
• Flash memory: portable, no physical disk
• Optical devices: data encoded optically

9 10

Input Devices Output Devices


• Input: data the computer collects from people and • Output: data produced by the computer for other
other devices people or devices
• Input device: component that collects the data • Can be text, image, audio, or bit stream
• Examples: keyboard, mouse, touchscreen, scanner, camera • Output device: formats and presents output
• Disk drives can be considered input devices because they load • Examples: video display, printer
programs into the main memory • Disk drives and USB drives can be considered output devices
because data is sent to them to be saved

11 12

Software Software (cont’d.)


• Everything the computer does is controlled by software • System software: programs that control and manage
• General categories: basic operations of a computer
• Application software • Operating system: controls operations of hardware
• System software components
• Application software: programs that make computer • Utility Program: performs specific task to enhance computer
useful for every day tasks operation or safeguard data
• Examples: word processing, email, games, and Web browsers • Software development tools: used to create, modify, and test
software programs
13 14

How Computers Store Data Storing Numbers


• All data in a computer is stored in sequences of 0s and • Bit represents two values, 0 and 1
1s • Computers use binary numbering system
• Byte: just enough memory to store letter or small • Position of digit j is assigned the value 2j-1
number • To determine value of binary number sum position values of
• Divided into eight bits the 1s
• Bit: electrical component that can hold positive or negative • Byte size limits are 0 and 255
charge, like on/off switch • 0 = all bits off; 255 = all bits on
• The on/off pattern of bits in a byte represents data stored in • To store larger number, use several bytes
the byte

15 16

Example Storing Characters


• Data stored in computer must be stored as binary
number
• Characters are converted to numeric code, numeric
code stored in memory
• Most important coding scheme is ASCII
• ASCII is limited: defines codes for only 128 characters
• Unicode coding scheme becoming standard
• Compatible with ASCII
• Can represent characters for other languages

17 18

Example Advanced Number Storage


• To store negative numbers and real numbers,
computers use binary numbering and encoding
schemes
• Negative numbers encoded using two’s complement
• Real numbers encoded using floating-point notation
19 20

Other Types of Data How a Program Works


• Digital: describes any device that stores data as binary • CPU designed to perform simple operations on pieces of
numbers data
• Digital images are composed of pixels • Examples: reading data, adding, subtracting, multiplying, and
dividing numbers
• To store images, each pixel is converted to a binary number
representing the pixel’s color • Understands instructions written in machine language and
included in its instruction set
• Digital music is composed of sections called samples • Each brand of CPU has its own instruction set
• To store music, each sample is converted to a binary number
• To carry out meaningful calculation, CPU must perform
many operations

21 22

How a Program Works (cont’d.) How a Program Works (cont’d.)


• Program must be copied from secondary memory to
RAM each time CPU executes it
• CPU executes program in cycle:
• Fetch: read the next instruction from memory into CPU
• Decode: CPU decodes fetched instruction to determine which
operation to perform
• Execute: perform the operation

23 24
From Machine Language to
High-Level Languages
Assembly Language
• Impractical for people to write in machine language • Low-level language: close in nature to machine language
• Assembly language: uses short words (mnemonics) for • Example: assembly language
instructions instead of binary numbers • High-Level language: allows simple creation of powerful
• Easier for programmers to work with and complex programs
• Assembler: translates assembly language to machine • No need to know how CPU works or write large number of
instructions
language for execution by CPU
• More intuitive to understand
25 26
Key Words, Operators, and Syntax:
Python Key words
an Overview
• Key words: predefined words used to write program in
high-level language
• Each key word has specific meaning
• Operators: perform operations on data
• Example: math operators to perform arithmetic
• Syntax: set of rules to be followed when writing
program
• Statement: individual instruction used in high-level
language

27 28

Compilers and Interpreters Compilers and Interpreters (cont’d.)


• Programs written in high-level languages must be • Interpreter: translates and executes instructions in high-
translated into machine language to be executed level language program
• Compiler: translates high-level language program into • Used by Python language
separate machine language program • Interprets one instruction at a time
• Machine language program can be executed at any time • No separate machine language program
• Source code: statements written by programmer
• Syntax error: prevents code from being translated

29 30

Compilers and Interpreters (cont’d.) Using Python


• Python must be installed and configured prior to use
• One of the items installed is the Python interpreter
• Python interpreter can be used in two modes:
• Interactive mode: enter statements on keyboard
• Script mode: save statements in Python script
31 32
Writing Python Programs and
Interactive Mode
Running Them in Script Mode
• When you start Python in interactive mode, you will see • Statements entered in interactive mode are not saved
a prompt as a program
• Indicates the interpreter is waiting for a Python statement to • To have a program use script mode
be typed
• Save a set of Python statements in a file
• Prompt reappears after previous statement is executed
• The filename should have the .py extension
• Error message displayed If you incorrectly type a statement
• To run the file, or script, press F5 button
• Good way to learn new parts of Python

33 34

The IDLE Programming Environment Summary


• IDLE (Integrated Development Program): single program • This chapter covered:
that provides tools to write, execute and test a program • Main hardware components of the computer
• Automatically installed when Python language is installed • Types of software
• Runs in interactive mode • How data is stored in a computer
• Has built-in text editor with features designed to help write • Basic CPU operations and machine language
Python programs • Fetch-decode-execute cycle
• Complex languages and their translation to machine code
• Installing Python and the Python interpreter modes

You might also like