CHAPTER 2 HARDWARE - PowerPoint PPT Presentation

1 / 52
About This Presentation
Title:

CHAPTER 2 HARDWARE

Description:

Binary is the computer's native language. ... Memory write is a destructive operation. Memory read is not destructive. Memory contents: ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 53
Provided by: HalStr3
Category:

less

Transcript and Presenter's Notes

Title: CHAPTER 2 HARDWARE


1
CHAPTER 2HARDWARE
  • CGS 3763 - Operating System Concepts
  • UCF, Spring 2004

2
OVERVIEW
  • Binary Hex Data Representation
  • Memory Storage Heirarchy
  • Addressing
  • Primary Secondary Memory
  • The disk I/O Mechanism
  • Processor Components
  • Instruction Execution Cycle
  • Program Control Flow The Interrupt Cycle

3
BINARY REPRESENTATION
  • Binary is the computers native language.
  • Binary is a Base 2 numbering system (we represent
    numbers using 2 digits, 0 or 1) wheras our normal
    numbering system is a base 10 system (we
    represent numbers using 10 digits 0-9)
  • Example of a typical binary number 10001010
  • 8-bit binary number representing the decimal
    number 138
  • The computer uses various combinations of 2
    digits to represent letters, numbers, and pixels.
  • NOTE At the hardware level binary digits aren't
    really 1s and 0s. They're actually electrical
    impulses in either a (mostly) on state or a
    (mostly) off state.

4
BINARY REPRESENTATION (cont).
  • With 1 binary digit, we have 2 possible
    combinations
  • 0 or 1.
  • With 2 binary digits, we have 4 possible
    combinations and are able to represent the
    numbers, 0-3.
  • 0 00
  • 1 01
  • 2 10
  • 3 11

5
BINARY REPRESENTATION (cont.)
  • With 4 binary digit, we have 16 possible
    combinations and are able to represent the
    numbers 0 15.
  • 0 0000
  • 1 0001
  • 2 0010
  • 3 0011
  • 4 0100
  • 5 0101
  • 6 0110
  • 7 0111
  • 8 1000
  • 9 1001
  • 10 1010
  • 11 1011
  • 12 1100
  • 13 1101
  • 14 1110
  • 15 1111

6
BINARY REPRESENTATION (cont.)
  • In general, how many different binary values can
    be represented by a specific number of bits?
  • number of different values 2n where n is the
    number of bits .
  • Example
  • We can represent 256 values using 8 bits
  • 256 28
  • Q How many bits does it take to represent the
    value 24?
  • A. lg2(24) lg2(2n )
  • lg2(24) n
  • log(24) / log(2) n
  • n 4.5 ? 5 bits

7
HOW TO READ A BINARY NUMBER
  • Example binary to decimal conversion 10001010

127 026 025 024 123 022
121 020 138
  • Q Convert the binary number 1011 to decimal?
  • A 123 022 121 120 11

8
HEX REPRESENTATION
  • Most modern architectures are either 32 or 64
    bit.
  • If every number we dealt with was 32 or 64 digits
    long, programmers would go nuts!
  • The solution is to represent binary numbers in
    hex.
  • Hex is a base 16 numbering format which means
    that we represent numbers using 16 digits,
    0-9,A-F
  • A hex number is represented with a 0x in front
    of it
  • Example 0xA3 or 0xF0 or 0x46

9
HEX REPRESENTATION
  • Example binary to hex conversion 10001010
  • Break binary number into groups of 4 digits
  • Treat each 4 digit group as an individual binary
    number.

123 121
123
A
8
0x8A
10
HEX CONVERSION (cont.)
  • Q Convert 10110011 into hex?
  • A
  • Break into groups of 4 digits
  • 1011 0011
  • Treat each 4 digit group as an individual binary
    number.
  • 1011 123 022 123 120 0xB
  • 0011 023 022 123 120 0x3
  • Final Answer 0xB3

