Flip Flops

Combinational circuit: a circuit in which the output is dependent only on the input values, e.g a single gate

Sequential circuit: a circuit in which the output depends on the input values and the previous output, e.g a flip-flop

Required reading: Stallings 8th edition pg 20-25 (Chapter 20)

The reading can be accessed free at Mr. Stallings” website : http://williamstallings.com/ComputerOrganization/styled-2/

© 2021  Vedesh Kungebeharry. All rights reserved. 

Logic Gates – Formal Introduction

In the previous example we used statements as propositions.  Computer logic is accomplished by using logic gates as building blocks.  A logic gate is a physical circuit which has electrical inputs and usually a single output.

Used in truth tables, we label each input and use truth values to represent weather or not an input is on or off. 

We use the value true , T , 1 to represent on and false , F , 0 to represent off.

Sometimes, On is refered to as a high voltage and off is referred to as a low or no voltage.

The most common gates are shown in the table below:

Gate

AND

OR

NOT

NAND

NOR

XOR

Symbol

AND ANSI Labelled

OR ANSI Labelled

Buffer ANSI Labelled

NAND ANSI Labelled

NOR ANSI Labelled

XOR ANSI Labelled

Inputs

 

A

B

Q=AB

Q=A+B

Q = A

Q= AB

Q=   A+B

Q= A B

0

0

0

0

1

1

1

0

0

1

0

1

1

0

1

1

0

0

1

0

1

0

1

1

1

1

1

0

0

0

 

Description

Outputs 1 when all inputs are 1

Outputs 1 when ANY input is a 1

Inverts the input

Outputs 0 where all inputs are 1

Outputs 1 then both inputs are 0

Outputs 1 when exactly one input is 1

Outputs 0 otherwise

Outputs 0 otherwise

 

Outputs 1 otherwise

Outputs 0 otherwise

Outputs 0 otherwise

Typing the mathematical notation into most word processors can be challenging. Sometimes these worded expressions or symbols are used :

GateWorded expressionSymbol Expression
ANDA AND BA^B
ORA OR BA v B
NOTNOT A~A
NANDNOT( A AND B) ~(A^B)
NORNOT (A OR B)~(A v B)
XORA XOR BA B

© 2021  Vedesh Kungebeharry. All rights reserved. 

Logic Gates

Logic gates are electronic combinational circuits which contain one or more electrical inputs and usually one output.

A combinational circuit’s output depends on the state of it’s inputs.

We use truth tables to document the  behaviour of a logic gates.

In class demonstration

Demonstrate an AND gate and describe with a truth table and in words

(Teacher constructs the truth table from description for a 2 input and a 3 input gate)

An AND gate’s  output is true only when both inputs are true”

Homework/In class exercise

Draw the truth table for  the following gates

  1. AND
  2. OR
  3. NOT
  4. ExOR
  5. NAND

Describe their outputs or mode of operation using a well formed sentence in English. E.g “An AND gate’s  output is true only when both inputs are true”

© 2021  Vedesh Kungebeharry. All rights reserved. 

Truth Tables – An application of abstraction to physical circuits to arrive at their logical nature

Warning: I wrote to following paper to maintain a high level of precision when considered  formally under the disciplines of mathematical logic and computer science. This allows for the proper consideration of semantics in future discussions. 

This writing may lead you to believe that you are taken along a platitude of truism devoid of axiomatic purpose that amounts to a march of banality unrivaled in the history of human thought.

Let us begin.

Definition :  A truth table lists  all possible unique inputs to a logic function accompanied by each output value.

A truth table uses the veracity of propositions. Veracity refers to truthfulness, whether the statement is true or false.   A proposition is a statement.

e.g.      let P be the proposition ‘it is raining’.   

            We can assign 2 values to P.  That is,    

P = truemeaning that ‘the statement P is true’
P = falsemeaning ‘the statement P is false.

NOTE:  We can use the following symbols for truth values:

VALUESYMBOL
TrueTrue,  T, 1
FalseFalse, F, 0

In the above example, the proposition for P can be written as the following table:

P
True
False

Note, the proposition has no meaning when taken by itself. Here we only see the possible circumstances described by the statement as it can be used as an input to a logical scenario or taken s the output of a scenario.

I now introduce…

Truth tables in computer science

In this context, Truth tables  can be used to represent the voltages that are applied as input to a circuit and the resulting output.

Though it may seem trivial, we consider a simple circuit with one input or switch , a battery, and a one output or lightbulb:

Simple circuit diagram

Approaching this physical construct of discrete possible events using mathematical logic we say:

