Download Thursday

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Reactive programming wikipedia , lookup

Object-oriented programming wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Programming language wikipedia , lookup

Abstraction (computer science) wikipedia , lookup

Structured programming wikipedia , lookup

Go (programming language) wikipedia , lookup

Compiler wikipedia , lookup

Parallel computing wikipedia , lookup

History of compiler construction wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

ILLIAC IV wikipedia , lookup

Interpreter (computing) wikipedia , lookup

Assembly language wikipedia , lookup

Transcript
COMS 261
Computer Science I
Title: Computer Organization
Date: September 1, 2005
Lecture Number: 2
1
Announcements
• Homework 1
– Due Monday, 9/5/05
2
Review
• Rules of the game
– Any questions?
3
Outline
• Computing Terminology
– Decimal to binary conversion
– Fetch/Execute cycle
– Programming
• High-Level language
• Assembly language
• Machine Language
– Think – Edit – Compile - Test Cycle
4
Computing Terminology
• Computer system
– Components
• Hardware: physical devices
– Processor, disk drive, graphics card, RAM, …
• Software: tells the computer what to do
– FireFox, Outlook, PowerPoint, Unreal Tournament,
…
– Development is difficult
» Not just sitting at a computer and typing
» Different methodologies have emerged, Object-Oriented
5
Computing Terminology
• Measurements
– Important way Computer Scientists
communicate
– Machine performance
• Amount of time it takes a machine to perform a
basic operation
6
Computing Terminology
• Measurements
(Cont.)
thousandths
millionths
billionths
10-3
10-6
10-9
milli, m
micro, u
nano, n
trillionths
10-12
pico, p
quadrillionth
10-15
femto, f
quintillionth
sextillionth
septillion
10-18
10-21
10-24
atto, a
zepto, z
yocto, y
7
Computing Terminology
• Measurements
(Cont.)
– Another (incorrect) measure of machine
performance
• Clock rate
–Measured in cycles/second, hertz (Hz)
8
Computing Terminology
• Measurements
(Cont.)
thousands
103
kilo, K
millions
106
mega, M
billions
109
giga, G
trillions
1012
tera, T
9
Computing Terminology
– Caution
• Capacity measures are made using powers of
2’s, not 10’s
• The abbreviations are the same, K, M, G, …
Scientific Units
Latin
SI
Prefixes
Computer Science
Units
103 = 1,000
thousands
kilo, K
210 = 1024
106 = 1,000,000
millions
mega, M
220 = 1,048,576
109 = 1,000,000,000
billions
giga, G
230 = 1,073,741,824
tera, T
240 =
1,099,511,627,776
1012 =
1,000,000,000,000
trillions
10
Computing Terminology
Scientific Units
Latin
SI Prefixes
Computer Science
Units
1015 = 1,000,000,000,000,000
Quadrillion
peta, P
250 =
1125899906842624
exa, E
260 =
115292150460684697
6
zetta, Z
270 =
118059162071741130
3424
yotta, Y
280 =
120892581961462917
4706176
Nobi, Ni
290 =
123794003928538027
4899124224
Debi, Di
2100 =
126765060022822940
1496703205376
1018 = 1,000,000,000,000,000,000
1021 = 1,000,000,000,000,000,000,000
1024
=
1,000,000,000,000,000,000,000,000
1027 =
1,000,000,000,000,000,000,000,000,000
1030 =
1,000,000,000,000,000,000,000,000,000
,000
Quintillion
Sextillion
Septillion
Octillion
Nonillion
11
Computer Organization
• Most computers have 4 main parts
Main Memory
Input Devices
Output Devices
Central Processing Unit
(CPU)
12
CPU
• Brains of the computer
• Consists of two components
– Arithmetic calculations are performed using
the Arithmetic/Logical Unit or ALU
– Control unit decodes and executes
instructions
• Arithmetic operations are performed
using binary number system
13
Control Unit
• The CPU uses a fetch/execute cycle to
execute instructions
• Performing the action specified by an
instruction is known as executing the
instruction
• The program counter (PC) holds the
memory address of the next instruction
– Special purpose register
14
Fetch/Execute Cycle
• Computers are stupid
– They can only perform
• Simple
• Well defined
• Very specific tasks
– Instructions: The tasks a computer can do
• Different programs or applications result from
different sets (or sequences) of instructions
– A computer (even the most powerful) simply
get instructions and execute them
15
Fetch/Execute Cycle
Fetch the next instruction
from memory
Update the PC to reference
the next instruction
Program Counter
(PC)
Execute the current
instruction
16
Number Systems
• Computers use a positional numbering
system
– Positions of digits in a number have
meaning
• The decimal number system (base 10) is a
positional system
• 28 has a different meaning than 82
– Even though the same digits are used
28  2 *10  8 *10
1
0
Base raised to its
positional power
17
Number Systems
• Likewise
– The binary number system is also positional
1011  1* 2  0 * 2  1* 2  1* 2
3
2
1
0
1011  1*8  0 * 4 1* 2 1*1  8  2 1  11
• So, we learned that
1011  11
18
Number Systems
– Which of course does not make any sense
unless you indicate the quantity
• 1011 is a binary representation
• 11 is a decimal representation
– We denote numbers with their base
10112  1110
• Note: the smaller the base, the more the
number of digits needed to represent the
quantity
19
Operating System
• Windows®, UNIX®, Mac OS X®
• Controls and manages the computing
resources
– Important services provided by an operating
system
• File system
– Directories, folders, files
Operating System
– Commands that allow for manipulation of the
file system
• Sort, delete, copy
– Ability to perform input and output on a
variety of devices
– Management of the running systems
Decimal to Binary Conversion
• Convert 1110  ?2
• Procedure
– Find the highest power of the base (2) the
number will divide
• Find the highest power so that the base raised
to that power is less than or equal to the given
number
5
4
2 2
32 16
3
2
8
2
4
2
1
2
2
0
2
1
22
Decimal to Binary Conversion
• 24 = 1610 is larger than 1110, while
• 23 = 810 is less than or equal to 1110
– There is a 23 in the binary representation of the
number 1110
– Subtract the base raised to the highest
power from the number to convert
1110  810  310
1110  1* 2  ...
3
23
Decimal to Binary Conversion
– Find the highest power of 2 the remainder
will divide
• 22 = 4 is larger than 310
– There is not a 22 in the binary representation of 1110
• 21 = 2 is less than or equal to 310
– There is a 21 in the binary representation of 1110
1110  1* 2  0 * 2  1* 2 ...
3
2
1
– Subtract the base raised to the highest
power from the remainder
24
Decimal to Binary Conversion
310  210  110
1110  1* 2  0 * 2  1* 2 ...
3
2
1
– Find the highest power of the base (2) the
remainder will divide
• 20 = 1 is the same as 110
– There is a 20 in the binary representation of 1110
1110  1* 2  0 * 2  1* 2  1* 2
3
2
1
0
25
Decimal to Binary Conversion
– Subtract the base raised to the highest
power from the remainder
• No remainder, and no more powers of 2,
therefore
110  110  010
1110  10112
26
Other Representations
• There are other representations of
quantities
– Octal: base 8
– Hexadecimal: base 16
• Conversions between the
representations
27
Two’s Complement
•
•
•
•
Used by almost all computers
Binary representation
Includes negative numbers
Contains one representation for the
quantity 0
• Arithmetic operations
– Simpler to perform
– Result in a two’s complement number
• No extra conversion must take place
28
Programming
• Programs are specific sequences of
instructions
– Instructions are primitive operations
• Move data from one place to another
• Add two items together
• Check a value for equivalence to zero
•…
29
Programming
– Instructions have a binary representation or
encoding
• Advantageous to have all instructions be a
constant number of bits
• Typically composed of several fields (groups of
bits)
30
Programming
– Instruction set
• The set of legal instructions for a particular
machine
– MIPS
– Intel
– AMD
• Legal bit patterns recognized by the machine
31
Programming
10110010 10100110 01001110 11001010
• May mean add the contents of two registers
and put the result in a third register in the MIPS
processor, while it may no be a part of the
instruction set for the Intel processor
32
Programming
• It is possible to write a program in binary
instructions
10110010 10100110 01001110 11001010
11100011 10000100 01001010 11011001
10001001 11100101 11011000 10011011
.
.
.
– The binary instruction set is also called
machine language
• Varies from processor to processor
33
Programming
• Do software developers write programs
in machine language?
– NO
• Tedious
• Error prone, single bit out of place
• Specific to only one machine
– Said to be not portable
• Difficult to maintain and change
• Impossible for someone else to work on the
program
34
Machine Language
• Programs written using the binary
instruction set are said to be written in
machine language
– The resulting list of instructions is called
machine code, also called object code
35
Assembly Language
• Assembly language
– A language directly related to machine
language
– each instruction has a unique symbol
associated with it
– Assembly language programmers use the
symbols that represent instructions instead
of the binary instructions
– An assembler converts the symbols into
machine language (instructions)
36
Assembly Language
• Example assembly language program
mnemonics
push
mov
sub
mov
mov
mov
mov
mov
mov
mov
leave
ret
ebp
ebp,esp
esp,0x8
eax,0xcccccccc
dword ptr [esp],eax
dword ptr [esp+0x4],eax
dword ptr [ebp-0x4],0x6
eax,dword ptr [ebp-0x4]
dword ptr [ebp-0x8],eax
eax,0x0
arguments
near
37
Assembly Programming
Editor
Think
Think
Think
Assembly
Language
Program
Assembler
Machine
Language
Program
Different Input
Test Cases
Execute (run)
Program
38
Programming
• Machine language
– Low-level programming
– Binary language
• Assembly language
– Higher-level programming
• Still pretty low-level
– Mnemonics simplify programming
39
Programming
• Assembly language
(Cont.)
– May also include Pseudo instructions
• Mnemonics can encapsulate one or more
machine instructions
– Simpler than machine language
• Still tedious
• Error prone
• Not portable
• Difficult to maintain
40
HLL Programming
• High-level languages
– More English like
– Powerful constructs
– Simpler to write and maintain code
– More portable
41
HLL Programming
• High-level languages
(Cont.)
– Popular high-level languages
•C
• C++
• Java
• Fortran
• Perl
• Smalltalk
• Scheme
•…
42
HLL Programming
• Code reusability
– Many operations are common to most
programs
• Printing to the console (screen) or a file
• Mathematical routines
• String processing
• Etc, …
43
HLL Programming
• Code reusability
(Cont.)
– Most useful to have common routines
already compiled into machine language
(object code)
– Libraries are the object code for groups of
related routines packaged into a single file
44
HLL Programming
• Code reusability
(Cont.)
– Libraries and different object files must be
combined forming a single executable file
• Linking and the linker
– Linking is the process of combining
different files of object code into a single
executable file
– The linker is a program that performs the
linking
45
HLL Programming
C++/Fortran
Language
Program
Editor
Compiler
Assembly
Language
Program
Math
Library
Object
Code
Linker
Assembler
Think
Think
Think
Machine
Language
Program
Execute (run)
Program
46
IDE’s
• Integrated Development Environments
– Provides one user interface for the
development process
• Editor, Compiler, Linker, Loader, Debugger,
Viewer
– We will be using the CodeWarrior IDE
throughout this course
47