11
MEMORY
  • Memory holds active programs and data.
  • Memory write is a destructive operation.
  • Memory read is not destructive.
  • Memory contents
  • Numbers count 0 to infinity...
  • In a computer, we can only represent a limited
    subset of them.
  • Bit one binary digit (0 or 1).
  • Byte eight bits (1 character).
  • Word a group of bytes.
  • Word size is usually machine dependent.

12
MEMORY (cont.)
  • Memory can be viewed as a hierarchy based upon
    size .

Words are made up of 1 or more bytes
Bytes are made up of 8 bits
13
ADDRESSING MEMORY
  • Each byte (or word) is assigned a unique address.
  • The bytes (or words) are numbered sequentially.
  • Bytes (or words) are the basic addressable units
    of memory.
  • Because we cannot represent numbers through
    infinity, there is a maximum size number that can
    be represented on any given machine.
  • This number usually corresponds to the maximum
    number of addressable memory units.
  • For example, if we had a 16 bit (2 byte) machine,
    we would only be able to address 216 or 65,536
    bytes of memory (because the 16 bits can only
    make 65,536 unique combinations of 0s and 1s).
  • Data in memory is stored in binary / hex.

14
OVERVIEW TYPES OF MEMORY
  • Registers
  • Main Memory (RAM ROM)
  • Cache
  • Magnetic Disk
  • Optical Disk
  • Magnetic Tape

15
VOLATILE VS. NON-VOLATILE STORAGE
  • Volatile Storage looses its contents when the
    power to the device is removed
  • Examples registers, cache, main memory (RAM)
  • Non-volatile Storage retains its contents when
    the power to the device is removed
  • Examples magnetic disk, optical disk, magnetic
    tape

16
REGISTERS MAIN MEMORY(PRIMARY STORAGE)
  • Registers are high speed, temporary storage
    devices used by the CPU to hold control
    information, data, and intermediate results of
    calculations.
  • Main Memory (RAM ROM)
  • RAM (random access memory) provides moderately
    high speed temporary storage for program code and
    data. It is both readable and writable.
  • ROM (read only memory) provides moderately high
    speed permanent storage for program code and data
  • Often holds the program that loads the operating
    system (BIOS).

17
PRIMARY STORAGE (cont.)
  • Main memory and the processor registers are the
    only storage that the CPU can access directly.
  • Processor instruction set provides instructions
    that allow a programmer to manipulate the
    contents of memory and registers.
  • EXAMPLE
  • mov reg, mem
  • mov mem, reg
  • add reg, reg
  • The processor manipulates data stored in memory
    under the control of a program stored in memory.

18
CACHE
  • Cache is a very fast block of memory that speeds
    up the performance of another device.
  • It is used to hold recently-accessed data.
  • The computer looks in the cache first to see if
    what it needs is there.
  • EXAMPLE
  • Main memory is much slower than the CPU registers
  • A cache may be placed between the processor and
    main memory to speed up data access.
  • If a program needs to load a data value into a
    register using an instruction like mov reg, mem
    the machine first looks to see if it is available
    in the cache before going out to main memory.
  • If the data is present it is termed a cache hit
    and will be loaded directly from the cache.
  • If the data is not present it is termed a cache
    miss and will be loaded from main memory.

19
CACHE RELATIONSHIP WITH THE PROCESSOR MAIN
MEMORY
20
PROBLEM WITH PRIMARY STORAGE
  • PROBLEM
  • Primary memory is both expensive and volatile!
  • Because it is expensive, we may not have enough
    memory to store all of the data we need for a
    program.
  • Quantity is measured in megabytes.
  • Because it is volatile, we have no way to save
    the output of our program.
  • SOLUTION
  • Secondary Storage
  • Provides an extension of main memory.
  • We can move data from the secondary storage to
    main memory on an as needed basis.
  • Inexpensive so we can have lots of storage!
  • Quantity is measured in gigabytes.
  • Non-volatile so we can permanently save data.

