0% found this document useful (0 votes)
18 views32 pages

Lecture 1

Uploaded by

jam khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views32 pages

Lecture 1

Uploaded by

jam khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Course: Computer Architecture and

Organization
Computer Systems: A Programmer's Perspective by Randal E.
Bryant and David R. O'Halloran, Pearson;
3rd Edition. (2015). ISBN-13:978-0134092669, ISBN-
10:013409266.
Introduction to Computer systems
Information Is Bits

Figure 1.1 The hello program.


Information Is Bits
 hello program begins life as a source program (or source file).
 That the programmer creates with an editor and saves in a text file called
hello.c.
 The source program is a sequence of bits, each with a value of 0 or 1,
organized in 8-bit chunks called bytes.
 Each byte represents some text character in the program.
 Most computer systems represent text characters using the ASCII standard.
 That represents each character with a unique byte-size integer value.
Information Is Bits
 The hello.c program is stored in a file as a sequence of bytes.
 Each byte has an integer value that corresponds to some character.
 Files such as hello.c that consist exclusively of ASCII characters are known as
text files.
 All other files are known as binary files.
 All information in a system including disk files, programs stored in memory,
user data stored in memory,
 and data transferred across a network is represented as a bunch of bits.
Programs Are Translated by Other Programs into Different Forms
 In order to run hello.c on the system,
 The individual C statements must be translated by other programs into a
sequence of low-level machine-language instructions.
 These instructions are then packaged in a form called an executable object
program and stored as a binary disk file.
 Object programs are also referred to as executable object files.
Programs Are Translated by Other Programs into Different Forms
 On a Unix system, the translation from source file to object file is performed
by a compiler driver:
Programs Are Translated by Other Programs into Different Forms
 Here, the gcc compiler driver reads the source file hello.c and translates it
into an executable object file hello.
 The translation is performed in the sequence of four phases.
 The programs that perform the four phases (preprocessor, compiler,
assembler, and linker)
 are known collectively as the compilation system.
Programs Are Translated by Other Programs into Different Forms
Preprocessing phase
 The preprocessor (cpp) modifies the original C program according to
directives that begin with the ‘#’ character.
 #include <stdio.h> tells the preprocessor to read the contents of the system
header file stdio.h
 and insert it directly into the program text.
 The result is another C program, typically with the .i suffix (hello.i).
Programs Are Translated by Other Programs into Different Forms
Compilation phase.
 The compiler (cc1) translates the text file hello.i into the text file hello.s,
 Which contains an assembly-language program.
 Assembly language is useful because it provides a common output language
for different compilers for different high-level languages.
 For example, C compilers and Fortran compilers both generate output files in
the same assembly language.
Programs Are Translated by Other Programs into Different Forms
Assembly phase
 Next, the assembler (as) translates hello.s into machine language
instructions,
 Packages them in a form known as a relocatable object program,
 and stores the result in the object file hello.o. This file is a binary.
Programs Are Translated by Other Programs into Different Forms
Linking phase
 Notice that our hello program calls the printf function,
 Which is part of the standard C library provided by every C compiler.
 The printf function resides in a separate precompiled object file called
printf.o,
 Which must somehow be merged with our hello.o program.
 The linker (ld) handles this merging. The result is the hello file,
 Which is an executable object file (or simply executable)
 That is ready to be loaded into memory and executed by the system.
Processors Read and Interpret Instructions Stored in Memory
 To run the executable file on a Unix system, we type its name to an
application program known as a shell:
linux> ./hello
hello, world
linux>
 The shell is a command-line interpreter that prints a prompt, waits for you to
type a command line, and then performs the command.
 If the first word of the command line does not correspond to a built-in shell
command.
Processors Read and Interpret Instructions Stored in Memory
 Then the shell assumes that it is the name of an executable file that it should
load and run.
 So in this case, the shell loads and runs the hello program and then waits for
it to terminate.
 The hello program prints its message to the screen and then terminates.
 The shell then prints a prompt and waits for the next input command line.
Hardware Organization of a System
 To understand what happens to our hello program when we run it,
 We need to understand the hardware organization of a typical system, which
is shown in Figure 1.4.
 This particular picture is modeled after the family of recent Intel systems,
 But all systems have a similar look and feel.
Hardware Organization of a System
Hardware Organization of a System
Buses
 Running throughout the system is a collection of electrical conduits called
buses.
 That carry bytes of information back and forth between the components.
 Buses are typically designed to transfer fixed-size chunks of bytes known as