Let the input be called I , and we use the convention that a value of 1 means that a high voltage is applied to the bulb and a 0 being the falsehood of “a high voltage is applied to the bulb ” or rather we can say a high voltage is not applied to the bulb or simply no voltage is applied to the bulb.

Another school as thought would describe I having a value 1 as the switch is on and I having a value of 0 as the switch is off.

Let the output of the circuit be O using the convention that a value of 1 means that the bulb is lit and a value of 0 means the falsehood of “the bulb is lit” or rather we can say the bulb is not lit or simply the bulb is unlit.

Yet another school of thought would describe O having a value of 1 as a high voltage was observed at the output and O having a value of 0 as low or no voltage observed at the output

Now we are ready to consider these discrete events devoid of timing to form an enumeration or superposition of sorts that is a truth table.

We arrive at the following truth table which list all possible inputs to the “circuit” and the observed outputs:

IO
11
00

This table tells us,

For an input of 1:

  • If a high voltage is applied to the bulb , the bulb is lit
  • If a high voltage is applied to the bulb then the statement “the bulb is lit” is True
  • If a high voltage is applied to the bulb , a high voltage was observed at the output.
  • If the switch is on, the bulb is lit

For an input of 0

  • If a high voltage is not applied to the bulb, the bulb is unlit
  • If no voltage is applied to the bulb, then the statement “the bulb is lit” is False
  • If no voltage is applied to the bulb , low or voltage was observed at the output.
  • If the switch is off, the bulb is unlit.

Our truth table allows for us to perform an abstraction on our circuit so that we no longer consider the events that physically occur in the circuit, rather the ideas on how the circuit’s output behaves given discrete inputs.

We no longer care about how the circuit is physically implemented; rather we only consider the logical implications of using the particular type of circuit as a building block in other circuits.

Thank you for reaching the end of this paper.

Attributions to media used in this post:

يحيى بن علي, CC BY-SA 4.0, via Wikimedia Commons

© 2021  Vedesh Kungebeharry. All rights reserved. 

Scheduling Algorithms

First Come First Serve or Non-pre-emptive Scheduling.

The CPU can run processes in the process queue (in  ready state) one at a time for a  “burst” at a time in a first come first serve fashion.  This is known as non pre-emptive scheduling, since no determination is made into the most efficient order to run processes on the CPU.

It should be noted that the amount of time that a process might stay on the CPU could be very long when compared to others in the queue. This is because a “burst” might  a sequence of CPU and IO instructions the process executes without interruption form the CPU scheduling algorithm .  The process is only moved from execution on the CPU when a I/O operation occurs that causes the process to be put in wait mode, or, it terminates.

Having other processes wait exceedingly long is not desirable, and todays modern operating systems do not implement FCFS. 

FCFS scheduling does have the advantage of being easier to program and implement; but this advantage does not outweigh the performance of an efficient process scheduler.

FCFS scheduling is also prone to race conditions, where 2 processes need to read from the same section in memory and end up producing inconsistent data.  See here for a good explanation:

https://stackoverflow.com/questions/3130079/difference-between-racearound-condition-and-deadlock

Shortest Job First or Pre-Emptive scheduling

This scheduling algorithm examines each process to determine the length of time that is needed for on the CPU.  The algorithm then places processes with the shortest estimated time to be executed as priority.

Round Robin Scheduling

This is very similar to FCFS scheduling , only this time each process is given a fixed maximum time to be executed on the CPU.  If the process exceeds the time, it is put in wait mode and added to the end of the queue.

© 2021  Vedesh Kungebeharry. All rights reserved. 

Strategy For Storing Records In Plaintext Files

Introduction

Previously we have seen an implementation for a library catalog ( Mini IA Example – A library catalog). That implementation used binary files.

In this class video, we anticipate the scenario where will upgrade the library catalog to store information about people. We explore this implementation using plain text files. Plain text has the advantage that the datafile is easily viewable and editable.

Both examples use the strategy to load ALL DATA AT THE START of the program. Whenever any new data is added to the system, we save all data in structure arrays by calling our save() functions which OVERWRITE the older files.

In real world practice, overwriting files on every data addition would not be as efficient , however this strategy is the easiest to manage at our introductory level. Other strategies appends the data to the end of the file which involve testing for the end of file or managing sentinel file values.

See the Video Below:

Update:

2022-01-24 : Added introduction.

© 2021  Vedesh Kungebeharry. All rights reserved. 

Internal Assessment Discussion – Unit 1

This video is a live capture from today’s class (Monday 18th January 2021).

In this video:

  • We discuss a template for your IA
  • View A past Naparima College Sample
  • View A past Sample from a past student
  • View An Online sample
  • Observe code for a Mini IA
  • Discuss our First IA Deadline

© 2021  Vedesh Kungebeharry. All rights reserved.