21
SECONDARY STORAGE MAGNETIC DISK
  • Magnetic Disks (Hard Disks)
  • Magnetic disks rigid metal or glass platters
    covered with magnetic recording material.
  • Data is recorded on a series of concentric
    circles on the disk surface called tracks. Tracks
    are subdivided into sectors.
  • A sector is the smallest unit of data that can be
    moved between the disk and main memory.
  • Storage Capacity 20 - 400 Gigabytes

22
I/O Disk Head Mechanism
23
CALCULATING DISK CAPACITY
  • A disk has 3 platters. There are 3000 tracks on
    the disk (or 1000 tracks on each platter). Each
    track has 32 sectors and each sector has 512
    bytes.
  • Q How many cylinders are there?
  • A There 3 tracks for every 1 cylinder. Since the
    disk has a total of 3000 tracks, there are 3000/3
    cylinders. The total number of cylinders is
    therefore 1000.

24
CALCULATING DISK CAPACITY (cont.)
  • A disk has 3 platters. There are 3000 tracks on
    the disk (or 1000 tracks on each platter). Each
    track has 32 sectors and each sector has 512
    bytes.
  • Q How many bytes are stored per cylinder?
  • A There 32 sectors 512 bytes 16384 bytes per
    track. Since there are 3 tracks per cylinder, a
    cylinder can store 3 16384 49,152 bytes.

25
CALCULATING DISK CAPACITY (cont.)
  • A disk has 3 platters. There are 3000 tracks on
    the disk (or 1000 tracks on each platter). Each
    track has 32 sectors and each sector has 512
    bytes.
  • Q What is the total storage capacity of the
    disk?
  • A 1 cylinder can store 49,152 bytes and
    previously determined that there are 1000
    cylinders. Therefore, the total disk capacity is
    49,152 bytes 1000 cylinders 49,152,000 bytes

26
Input and Output
  • Input
  • The act of transferring data into memory from a
    peripheral device.
  • Output
  • The act of transferring data from memory to a
    peripheral device.
  • Input and Output
  • Support human interaction with a computer.

27
MAGNETIC DISKS I/O MECHANISM
  • Steps to read a sector from a hard disk.
  • The disk drive is brought up to operating speed.
  • The read-write head is positioned over the track
    that holds the data.
  • The time required to position the head is called
    the seek time.
  • The system waits while the desired sector rotates
    to the read-write head.
  • This wait time is called the rotational delay.
  • The system reads the data.
  • The time required for the system to finish
    reading the data is called the transfer time.
  • The disk service time seek time rotational
    delay transfer time

28
Reading a sector from disk Step 1
The disk drive is brought up to operating speed.
29
Reading a sector from disk Step 2
During seek time, the access mechanism is
positioned over the track that holds the data.
30
Reading a sector from disk Step 3
The system waits while the desired sector rotates
to the read/write head (rotational delay).
31
CALCULATING DISK SERVICE TIME
  • A disk has 3 platters. There are 3000 tracks on
    the disk (or 1000 tracks on each platter). Each
    track has 32 sectors and each sector has 512
    bytes.
  • Q Assume the average seek time is 10 ms. The
    rotation speed is 3600 rpm. It additionally takes
    approximately 2 ms to transfer the data contained
    in 1 sector. How long would you expect it to take
    (on average) to read a block of 10 contiguous
    sectors (5120 bytes)?

