Topic 1
Topic 1
- What’s a computer?
- Algorithms
- What’s a program?
- Data Representation
2
Hardware and Software
The CPU
• The central processing unit is the part that actually runs programs
– The most important part of a computer
– Today CPUs are microprocessor
– Commonly used CPU vendors are Intel and AMD
Main Memory
• Devices that can hold data for long periods of time, even when the power
is off
– Where important data and system files are stored
– Most commonly used is the disk drive which stores data by
magnetically encoding it onto a circular disk
– Solid state drives have no moving parts, and operate faster than a
traditional disk drive.
– Optical devices such as DVD-ROMs and CD-ROMs are also popular
– USB drives and SD memory cards are small devices that plug into a
port
Input Devices
Output Devices
• “Digital” refers to anything that can only have two possible values
– Digital data is the data that is stored in binary.
– Digital devices are devices that work with binary data
– Computers are digital devices
Algorithms
12
Algorithm
Properties of an Algorithm
14
Algorithm
Pseudocode
17
– Machine languages:
• A sequence of 0s and 1s represent one instruction
• Differs from machine to machine
• low-level language
– High-level languages: more human readable languages that allow
programmers to create programs without knowing how CPU works.
• Modern languages are high-level
• High level languages use keywords that have special meaning and cannot
be used for any purpose other than to write programs
• Operators are keywords that represent special program functions such as
addition, subtraction, and multiplication
• Syntax is a set of rules that must be strictly followed to write computer-
understandable instructions
– Syntax error is a mistake or violation of these rules
• Each instruction in a program is called a statement
Compilers and Interpreters
22
The Compilation Process 53 83 EC 08 E8 97 00 00
- Machine Language 00 00 81 C3 47 1D 00 00
8B 83 FC FF FF FF 85 C0
● A machine language can be processed 74 05 E8 32 00 00 00 83
directly by a computer. C4 08 5B C3 FF 35 04 A0
04 08 FF 25 04 A0 04 08
○ A program is a sequence of 00 00 FF 25 0C A0 04 08
instructions. 68 00 00 00 00 FF 25 10
A0 04 08 68 08 00 00 00
○ Each instruction is represented by a 00 E9 D0 FF FF FF FF 25
binary number and includes: 14 A0 04 08 68 10 00 00
00 00 E9 C0 FF FF FF 31
○ Operation code
ED 5E 89 E1 83 E4 F0 50
○ Optionally, an Operand 54 52 68 B0 84 04 08 68
○ No variable names or subroutine 40 84 04 08 51 56 68 40
84 04 08 E8 CF FF FF FF
names in machine language! F4 66 90 66 90 66 90 66
90 66 90 66 90 8B 1C 24
● Machine languages are very hard for
C3 66 90 66 90 66 90 B8
humans to write and understand.
Machine Code for part of the “Hello World!” program
23
Data Representation
24
Character Encodings
25
Character Encodings
• Recall: the main representation used in our computers are bits (binary
representation), which can be either 0 or 1.
– Question: So how does the computer know what we are trying to
input?
– Answer: Character encodings
• Using binary representation, we can obtain different types of data by
using that character encoding. Here are some examples:
– base n number systems
– ASCII
Character Encodings
Binary Representations:
• Bit - one binary digit (0,1)
• Nibble – a group of four bits
• Byte - a group of eight bits
• Word - a group of sixteen bits
• Bit string - a series of bits that the computer uses as data
Other Measures:
• Kilobyte = 210 bytes
• Megabyte = 220 bytes
• Gigabytes = 230 bytes
Character Encodings
- Base r number systems
Decimal: 0, 1, 2, … , 8, 9, 10, 11, 12, ………. 99, 100, 101, 102, ……….
Hexadecimal: 0, 1, 2, … , E, F, 10, 11, 12, ………. FF, 100, 101, 102, ……….
Character Encodings
- Base r number systems
Character Encodings
- base r number systems
Columns: 5 4 3 2 1 0
1100012 = 25 + 24 + 20 10 = 49 10
Character Encodings
- base r number systems
Character Encodings
- Base r number systems
Sign-Magnitude:
01110SM = + 14 10
11110SM = - 14 10
Character Encodings
Negative number systems
011102C = +14 10
111102C = - (00001 + 1)2 = - (00010)2 = - 210
Character Encodings
Negative number systems
Character Encodings
- other encodings
In general,
Besides base r number systems, there are other ways to encode a character
(for input, output, memory, etc.)
• ASCII - includes 7 bits, codes 128 characters (next slide)
• Typically, we add a zero at the beginning to make it an 8 bit (1 byte)
representation.
• Unicode - extends ASCII to 16 or 32 bits: 4,294,967,296 different
characters
http://www.unicode.org/charts/
http://macchiato.com/unicode/chart/
ASCII table
B6 B5 B4
B3 B2 B1 B0 000 001 010 011 100 101 110 111
0000 null dle sp 0 @ P ` p
0001 soh dc1 ! 1 A Q a q
0010 stx dc2 “ 2 B R b r
0011 etx dc3 # 3 C S c s
0100 eot dc4 $ 4 D T d t
0101 enq nak % 5 E U e u
0110 ack syn & 6 F V f v
0111 bel etb ‘ 7 G W g w
1000 bs can ( 8 H X h x
1001 ht em ) 9 I Y i y
1010 lf sub * : J Z j z
1011 vt esc + ; K [ k {
1100 ff fs , < L \ l |
1101 cr gs - = M ] m }
1110 so rs . > N ^ n ~
1111 si us / ? O _ o del