1 COMS 261 Computer Science I Title: Computer Organization Date: September 1, 2005 Lecture 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.) thousandths10 -3 milli, m millionths10 -6 micro, u billionths10 -9 nano, n trillionths pico, p quadrillionth femto, f quintillionth atto, a sextillionth zepto, z septillion 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.) thousands10 3 kilo, K millions10 6 mega, M billions10 9 giga, G trillions10 12 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 Latin SI Prefixes Computer Science Units 10 3 = 1,000thousandskilo, K2 10 = = 1,000,000millionsmega, M2 20 = 1,048, = 1,000,000,000billionsgiga, G2 30 = 1,073,741, = 1,000,000,000,000 trillionstera, T 2 40 = 1,099,511,627,776
11 Computing Terminology Scientific UnitsLatinSI Prefixes Computer Science Units = 1,000,000,000,000,000Quadrillionpeta, P 2 50 = = 1,000,000,000,000,000,000Quintillionexa, E 2 60 = = 1,000,000,000,000,000,000,000Sextillionzetta, Z 2 70 = = 1,000,000,000,000,000,000,000,000 Septillionyotta, Y 2 80 = = 1,000,000,000,000,000,000,000,000,000 OctillionNobi, Ni 2 90 = = 1,000,000,000,000,000,000,000,000,000,000 NonillionDebi, Di =
12 Computer Organization Most computers have 4 main parts Main Memory Input DevicesOutput 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 instruction from memory Execute the current instruction Program Counter (PC) Update the PC to reference the 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 Base raised to its positional power
18 Number Systems Likewise –The binary number system is also positional So, we learned that
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
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
23 Decimal to Binary Conversion 2 4 = is larger than 11 10, while 2 3 = 8 10 is less than or equal to –There is a 2 3 in the binary representation of the number –Subtract the base raised to the highest power from the number to convert
24 Decimal to Binary Conversion –Find the highest power of 2 the remainder will divide 2 2 = 4 is larger than 3 10 –There is not a 2 2 in the binary representation of = 2 is less than or equal to 3 10 –There is a 2 1 in the binary representation of –Subtract the base raised to the highest power from the remainder
25 Decimal to Binary Conversion –Find the highest power of the base (2) the remainder will divide 2 0 = 1 is the same as 1 10 –There is a 2 0 in the binary representation of 11 10
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
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
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
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 ebp mov ebp,esp sub esp,0x8 mov eax,0xcccccccc mov dword ptr [esp],eax mov dword ptr [esp+0x4],eax mov dword ptr [ebp-0x4],0x6 mov eax,dword ptr [ebp-0x4] mov dword ptr [ebp-0x8],eax mov eax,0x0 leave ret near mnemonics arguments Example assembly language program
38 Assembly Programming Assembler Machine Language Program Execute (run) Program Assembly Language Program Think Editor Object Code Different Input Test 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 Machine Language Program Think Assembler Editor Compiler Assembly Language Program C++/Fortran Language Program Math Library Object Code 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