Computer Organization and Architecture Chapter 1 Software Perspective The Lifetime of a Simple Program A Simple Program # include <stdio.h> int main() { printf( hello, world\n ); } The goal of this course is to help you understand what happens and why, when the program executes on a computer system. Lifetime: Created as a source file Translated into object code Linked into executable Loaded to through a command interpreter Access through a storage hierarchy Hardware resources managed by OS System communicates using network 2 Source Program Representation The Source program is - A text file - A sequence of bits, organized in 8-bit chunks called bytes - Each byte represents one text character - Text characters are represented in ASCII format. Example # i n c l u d e <sp> 35 105 110 99 108 117 100 101 32 All information in a computer system is represented as a bunch of bits. 3
Translation Process The C program hello.c must be translated into a sequence of low-level machine language instructions. Example: On Linux, we use the GCC compiler to translate hello.c into object file Unix> gcc o hello hello.c Compiling phases gcc is a driver that calls preprocessor (cpp), compiler (cc1), assembler (as), and the linker (ld). Hello.c cpp Hello.i cc1 Hello.s as print.o Hello.o ld Hello 4 Understanding Compiler-Generated Code Optimizing program performance Is switch always more efficient than a sequence of ifthen-else? Why accessing a local variable is faster than accessing an argument passed by reference? Why two functionally equivalent loops have very different running times? Understanding link-time errors Linker is playing an increasingly important role Avoid security holes Buffer overflow bugs/tricks account for many security holes 5 Hardware organization Modeled after the Intel Pentium systems CPU/Processor Memory Buses I/O devices 6
Hardware organization Processor (CPU)»Interprets instructions», Registers,»Example instructions load, store, add, I/O read/write, jump»code and data I/O devices»keyboard, mouse, display,, network Buses»Transfer fixed-sized chunks of bytes 7 Running the hello program DMA User types hello Loading hello into 8 Running the hello program Executing hello Loading hello into 9
Running the hello program Write output string to the display 10 It May Look Complicated But it s actually simplified CPU/Processor Memory Buses I/O devices 11 Caches Matter L2 caches L1-cache Front-side bus Back-side bus Caches: smaller faster storage devices that serve as temporary staging areas for frequently referenced information, managed by hardware Local : like caches, but is managed by compilers/programmers 12
Storage Hierarchy Larger, Slower, And Cheaper Storage Devices registers On-chip L1 cache Off-chip L2 cache Memory 8 to 128 16KB to 64KB 256KB to 4MB 128MB to 16GB Local secondary storage 20GB to 1TB Remote secondary storage 13 idea: Storage Hierarchy Storage at one level serves as a cache for storage at the next lower level Example: The L1 cache is a cache for the L2 cache The L2 cache is a cache for the main The main is a cache for the The local serves as a cache for data stored on the s of other systems in a networked system. 14 Operating System OS controls the execution of application programs and acts as an interface between users and the computer hardware. Applications Operating System processor I/O Objectives Protection: to protect the hardware from misuse Convenience: make a computer easier to use (e.g. WIN) Efficiency: allow more efficient use of hardware resources Abstractions Processes for processor,, and I/O Virtual for main and I/O devices Files for I/O device 15
Networks Modern systems are often linked to other systems by networks The network can be viewed as just another I/O device Copying information from one machine to another becomes the most important application e-mail, instant messaging, www, FTP, telnet Napster, Morpheus Network is computer Web caches have been very successful 16