32
CALCULATING DISK SERVICE TIME (cont.)
We want to read 10 consecutive sectors starting
here
Step 2 Calculate the rotational delay for the
desired sector to be positioned over the disk
head.
Step 1 Calculate seek time for the disk Head
to be positioned Over the desired track.
Step 3 Calculate rotational delay for the head
to rotate across all 10 of the sectors we wish to
read.
Step 4 Calculate the time to transfer 10
sectors.
Step 5 disk service time seek time total
rotational delay total transfer time for all 10
consecutive sectors
33
CALCULATING DISK SERVICE TIME (cont)
  • A The time required to read 10 contiguous
    sectors will be the seek time rotational delay
    transfer time.
  • The seek time is given as 10 ms.
  • To calculate the rotational delay we must find
    out how long it takes for the disk to make a
    single rotation.
  • 3600 rotations / sec 1 rotation / X sec
  • 3600x 60
  • .0167 sec per rotation
  • We expect that on average it will take ½ rotation
    to get to the first sector we wish to read
  • The rotational latency to the first sector is
    therefore
  • ½ (.0167 sec) .0083 sec 8.3 ms
  • Since we wish to read 10 sectors beyond the
    starting point, we also need to calculate the
    rotational latency to the last sector well be
    reading.
  • 10 sectors / 32 sectors .0167 sec per
    rotation .3125 .0167 5.2ms
  • Lastly, we calculate the transfer time for the 10
    sectors. The time to transfer the data in 1
    sector 2 ms. Therefore, the total transfer time
    is 10 2ms 20 ms.
  • Disk service time 10ms (seek time) 8.3ms
    5.2ms (total rotational delay) 20ms
  • (total transfer time) 43.5ms

34
OTHER STORAGE DEVICES
  • Floppy Disks thin circular piece of flexible
    polyester coated with magnetic material
  • Storage Capacity 1 MB
  • Optical Disks - a flat, circular, plastic disk
    coated with material on which bits may be stored
    in the form of highly reflective areas and
    significantly less reflective areas, from which
    the stored data may be read when illuminated with
    a narrow-beam source, such as a laser diode.
    Usually read only.
  • Storage Capacity 700 MB 4 GB
  • Examples CD, DVD, CD-R, CD-RW
  • Flash Drives a plug-and-play portable storage
    device that uses flash memory. Flash memory
    (sometimes called "flash RAM") is a type of
    constantly-powered nonvolatile memory that can be
    erased and reprogrammed in units of memory called
    blocks.
  • Storage Capacity 32 MB 1 GB
  • Magnetic Tape - A device, like a tape recorder,
    that reads data from and writes it onto a tape.
  • Sequential Access ? slow data access time
  • Used primarily for backup
  • Storage Capacity gt Magnetic Disk

35
THE STORAGE HEIRARCHY
  • Storage systems organized in hierarchy according
    to
  • Speed
  • Cost
  • Volatility

VOLATILE
SPEED
NON VOLATILE
COST
36
SUMMARY DATA CODE PATH
37
WHAT IS A PROGRAM?
  • A program can be defined as a series of
    instructions which tells the computer to perform
    one of its basic functions (i.e. add, subtract,
    multiply, compare, ect.).

Each instruction has an operation code and one or
more operands.
38
PROCESSOR COMPONENTS
39
PROCESSOR COMPONENTS (cont.)
  • Instruction Control Unit (ICU) fetches
    instructions from memory
  • Arithmetic Logic Unit (ALU) holds or activates
    the computers instruction set and executes
    instructions.
  • Registers temporary storage devices that hold
    control information, data, and intermediate
    results.
  • Types of registers
  • Instruction Counter holds the address of the
    instruction currently being executed.
  • Accumulator holds data being used in arithmetic
    calculations (addition, subtraction,
    multiplication, ect.)
  • Clock generates precisely timed electronic
    pulses to synchronize the operation of the other
    components.

40
TRACING A BASIC MACHINE CYCLE
  • Memory holds both program instructions and data.
  • The instruction counter points to the first
    instruction to be executed.

41
TRACING A BASIC MACHINE CYCLE (cont.)
  • The first instruction is fetched from memory and
    stored in the instruction register.
  • Note that the instruction counter points to the
    next instruction.

42
TRACING A BASIC MACHINE CYCLE (cont.)
  • The arithmetic logic unit executes the
    instruction in the instruction register.

43
TRACING A BASIC MACHINE CYCLE (cont.)
  • The instruction counter points to the next
    instruction.

