1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number:...

Post on 29-Dec-2015

214 views 1 download

Tags:

Transcript of 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number:...

1

COMS 261Computer Science I

Title: Computer OrganizationDate: September 1, 2005Lecture Number: 2

2

Announcements

• Homework 1– Due Monday, 9/5/05

3

Review

• Rules of the game– Any questions?

4

Outline

• Computing Terminology– Decimal to binary conversion

– Fetch/Execute cycle

– Programming• High-Level language• Assembly language• Machine Language

– Think – Edit – Compile - Test Cycle

5

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

6

Computing Terminology

• Measurements– Important way Computer Scientists

communicate

– Machine performance• Amount of time it takes a machine to perform a

basic operation

7

Computing Terminology

• Measurements (Cont.)

thousandths 10-3 milli, m

millionths 10-6 micro, u

billionths 10-9 nano, n

trillionths 10-12 pico, p

quadrillionth 10-15 femto, f

quintillionth 10-18 atto, a

sextillionth 10-21 zepto, z

septillion 10-24 yocto, y

8

Computing Terminology

• Measurements (Cont.)– Another (incorrect) measure of machine

performance• Clock rate

–Measured in cycles/second, hertz (Hz)

9

Computing Terminology

• Measurements (Cont.)

thousands 103 kilo, K

millions 106 mega, M

billions 109 giga, G

trillions 1012 tera, T

10

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 LatinSI

PrefixesComputer 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

1012 = 1,000,000,000,000

trillions tera, T240 =

1,099,511,627,776

11

Computing Terminology

Scientific Units Latin SI PrefixesComputer Science

Units

1015 = 1,000,000,000,000,000 Quadrillion peta, P250 =

1125899906842624

1018 = 1,000,000,000,000,000,000 Quintillion exa, E260 =

1152921504606846976

1021 = 1,000,000,000,000,000,000,000 Sextillion zetta, Z270 =

1180591620717411303424

1024 = 1,000,000,000,000,000,000,000,000

Septillion yotta, Y280 =

1208925819614629174706176

1027 = 1,000,000,000,000,000,000,000,000,000

Octillion Nobi, Ni290 =

1237940039285380274899124224

1030 = 1,000,000,000,000,000,000,000,000,000,

000Nonillion Debi, Di

2100 =

1267650600228229401496703205376

12

Computer Organization

• Most computers have 4 main parts

Main Memory

Input Devices Output Devices

Central Processing Unit(CPU)

13

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

14

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

15

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

16

Fetch/Execute Cycle

Fetch the next instructionfrom memory

Execute the current instruction

Program Counter(PC)

Update the PC to referencethe next instruction

And Ya

Don’t Stop,

And Ya

Don’t Quit

17

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

01 10*810*228 Base raised to its positional power

18

Number Systems

• Likewise– The binary number system is also positional

• So, we learned that

0123 2*12*12*02*11011

111281*12*14*08*11011

111011

19

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

• Note: the smaller the base, the more the number of digits needed to represent the quantity

102 111011

• 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

Operating System

22

Decimal to Binary Conversion

• Convert

• 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

210 ?11

012345 2 2 2 2 2 21 2 4 8 61 32

23

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

101010 3811

...2*111 310

24

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

– Subtract the base raised to the highest power from the remainder

...2*12*02*111 12310

25

Decimal to Binary Conversion

– 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

012310 2*12*12*02*111

...2*12*02*111 12310

101010 123

26

Decimal to Binary Conversion

– Subtract the base raised to the highest power from the remainder• No remainder, and no more powers of 2,

therefore

101010 011

210 101111

27

Other Representations

• There are other representations of quantities– Octal: base 8

– Hexadecimal: base 16

• Conversions between the representations

28

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

29

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• …

30

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)

31

Programming

– Instruction set• The set of legal instructions for a particular

machine– MIPS– Intel– AMD

• Legal bit patterns recognized by the machine

32

Programming

• 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

10110010 10100110 01001110 11001010

33

Programming

• It is possible to write a program in binary instructions

– The binary instruction set is also called machine language• Varies from processor to processor

10110010 10100110 01001110 1100101011100011 10000100 01001010 1101100110001001 11100101 11011000 10011011

.

.

.

34

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

35

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

36

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)

37

Assembly Language

push ebpmov ebp,espsub esp,0x8mov eax,0xccccccccmov dword ptr [esp],eaxmov dword ptr [esp+0x4],eaxmov dword ptr [ebp-0x4],0x6mov eax,dword ptr [ebp-0x4]mov dword ptr [ebp-0x8],eaxmov eax,0x0leave ret near

mnemonics arguments

• Example assembly language program

38

Assembly Programming

Assembler

MachineLanguageProgram

Execute (run)Program

AssemblyLanguageProgram

ThinkThinkThink

Editor

Object

Code

Different InputTest Cases

39

Programming

• Machine language– Low-level programming

– Binary language

• Assembly language– Higher-level programming

• Still pretty low-level

– Mnemonics simplify programming

40

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

41

HLL Programming

• High-level languages– More English like

– Powerful constructs

– Simpler to write and maintain code

– More portable

42

HLL Programming

• High-level languages (Cont.)– Popular high-level languages

• C• C++• Java• Fortran• Perl• Smalltalk• Scheme• …

43

HLL Programming

• Code reusability– Many operations are common to most

programs• Printing to the console (screen) or a file• Mathematical routines• String processing• Etc, …

44

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

45

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

46

HLL Programming

MachineLanguageProgram

ThinkThinkThink

Assembler

Editor

Compiler

AssemblyLanguageProgram

C++/FortranLanguageProgram

MathLibrary

ObjectCode

Linker

Execute (run)Program

47

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