1 coms 261 computer science i title: computer organization date: september 1, 2005 lecture number: 2
TRANSCRIPT
![Page 1: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/1.jpg)
1
COMS 261Computer Science I
Title: Computer OrganizationDate: September 1, 2005Lecture Number: 2
![Page 2: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/2.jpg)
2
Announcements
• Homework 1– Due Monday, 9/5/05
![Page 3: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/3.jpg)
3
Review
• Rules of the game– Any questions?
![Page 4: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/4.jpg)
4
Outline
• Computing Terminology– Decimal to binary conversion
– Fetch/Execute cycle
– Programming• High-Level language• Assembly language• Machine Language
– Think – Edit – Compile - Test Cycle
![Page 5: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/5.jpg)
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
![Page 6: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/6.jpg)
6
Computing Terminology
• Measurements– Important way Computer Scientists
communicate
– Machine performance• Amount of time it takes a machine to perform a
basic operation
![Page 7: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/7.jpg)
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
![Page 8: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/8.jpg)
8
Computing Terminology
• Measurements (Cont.)– Another (incorrect) measure of machine
performance• Clock rate
–Measured in cycles/second, hertz (Hz)
![Page 9: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/9.jpg)
9
Computing Terminology
• Measurements (Cont.)
thousands 103 kilo, K
millions 106 mega, M
billions 109 giga, G
trillions 1012 tera, T
![Page 10: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/10.jpg)
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
![Page 11: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/11.jpg)
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
![Page 12: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/12.jpg)
12
Computer Organization
• Most computers have 4 main parts
Main Memory
Input Devices Output Devices
Central Processing Unit(CPU)
![Page 13: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/13.jpg)
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
![Page 14: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/14.jpg)
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
![Page 15: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/15.jpg)
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
![Page 16: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/16.jpg)
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
![Page 17: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/17.jpg)
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
![Page 18: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/18.jpg)
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
![Page 19: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/19.jpg)
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
![Page 20: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/20.jpg)
• 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
![Page 21: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/21.jpg)
– 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
![Page 22: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/22.jpg)
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
![Page 23: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/23.jpg)
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
![Page 24: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/24.jpg)
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
![Page 25: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/25.jpg)
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
![Page 26: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/26.jpg)
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
![Page 27: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/27.jpg)
27
Other Representations
• There are other representations of quantities– Octal: base 8
– Hexadecimal: base 16
• Conversions between the representations
![Page 28: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/28.jpg)
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
![Page 29: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/29.jpg)
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• …
![Page 30: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/30.jpg)
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)
![Page 31: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/31.jpg)
31
Programming
– Instruction set• The set of legal instructions for a particular
machine– MIPS– Intel– AMD
• Legal bit patterns recognized by the machine
![Page 32: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/32.jpg)
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
![Page 33: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/33.jpg)
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
.
.
.
![Page 34: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/34.jpg)
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
![Page 35: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/35.jpg)
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
![Page 36: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/36.jpg)
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)
![Page 37: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/37.jpg)
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
![Page 38: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/38.jpg)
38
Assembly Programming
Assembler
MachineLanguageProgram
Execute (run)Program
AssemblyLanguageProgram
ThinkThinkThink
Editor
Object
Code
Different InputTest Cases
![Page 39: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/39.jpg)
39
Programming
• Machine language– Low-level programming
– Binary language
• Assembly language– Higher-level programming
• Still pretty low-level
– Mnemonics simplify programming
![Page 40: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/40.jpg)
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
![Page 41: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/41.jpg)
41
HLL Programming
• High-level languages– More English like
– Powerful constructs
– Simpler to write and maintain code
– More portable
![Page 42: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/42.jpg)
42
HLL Programming
• High-level languages (Cont.)– Popular high-level languages
• C• C++• Java• Fortran• Perl• Smalltalk• Scheme• …
![Page 43: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/43.jpg)
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, …
![Page 44: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/44.jpg)
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
![Page 45: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/45.jpg)
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
![Page 46: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/46.jpg)
46
HLL Programming
MachineLanguageProgram
ThinkThinkThink
Assembler
Editor
Compiler
AssemblyLanguageProgram
C++/FortranLanguageProgram
MathLibrary
ObjectCode
Linker
Execute (run)Program
![Page 47: 1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture Number: 2](https://reader030.vdocuments.mx/reader030/viewer/2022032605/56649e725503460f94b71d33/html5/thumbnails/47.jpg)
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