44
TRACING A BASIC MACHINE CYCLE (cont.)
  • The next instruction is fetched into the
    instruction register.
  • Note that the instruction counter points to the
    next instruction.

45
TRACING A BASIC MACHINE CYCLE (cont.)
  • The arithmetic and logic unit executes the
    instruction in the instruction register.

46
INSTRUCTION / EXECUTION CYCLE
  • Modern computers operate using a 2-step cycle
  • Fetch
  • Get next instruction pointed to by the program
    counter
  • Increment the instruction counter
  • Decode the instruction and operands
  • Execute
  • Execute the instruction

An instruction is fetched during I-time and
executed during E-time.
47
FLOW OF EXECUTION
  • Program control flow is usually sequential (ie.
    instructions are executed in order, one at a
    time).

PROGRAM (sequential execution) 1. mov reg, mem 2.
add reg, reg 3. mov mem, reg 4. test reg, reg
  • Non sequential execution may occur because of a
    conditional jump or an interrupt.

PROGRAM (non sequential execution conditional
jmp) 1. mov reg, mem 2. cmp reg, 0 3. jz 8.
//jump to 8. if zero 4. mov reg, mem //otherwise
continue sequentially 5. 6. 7. 8. //execution
resumes here if the test in 2. evaluates to 0 9.
48
CONTROL FLOW VISUALIZATION
  • Some programs can analyze another program and
    give you a visualization of its control flow.
  • Here, IDA Pro generates the control flow graph
    for a function in the Windows kernel.

49
FLOW OF EXECUTION (cont.)
  • Control flow alterations in response to a
    conditional jump instruction occur in response
    to a change in the internal program state
    (weather a status flag evaluates to true or
    false, for example).
  • In contrast, control flow alterations resulting
    from an interrupt occur in response to an
    external event.

50
INTERRUPT CYCLE
  • When interrupts are introduced, the CPU and the
    operating system driving the system, is
    responsible for the suspension of the program
    currently being run, as well as restoring that
    program at the same point before the interrupt
    was detected.
  • Sequence of events the occur following an
    interrupt
  • The CPU drops what its doing and saves its state
    (the values contained in all of its registers).
  • The CPU determines what type of interrupt
    occurred and looks up the address of its handler
    in a special table called the interrupt vector
    table (IVT).
  • Interrupt Vector - a table or array of addresses
    stored in memory which point to each interrupt
    handler.
  • Interrupt Handlers - portions of OS program
    specifically written to deal with each interrupt
    type
  • It then loads the instruction pointer with the
    interrupt handler extracted from the IVT.
  • The CPU executes the code contained at the
    address of the interrupt handler. The interrupt
    handler may disable further interrupts to prevent
    problems with reentrancy.
  • The CPU restores the processor registers to their
    state prior to the interrupt and restarts
    execution in the process that was interrupted.

51
NOTES ABOUT INTERRUPTS
  • Interrupt handlers are provided by the operating
    system.
  • What are some uses for interrupts?
  • How about gracefully handling an error? The
    interrupt handler detects an error and takes
    control before an errant program can corrupt the
    data of itself or another program.
  • How about to detect user input? Consider an input
    device like the keyboard. Most of the time the
    keyboard is idle (no one is typing). Why waste
    CPU cycles constantly checking if there is data
    in the keyboard buffer? Let the keyboard notify
    the OS that there is data available by sending an
    interrupt! When its not receiving interrupts, it
    is free to do other processing.
  • What about to manage the CPU resources among
    multiple programs? The timer interrupt allows
    the OS to periodically gain control of the
    processor and give it to another program. This
    sharing of the CPU gives the illusion of many
    programs running at the same time and is the
    basis of the terms, "multi-tasking",
    "multi-processing, and "multiprogramming".
  • How about calls to the operating system
    interface? System calls use an interrupt to
    transfer control from an application to the
    operating system in a protected manner.

52
?
Write a Comment
User Comments (0)
About PowerShow.com