notes logic gate

Upload: vishal-paupiah

Post on 03-Jun-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Notes Logic Gate

    1/25

    Chapter 2: Overview of Digital Logic

    Digital Computers use discrete values represented with a finite number of

    digits - cannot represent irrational or repeating numbers this way.Binary numbers as used to represent data. (base 2)Digital Logic

    -allows physical components it process and remember information. -laws and operations that manipulate information !Boolean algebra

    2.1 The BuildingBlocks

    Boolean algebra works with true/false values (variables)Logic gates are operators for Boolean algebraTruth Tablesdescribe outputs for given input.

    2.2 Basic Boolean Operations

    COS 140 Text Notes

    NOT AND(Both Statements True)

    Or [Inclusive](One or Both True)

  • 8/12/2019 Notes Logic Gate

    2/25

    Because AND and ORtake two inputs, they arecalled a binary operators;

    NOT, in contrast, is aunary operator.

    2.3 Writing Boolean ExpressionsIn this book, we will usually use + or _ for or, juxtaposition or ^ for and, anda line over the variable or expression for not.

    2.5 Other Gates

    NAND

    At least one of the two variables arefalse.

    "NOT AND"

    *ActuallyNOR

    True whenever OR would be false.

    "NOT OR"

    XOR

    Exclusive OR

    The output of this gate is true whenone or the other, but not both, of its

    inputs is true.

    We can use xor to make an equalityfunction simply by negating it.

    NAND or NOR are themselves sufficient to be the basis of digital logic.

    2.6 Truth Tables Revisited

    Include all possible combinations of inputs.

    As with the more familiar base 10, the least significant digit is on theright, while the most significant is on the left. The least significant digitvaries the fastest.

    With n inputs, there will be 2n rows. - exponential growth

    COS 140 Text Notes

  • 8/12/2019 Notes Logic Gate

    3/25

    2.6 Creating Functions with Boolean OperatorsBoolean functions can be created by putting Boolean operators together.

    To write the function, we must consider the statement of the problem. We will take an

    umbrella (U = 1) if either or both of the following conditions are true: (1) it is raining (R= 1); or (2) both the weatherman predicted rain (W = 1) and it is cloudy (C = 1).

    U = R OR (W AND C) or, in symbols: U = R or (W and C) U = R _ (W ^ C)

    2.8 Abstraction

    Abstraction is used to hide details that wouldotherwise get in the way. We say that the detailshave been abstracted away.

    Chapter 3: Boolean Algebra

    Two circuits are functionally equivalentif, inevery case, they produce the same output giventhe same inputs.

    3.3 ReviewNOT has precedence over

    anything else, followed by AND,then OR and XOR.

    3.4 Equivalence with Truth TablesShow that for all inputs the functions havethe same outputs.

    3.5 Proving Equivalence UsingAlgebraic SubstitutionWe can't use truth tables if we dont know what we want to prove

    equivalence to, as when we want to simplify an expression.

    Substitute one expression for another, equivalent one, using the laws ofBoolean algebra.

    COS 140 Text Notes

    User View

    Assembly Language

    Machine Code Level

    Firmware

    CPU, memory input/output

    ALU, Control Unit, Register, ect.

    Functional Units

    Gates

    Electronic

    Quantum (Subatomic) Order of Operations

  • 8/12/2019 Notes Logic Gate

    4/25

    3.5.1 Laws of Boolean Algebra

    AND version and OR version most

    laws.

    Each step in your proof will need tobe justified by a law of Booleanalgebra.

    3.5.4 How to Apply the LawsWe can't use the laws unless theyexpression matches the law's patternexactly.

    Chapter 2: Circuits from FunctionsComputer components(logic circuits) realizefunctions

    Example:50 varieties, 1 a month.

    Truth Table with Dont Cares Let each variety be a uniquepattern of 1s in the input n input lines can represent 2ndifferent patterns

    How many input lines? 6

    64 !50 = 14 unused combinations

    COS 140 Text Notes

    AND VersionOR Version

    ABC

    (AB)C

    XC

    CX

    C(AB)

    CAB

    Given.

    Precedence, definition of ().

    Let X = (AB).

    Commutative Law.

    Substitution for X.

    Precedence, definition of ().

  • 8/12/2019 Notes Logic Gate

    5/25

    Algebraic Expressions for Circuits Don't Cares: dont care whether their

    corresponding outputs are 1 or 0 - leavethese out or mark with symbol (-)

    Gates visited in the order that thesubexpressions are evaluated, as valuestravel along lines

    from input to output (left to right).

    Programmable Logic Array(PLA) is achip designed with NOT, AND, and OR

    gates so it can handle arbitrary SOPexpressions.

    A subarray of ANDs creates product termsfrom the inputs.

    A subarray of ORs takes input from the ANDsand creates outputs.

    4.4 Creating Boolean Expressions from Truth Tables

    Do this by creating a sum of products (SOP)

    expression from the truth table. This is a Boolean expression inwhich there are one or more expressions, or terms, consistinginputs or their negations ANDed together (the products), all

    joined by ORs (the sum). From the SOP expression, wecan create the circuit diagram in a straightforward way. The terms in our SOP expression will correspond to rows in the truthtable for which the output is 1. The circuit should produce a 1 whenever any ofthese terms produce a 1, so these terms will be ORed together. So, for the

    truth table shown in Figure 4.8, there will be three terms, one for each row witha 1 as output. This is shown in the truth table in the column to the right of theoutput (F). The resulting expression is just these termsthe only cases whenthe function is trueORed together.Another way of thinking of this would bethat the term is true when A = 1 and B = 1 and C = 1.

    COS 140 Text Notes

    SOP:

    Fuses marked xare blown.

  • 8/12/2019 Notes Logic Gate

    6/25

  • 8/12/2019 Notes Logic Gate

    7/25

    Circle groups of 1s that are size of 2 to some power(1, 2, 4, 8, etc.) untilall 1s have been circled

    Not necessary to circle groups of size 1 but they must be includedas terms in the resulting expression.

    Circle the largest group possible to cover each 1

    Only circle groups of 1s that are size 2^n.

    Circles can wrap aroundthe map.

    A 1 can be included in more than one group.

    There must always be at least one 1 in each group that isnot included in other groups.

    Minimized value from a map:one term for each of the circles. For eachcircle, a variable will participate in the corresponding term if and only if itsvalue is the same for all cells that have been circled. A variable canparticipate either as it- self or as itself negated.

    If two terms differ in only one variableand its complementthat is, thevariable is positive in one term and negative in the otherthen the value ofthe variable does not contribute anything to the functions value and can beomitted.

    Gray code - elements differ from their neighbors byat most one value. 00, 01, 11, 10

    Chapter 6: Adders

    Combinational Circuits -outputs determined by the current state of its inputs

    Adder - a circuit that computes the sum of binarynumbers

    Two input bits are added together to produce a sum

    bit plus a carry out bit. For example, if A=1 and B=1,then the sum,1021would be represented as S=0 and carry out = 1.

    S - low-order (least-significant) C - high-order (most-significant)

    Half - Adder - adds, but no carry-in bit.

    Binary: Base two, from right.

    COS 140 Text Notes

  • 8/12/2019 Notes Logic Gate

    8/25

    Chapter 7: Parallel Registers

    Registers are fast, basic, memory used in the CPU and other places. They

    store several bits in parallel, contents don't change until the Data Readyline is set high (1). Sometimes the registers contents are not immediatelyplaced on the output lines: the register might have another input line that,when it is high, will cause the registers to output.

    Sequential Circuits:circuits that canremember their past states, and onlychange their state for some values oftheir inputs.

    SR Latch:An SR latch is one that can beset (i.e., its state = 1) or reset (state = 0) byits input lines, and it will hold that state aslong as desired.

    A latchis a circuit that for some values

    of its input lines changes its state, andthen it holds, or latches, that value untilthere is another particular pattern of itsinput lines.

    Latches and Flip-Flops: building blocks of

    registers. They have input and output lines.They also often have another input line thatdetermines when the data lines are gatedinto the device.

    Note there is feedback: some of the outputs (both in this case) feed backinto the inputs to the circuit.This is how the current state reflects the future

    state of the device.

    In order to analyze a sequential circuitwe use a characteristic table. This

    has columns for the input, and ainstead of a output column it has acolumn representing its next state,given its current state and its input(s).

    Race Condition: When the answerdepends on which gate is faster andcannot in general be predicted.

    COS 140 Text Notes

    Oscillating, Unstable

  • 8/12/2019 Notes Logic Gate

    9/25

    Chapter 10:RAID: Redundant Array of Independent Disks

    - its important to have a reliable memory system so as many requests can

    be processed as possible

    Magnetic Disk Storage - Direct Access -data has address but is not RAM

    Primitive Unit of a disk - sector(512bytes)

    Access time=Seek time+Rotational latency-not constant timing, like RAM

    Arm with read/write head- moving it is 'seek time'

    Rotational latency:time for the disk to rotateto position the right sector under the head

    Constant angular velocity: disk spins at constant speed so data is moredense near center

    Type of Disks: Closer the head narrower head can be narrower tracks

    head gets to surface increased chance of errors (ex. dust)

    Standard disks: head flof air does not come i

    ats on a cushioncontact

    Floppy: head touches the disk whenreading and writing

    Winchester: in sealed nit so head can ge closer to the disk - no contaminants

    ContradictEach Other,

    !Transfer capacity - how much data can be read from orwritten to the disk in a given amount of time

    . .order, slowerrequest rate

    !I/O request rate- how many reads or writes can beaccomplished in a given amount of time

    RAID - we have several disks in an array.Need to know levels of RAID

    Logical Disk -

    abstraction

    Divide data into segments called strips.

    Place strips on disks in ato disk 2...)

    round-robin fashion (first strip to disk 1, second

    A stripe is all of the strip at the same location on all of the disks.

    COS 140 Text Notes

  • 8/12/2019 Notes Logic Gate

    10/25

  • 8/12/2019 Notes Logic Gate

    11/25

  • 8/12/2019 Notes Logic Gate

    12/25

  • 8/12/2019 Notes Logic Gate

    13/25

    Parity Bits- used to detect errors. Some RAIDlevels use parity bits to detect errors.

    Parity bits record whether the data has an odd or an

    even number of 1s in it: i.e., its parity. We add an extrabitthe parity bitto the data and force the combinedparity of the data plus the parity bit to be either odd oreven by setting the parity bit to be either 0 or 1.

    When read data, make sure that the parity matches given. If not, know that have an error in the data or the parity bit. In general, dont know where the error is Parity Bits can't detect even numbers of errors - says its all good

    RAID 3

    Strips are very small. The discs are synchronized Uses parity bits stored on parity disc

    The parity byte is computed by taking the parity ofeach of the bits on the other drives.

    Increased transfer speed because ofsmall strips.

    Bottleneck: the parity disk. This disk has to be readeach time other disks are read. Detects single-bit errors.

    If a disk does not provide a strip, that strips data bitsdata bits and the parity bits. Allows the RAID array t

    can be reconstructed from the remainingcontinue even when one disk has failed.

    The cost of RAID 3 is minimal, only an additional disspace is devoted to parity and thus lost to overh

    k drive is needed. So 1/n of the total diskead, where n is the number of disks.

    RAID 4

    parity is computed for the bits in each stripe, and theparity bits are stored on a dedicated parity drive strips much large than in RAID 3

    The drives do not have to be synchronized to all accThis RAID is an independent access array. Multiple dthus speeding up I/O r

    ess the same addresses simultaneously.rives can simultaneously satisfy requests,quest rate.

    Increased Reliability, Transfer rate in unaffected. Cost is same as RAID 3

    To write a block, however, the old parity strip must bthen written. Consequently, the parity drive b

    e read first, modified with the new parity,ecomes a bottleneck for RAID 4.

    RAID 5

    attempts to get rid of RAID 4 bottleneck same strip size, no dedicated parity drive

    Parity blocks for stripes are distributed acrsimultaneously, with parity info

    ss the drives. Multiple requests can be handledrmation coming from multiple disks.

    Similar benefits and costs to RAID 4

    Sign-Magnitude Representation:

    Magnitude is the absolute valueof the number.

    Sign bit is 0 if the number is positive and 1 if not.

    Problem: Two ways to represent 0, 00000000 and 10000000.

    COS 140 Text Notes

    Round Robin Striping

  • 8/12/2019 Notes Logic Gate

    14/25

    Twos complement representation:

    Positive number looks exactly like its sign-magnitude form.

    Negative numbers, however, are represented in what is known as the twos

    complement of the numbers absolute value.

    The twos complement of a number is formed byfirst taking the ones complement.

    (switching zeros and ones)

    Ex: the ones complement of00111111 (6310) is 11000000.

    Then the twos complement of the number isformed by adding 1 to the ones complement.

    Ex, 00111111 would be1+11000000 = 11000001.

    A number plus its twos complement add to 0.

    To find value of two's complement number:

    high-order bit is 0, convert from binary

    high-order bit is 1 take the twos complement to find the absolute value, and negate

    it.The twos complement of a numbers twos complement

    is the number itself.

    Booth's Algorithm analgorithm underlying computer-based multiplication

    Suppose we have the number:01111100111100002

    Using Booths algorithm: (215-210)+(28- 24) = (32,768 - 1024)+(256 - 16)=31 984

    3*4=0011*1110=0011*(24 - 21)= (0011* 24) -(0011* 21) =00110000-00110=101010 = 4210

    A block of k 1s, starting at bit n of the number,is: 2n+2n-1+2n-2+...+2n-k+1

    Booth's Algorithm Cycles of shifting, or additio or subtracting and shifting.

    Compare least significant bit of column Q with the content of column Q-1

    Least Significant of Q ismatches Q-1, just shift.

    Least Significant of Q is 0,Q-1 is 1, Add M

    Least significant of Q is 1,Q-1 is 0, Add -M

    http://www.youtube.com/wat h?v=MklsYxdukNw

    COS 140 Text Notes

    8 - Bit Representationof a Non-Negative

    Binary Number

    1 1 1 1 1 1 1 1

    Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0

    http://www.youtube.com/watch?v=MklsYxdukNwhttp://www.youtube.com/watch?v=MklsYxdukNw
  • 8/12/2019 Notes Logic Gate

    15/25

    Architecture - how a computer, or part of a computer is organized

    Assembly Language: low level language used to control CPU

    A Von Neumann computeris a stored program computer,

    which means that its programs and data are stored inmemory. A program can write data to be executed ascode; or program can be examined by anotherprogram as data. Von Neumann machines alsohave a single thread of control.

    They are doing one instruction at a time.

    fetch an instruction from memory > decode it > execute it

    CPU: where programs are actually carried out; where computations take place; allinformation that flows between the memory and the I/O either goes through the CPU oris controlled by it. Composed of connected functional. There is an arithmetic logic unit(ALU) that actually carries out computations. There are registers, which are high-speed

    memory for CPU operations. There is a control unit in charge of fetching andinterpreting instructions and causing the rest ofthe CPU to carry out the right tasks.

    Memory:internal storage or external.

    Internal storage:in CPU or onmotherboard. (CPU registers, cache, RAM)

    External storage: memory accessed as input/output by the CPU (discs, harddrives, flash drives ect.)

    Although computers can operate on bytes, most operations and most memoryaccesses are in terms of larger units of memory called words.

    The size of a wordis CPU-dependent and has to do with the width of (i.e., number ofbits in) the data bus,which defines the basic unit of memory access. same size as itsdata bus. Thus a 32-bit machine can address directly 232bytes.

    Some memory can only beaccessed sequentially: to access byte n, all bytes from 0 ton-1 must first be accessed. Some memory is random access: each unit of storage hasa unique addressand can be directly accessed. Access time is constant with RAM.

    In between these extremes is direct access. In direct access, an address is used to getto a general location in the storage device, then sequential search begins from there.

    Disks use have this property. Disks are laid out with data in concentric rings known as

    tracks. Each track is divided into sectorscontaining data. access time, then, is notconstant, but rather a function of how long it takes to get the head to the right track (theseek time) and for the right sector to come underneath the head (the rotation delay).

    COS 140 Text Notes

  • 8/12/2019 Notes Logic Gate

    16/25

    Associative access: finds info in memory based on the information itself. Each word ofan associative memory has some additional bits that are set based on the information inthe word. These bits are a key: they uniquely identify the memory location.

    Registers are used wherever speed is paramount and cost is no consideration, sinceregisters are expensive relative to other memory types.

    Cache: any kind of memory where a portion of the information in a slower kind ofmemory is stored to increase speed. i.e. Disk cache. Cache is not as expensive asregisters, but it is still expensive.

    Data on external storage is cached in main memory. Data inmain memory is cached in cache. Data in the cache is cached in registers.

    Locality of reference: data or memory locations that are used are likely to be usedagain soon. Caching can often be enhanced by speculatively caching memorylocations: when there is a reference to a memory location, the CPU may bring in thatlocation to cache along with some of its surrounding locations. If there is locality ofreference, then the chances are good that the next location will already be in the cache.

    CPU and memory are the central portion of the computer, I/O devices are peripheral

    Secondary storage devices:CD-ROMdrives, DVD drives

    Interactive input devices:keyboards,mice, tablets, touchscreens, etc.

    Display devices: displays, printers,virtual walls, caves (in which all surfacesof a room function as display devices),

    and multi-touch

    I/O device = peripheral device: any pieceof hardware to which the memory or CPUsend data and from which they receive it.

    Network interfaces:allow the computerto communicate, Ethernet interfaces, Wi-

    Fi hardware, and modems.

    Sensors:any device that can translate signals in the external world into data for the

    computer to process. Ex. thermometers, battery charge sensors, fingerprint readers,sonar for land robots, and cameras.

    Effectors: device that the computer can use to take action in the real world. Examplesinclude the wheels on a land robot, robot arms, and the thrusters on an UAV.

    I/O devices vary in their speed of access and access method. Some devices are purelysequential, i.e. keyboard, others are direct access, i.e. hard drives.

    COS 140 Text Notes

    Main memory =RAM(random-access memory):

    cheap, fast memory.

    External memoryis cheaperstill, which translates to morestorage capacity per dollar.

  • 8/12/2019 Notes Logic Gate

    17/25

  • 8/12/2019 Notes Logic Gate

    18/25

    assembly language: a more abstract language made torepresent machine language.

    Machine language can be entered into the computers

    memory for execution. Assembly language programmust first be translated into machine language, orassembled, by another program, the assembler.

    Assembly language is still a low-level language.

    high-level languages: bridge gap between CPU andhuman language

    High-level languages are compiled to assembly ormachinelanguage by a compiler, or they are interpretedby an interpreterthat reads them and carries out theprogram.

    Packed decimal:nibble (four-bit chunk) of a byte stores abinary number representing the decimal digits 09.

    Advantage: decimal numbers, even non-integers, can bestored. Unfortunately, arithmetic is made more difficult.

    Floating point numbers: subset of real numbers.

    Each character is encoded as a unique binary string. Avery common encoding scheme is ASCII(AmericanStandard Code for Information Interchange), in whicheach character is encoded by a single byte.

    2-byte Unicode representation:65,536 characters canbe represented enough for any human natural language.

    String: data type for strings of characters. Not basichardware data types, but defined by the programminglanguage.

    CPUs deal with logical data. A basic data type is the logical Boolean, which is one bit.

    Most CPU instructions are: data transfer, arithmetic, logical, control transfer, and system control.

    Data transfer instructions:used to move data from place to place within the computer.A data transfer instruction needs operands that describe the source and the destination

    of the data to be moved.

    Arithmetic instructions: do mathematical operations on data in the ALU or memory.

    An arithmetic shiftinstruction shifts all bits in a register or memory location tothe left or right. If it shifting to the left, then the new low-order bit is set to 0. If it isshifting to the right, then the new high-order bit is kept the same.

    Rotateinstructions are similar, except that the bit that is shifted out of the word isused as the new bit.

    COS 140 Text Notes

  • 8/12/2019 Notes Logic Gate

    19/25

    Masking: way to check a bit by isolating it using logical operations. A mask is applied tothe register to clear all of the bits other than the one we are interested in. At that point,we can see if the register contains binary 0if it does, then the bit was 0, else it was 1.

    One type of control transfer instruction is the branchorjumpinstruction. These can beunconditional or conditional. Often, unconditional jumps are called jumps, whilebranches are those that are conditional.

    An absolute jumpspecifies the target by an operand that represents the address. Arelative jump has an operand that is taken to be an offset from the current instruction.

    Subroutines:piece of code that can be used by the rest of the program, or even otherprograms, to perform some function. CPUs provide instructions to transfer control to asubroutine and to return control when the subroutine is finished to the calling program.The first is sometimes calledjumping to a subroutine, but most often called callingthe subroutine. The latter is called returning from the subroutine.

    A stackis a data structure that functions somewhat like a stack of paper. This is calledlast in, first out (LIFO) access. It is a good LIFO way to represent recency; the mostrecently-used piece of paper is on top.

    System control instructions: have to do with accessing or controlling CPU resources.These instructions are often protected, so some programs can't use them. CPUs usuallyhave two or more modes they can be in, with some levels having more rights thanothers. The operating system runs in the highest, most capable level. This is usuallycalled kernelmode, since it is the mode in which the OS kernel runs. This allows theoperating system, to limit what user programs have access to. System control

    instructions often are used to access protected registers or protected memory. The CPUcan mark a region of memory for no access or read only.

    Input/output instructions are usually protected and only executable in kernel mode. Thisprevents overwriting by multiple programs.

    Addressing modes: ways in which an operand in an instruction can specify where thedata is that is to be operated on, or where data is to be stored.

    Immediate addressing mode:the operand is contained within the instruction itself.One advantage is that there is no additional memory reference needed.

    LD R3,#23 Sharp sign denotes immediate mode operand, in this case 2310. The machine

    code for this instruction would be:

    COS 140 Text Notes

  • 8/12/2019 Notes Logic Gate

    20/25

    Register addressing mode:an operand is contained in a register, or a register is thetarget of an operation.

    Advantage:doesn't need a memory access, since the data is already in the

    register or can be stored to a register. If commonly-used operands are kept in registers,then execution speed increase. RISC machines make heavy use of register addressingand provide large numbers of registers. Advantage:of register addressing is that thereare relatively few registers compared to the number of memory locations, so only a fewbits are needed in the instruction to specify the operand. RISC machines should seek tokeep each instruction the size of a single word in order to speed up the processor.

    Direct addressing mode:used when a CPU needs to be able to retrieve from andstore to memory, and the direct addressing mode is used for this. Here, the operand isthe address of the memory location containing (or to contain) the data.

    Indirect addressing mode:address that contains not data, but the address at whichdata can be found. Increases the flexibility of the instruction set by avoiding having tohard-code addresses into the program. The cost of this flexibility is, in the case ofindirect addressing, an additional memory location and, hence, an additional memoryaccess.

    Register indirect addressing:like indirect addressing, but the indirect operandsaddress is found by looking in a register rather than in a memory location.

    Instructionsare divided into fields, sets of bits that correspond to the opcode, modebits, operands, etc.

    Program status word should be protected from change, since this register reflects thestatus of the processor and ALU operations as determined by the processor itself. Theinstruction counter is also protected. General-purpose registers should be unprotected.

    Debate about the number and kind of instructions a CPU should provide.

    RISC: relatively few and simple instructions, each simple, reduced this philosophy,reduced instruction set computers

    CISC: large number of rather complex instructions, including some very specializedones, called complex instruction set computers

    RISC machines have several advantages. Since there are relatively few instructions,

    its possible to optimize each so they run rapidly. Less complexity means less circuitry,so less space needed on the chip; so more space on the chip for other things. RISCmachines have a lot of registers- the more operations carried out using registers, thefaster the processing, since memory access is slower. Since the CPU is smaller, itscomponents are closer together, and faster. All instructions are the same size, so theentire instruction can be read at once, and often executed within one or a few machinecycles.

    COS 140 Text Notes

  • 8/12/2019 Notes Logic Gate

    21/25

  • 8/12/2019 Notes Logic Gate

    22/25

    Floating point numbers:have a fractional part beyond the decimal(radix) point. Can'trepresent repeating or irrational numbers.

    A problem with ASCIIis that it is an 8-bit code. It can represent only 256 characters.

    Unicodecharacters can be longer than 8 bits, depending on the Unicode form used.

    Strings: non-scalar data type, strings of characters, example of a compound, orcomposite, data type, as they are composed of characters, another primitive type.

    Arrays: composite data type, represent groups of related numbers. Stores dataelements one type, and the data elements are stored together in memory. Arrays havedimensions. A single-dimensional array, a vector, is composed of a set of dataelements that can each be identified by a single index(subscript). Often, the lowerbound of an array index is 0 (that is the first index). This means that the upper boundfor an index, if the array has n elements in that dimension, is n. The starting address ofan array is called the base addressof the array. An array is a random access data

    structure: all elements can be found in the same amount of time.

    Vector- single dimension array

    Address = Base Address + (Index - Lower Bound) * Size

    A = B + ( I - L ) * S

    If we store rows first in a two-dimensional array, this is called row-major order, if westore the columns first, it is called column-major order.

    Label the Indices: x,y,z could be used, but s,r,care most common (slice, row, column)

    Record/ Structure: data type allowing

    multiple kinds of elements to be stored.

    Enumerated type: specifies a set of values a

    variable having the type can contain.List: an ordered set of things, a list is either implemented as an array, or as a (non-primitive) data structure called a linked list, in which each item in the list has associatedwith it a pointer to the next item.

    Setsof things can be represented as arrays, lists, or sequences, but a set is notordered, nor do sets usually allow duplicate members.

    Chapter 17: Process Synchronization: Semaphores

    The problem:synchronizing processes so errors do not occur.Problem if: (1) processes share a resource and (2) need to use the resource in a waythat is incompatible with its simultaneous sharing with others.

    COS 140 Text Notes

    Deadlock: processes waitingfor a resource that is in use.

    Race Condition: processes share a resource; the outcomedepends on the timing or relative speed of the processes.

    Transaction:when a processaccesses shared data.

    Critical region: the part of the program that deals with thetransactions

  • 8/12/2019 Notes Logic Gate

    23/25

    Solution:need to force the clusters of transactions in each process to be executedserially, not in parallel. But, a CPUs instructions are atomic, that is, uninterruptible;everything else is not. But we need critical regions, too, to be atomic. Need to enforcemutual exclusionwith respect to each process critical region: neither process can bein its critical region(its program counter cannot be within the critical region)whilethe other process is within its own critical region.

    How:

    Process synchronization primitives: low level process synchronizationmechanisms. Other more abstract and high-level mechanisms are often built from them.

    Interrupt blocking: Not allowed in user-level processes because it could preventO.S. from needed tasks. Also, if the counter never exits the critical region, say becauseit need to make a CPU call but can't because of the blocks, the process would block thesystem from running anything forever.

    Spin locks:a process voluntarily blocking itself and waiting if it detects other

    processes with a flag. A flag(a lock) is set when a process is in its critical region. Butthe lock itself is a shared resource! So... another race condition. Solution: processorsprovide instructions to allow atomic access to locks, like the test and set lock (TSL)which atomically checks the value of a lock variable then sets it. Problem with the TSL:wasted CPU cycles while processes are waiting and checking the locks.

    Semaphores: to avoid spinning, we need a way for a process to give up theCPU when it is waiting to enter its critical region, and for the operating system not to runthat process again until it can enter its critical region. A semaphore is basically just adata structure and some subroutines.

    Mutex semaphore: simplest kind of semaphore, enforces mutual exclusion.

    When a process wants to enter its critical region, it checks if the semaphore is up (free)or down (in use). If a process calls Down on a semaphore that is already down, then thesemaphore causes the process to block. It is removed from the OSs ready queue andplaced on a queue of processes waiting for the resource, so it is no longer consideredby the scheduler as a possibility to run.

    Counting semaphores:used to keep track of the number of resources availableand to block processes when there is more demand than supply.

    Producerconsumer:there are two processes, one that simply produces items andattempts to put them into a shared location of finite capacity, and another that simplytakes the items out of the location. The location is called a bufferand this problem is aninstance of a bounded-buffer problem. We want the producer to wait when the bufferis full, and we want the consumer to wait when it is empty.

    Event counters:count the kinds of events that have happened to determine if abuffer is full and if a process should block or not.

    Monitor: non-primitive, language level synchronization mechanism.A monitor issomething like an object that surrounds and protects a shared resource. It has methodsthat are the only way to access the shared resource. Monitors only allow a singleprocess to be active at once.

    COS 140 Text Notes

  • 8/12/2019 Notes Logic Gate

    24/25

    Goals of virtual memory (VM): to overcome the memorylimitations of a computer to allow more processes to runsimultaneously (increase the degree of multiprogramming)and to allow large processes to run.

    VM keeps part of the program in memory.

    VM uses the computers disk(s)that is, secondary storageto hold the programs that are running.The CPU cant executedirectly from disk, and disks are slower.

    Run-time stack:is where parameters and returnaddresses get stored when calling subroutines. The gapis an unused portion ofmemory. Data grows upwards as the program runs, while the stack grows downward asthe program calls subroutines

    Virtual Memory - simply bring into memory the portion of a process memory actually inuse, leaving all the rest on disk. As new parts of are needed, they can be brought in,possibly replacing those already in memory. Since only a tiny part of each process is inmemory (is resident) at a time, many more processes can share main memory. Also, thesize of a process is limited only by the address space size or the amount of disk, andthe total number of processes is limited only by the size of disk available.

    In VM,each process has access to all of its address space. This is called the processvirtual memory. Virtual memory is divided into small pages, usually 24 KB in size.These are the units of the process that will be moved into main memory as needed.

    Physical memorythat is, main memory, or RAMis similarly divided into chunks of

    the same size that can hold pages. These are called page frames, since they areholders for pages.

    Demand Paging: pages still on disk are brought into main memory as they are neededby the process.

    COS 140 Text Notes

  • 8/12/2019 Notes Logic Gate

    25/25

    Mutual exclusion:Resource is either available or assigned to at most one process

    Hold-and-wait:Process can hold one resource and then ask for others.

    No preemption:Cant take a resource away from a process once assigned

    Circular wait:!2 processes in circle, each is waiting for resource held by next circle

    Formal language

    Languages do not even have to have anything to do with words. For example, aLindenmayer system, or L-system, is a formal language that is used, among otherthings, for modeling plant growth [?]. Here, the lan- guages grammar specifies how(e.g.) a new branch can bud from an existing one.

    So a language really is about describing a set of things: valid plant growth patterns,search expressions, programs, sentences and sonnets, and so forth. If it is done rightand it may not always be possiblea language specifies those and only those things inthe desired set.

    Note that the set of things we describe with languages are often infinite. This is certainlytrue of natural language and most useful kinds of formal languages.

    All languages have a particular syntax. Syntax refers to the form of something, in thiscase, the value ways the basic units of the languagee.g., words in Englishcan beput together to form larger units, and how those units can be combined, etc. When welearned grammar in elementary school, we were learning the syntax of our native

    language.Computer and human languages also have another attribute that is im- portant:semantics. The semantics of a language is what the meaning of

    COS 140 Text Notes