words.
 The number of bytes in a word (the word size) is a fundamental system
parameter that varies across systems.
 Most machines today have word sizes of either 4 bytes (32 bits) or 8 bytes (64
bits).
Hardware Organization of a System
I/O Devices
 Input/output (I/O) devices are the system’s connection to the external world.
 Our example system has four I/O devices: a keyboard and mouse for user
input,
 a display for user output, and a disk drive (or simply disk) for long-term
storage of data and programs.
 Initially, the executable hello program resides on the disk.
 Each I/O device is connected to the I/O bus by either a controller or an
adapter.
Hardware Organization of a System
Main Memory
 The main memory is a temporary storage device that holds both a program
and the data it manipulates,
 While the processor is executing the program.
 Physically, main memory consists of a collection of dynamic random access
memory (DRAM) chips.
 Logically, memory is organized as a linear array of bytes, each with its own
unique address (array index) starting at zero.
Hardware Organization of a System
Processor
 The central processing unit (CPU) is the engine that interprets (or executes)
instructions stored in main memory.
 At its core is a word-size storage device (or register) called the program
counter (PC).
 At any point in time, the PC points at (contains the address of) some
machine-language instruction in main memory.
Hardware Organization of a System
Processor
 Processor executes the instruction pointed at by the PC and updates the PC
to point to the next instruction.
 The register file is a small storage device that consists of a collection of
word-size registers, each with its own unique name.
Running the hello Program
 Initially, the shell program is executing its instructions, waiting for us to
type a command.
 As we type the characters ./hello at the keyboard,
 The shell program reads each one into a register and then stores it in
memory, as shown in Figure 1.5.
 When we hit the enter key on the keyboard, The shell then loads the
executable hello file.
 By executing a sequence of instructions that copies the code and data in
the hello object file from disk to main memory.
Running the hello Program
Running the hello Program
 Once the code and data in the hello object file are loaded into memory,
 The processor begins executing the machine-language instructions in the
hello program’s main routine.
 These instructions copy the bytes in the hello, world\n string from memory
to the register file,
 and from there to the display device, where they are displayed on the
screen.
Caches Matter
 Because of physical laws, larger storage devices are slower than smaller
storage devices.
 And faster devices are more expensive to build than their slower
counterparts.
 For example, the disk drive on a typical system might be 1,000 times larger
than the main memory.
 But it might take the processor 10,000,000 times longer to read a word
from disk than from memory.
Caches Matter
 Similarly, a typical register file stores only a few hundred bytes of
information.
 As opposed to billions of bytes in the main memory.
 However, the processor can read data from the register file almost 100
times faster than from memory.
 To deal with the processor–memory gap,
 System designers include smaller, faster storage devices called cache
memories (or simply caches).
Caches Matter
 That serve as temporary staging areas for information that the processor is
likely to need in the near future.
 Figure 1.8 shows the cache memories in a typical system.
Caches Matter
 An L1 cache on the processor chip holds tens of thousands of bytes and
can be accessed nearly as fast as the register file.
 A larger L2 cache with hundreds of thousands to millions of bytes is
connected to the processor by a special bus.
 It might take 5 times longer for the processor to access the L2 cache than
the L1 cache,
 But this is still 5 to 10 times faster than accessing the main memory.
 The L1 and L2 caches are implemented with a hardware technology known
as static random access memory (SRAM).
Caches Matter
 Newer and more powerful systems even have three levels of cache: L1, L2,
and L3.
 By setting up caches to hold data that are likely to be accessed often,
 We can perform most memory operations using the fast caches.
Storage Devices Form a Hierarchy
 The storage devices in every computer system are organized as a memory
hierarchy similar to Figure 1.9.
Storage Devices Form a Hierarchy
 As we move from the top of the hierarchy to the bottom,
 The devices become slower, larger, and less costly per byte.
 The register file occupies the top level in the hierarchy, which is known as
level 0 or L0.
 We show three levels of caching L1 to L3, occupying memory hierarchy
levels 1 to 3.
 Main memory occupies level 4, and so on.
 The main idea of a memory hierarchy is that storage at one level serves as a
cache for storage at the next lower level.
Storage Devices Form a Hierarchy
 Thus, the register file is a cache for the L1 cache.
 Caches L1 and L2 are caches for L2 and L3, respectively.
 The L3 cache is a cache for the main memory, which is a cache for the disk.

You might also like