Outline. flip-flops registers. sorting words values of numbers given in words. using Python lists towers of Hanoi

Similar documents
Sequential Logic and Clocked Circuits

Logic Design. Flip Flops, Registers and Counters

Chapter 3: Sequential Logic Systems

Experiment # 12. Traffic Light Controller

COMP2611: Computer Organization Building Sequential Logics with Logisim

Logic. Andrew Mark Allen March 4, 2012

(CSC-3501) Lecture 7 (07 Feb 2008) Seung-Jong Park (Jay) CSC S.J. Park. Announcement

LATCHES & FLIP-FLOP. Chapter 7

YEDITEPE UNIVERSITY DEPARTMENT OF COMPUTER ENGINEERING. EXPERIMENT VIII: FLIP-FLOPS, COUNTERS 2014 Fall

Outcomes. Spiral 1 / Unit 6. Flip-Flops FLIP FLOPS AND REGISTERS. Flip-flops and Registers. Outputs only change once per clock period

Sequential Logic Circuits

Sequential Digital Design. Laboratory Manual. Experiment #3. Flip Flop Storage Elements

IS1500 (not part of IS1200) Logic Design Lab (LD-Lab)

VeriLab. An introductory lab for using Verilog in digital design (first draft) VeriLab

Chapter 5 Sequential Circuits

Chapter 4. Logic Design

Synchronous Sequential Logic

Digital Logic Design Sequential Circuits. Dr. Basem ElHalawany

NEW MEXICO STATE UNIVERSITY Electrical and Computer Engineering Department. EE162 Digital Circuit Design Fall Lab 5: Latches & Flip-Flops

Other Flip-Flops. Lecture 27 1

LAB 7. Latches & Flip Flops

ELCT201: DIGITAL LOGIC DESIGN

North Shore Community College

DIGITAL CIRCUIT COMBINATORIAL LOGIC

Introduction to Sequential Circuits

ECE 341. Lecture # 2

Lecture 8: Sequential Logic

Logic Devices for Interfacing, The 8085 MPU Lecture 4

EXPERIMENT: 1. Graphic Symbol: OR: The output of OR gate is true when one of the inputs A and B or both the inputs are true.

Unit 11. Latches and Flip-Flops

SEQUENTIAL CIRCUITS THE RELAY CIRCUIT

Sequential Circuits: Latches & Flip-Flops

Dr.Mohamed Elmahdy Winter 2015 Eng.Yasmin Mohamed. Problem Set 6. Analysis and Design of Clocked Sequential Circuits. Discussion: 7/11/ /11/2015

DIGITAL CIRCUIT LOGIC UNIT 11: SEQUENTIAL CIRCUITS (LATCHES AND FLIP-FLOPS)

Module 4:FLIP-FLOP. Quote of the day. Never think you are nothing, never think you are everything, but think you are something and achieve anything.

ELCT201: DIGITAL LOGIC DESIGN

Digital Circuit And Logic Design I. Lecture 8

Digital Circuit And Logic Design I

The basic logic gates are the inverter (or NOT gate), the AND gate, the OR gate and the exclusive-or gate (XOR). If you put an inverter in front of

55:131 Introduction to VLSI Design Project #1 -- Fall 2009 Counter built from NAND gates, timing Due Date: Friday October 9, 2009.

EMT 125 Digital Electronic Principles I CHAPTER 6 : FLIP-FLOP

COE 202: Digital Logic Design Sequential Circuits Part 1. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

ELE2120 Digital Circuits and Systems. Tutorial Note 8

Name Of The Experiment: Sequential circuit design Latch, Flip-flop and Registers

Design of a Binary Number Lock (using schematic entry method) 1. Synopsis: 2. Description of the Circuit:

ELE2120 Digital Circuits and Systems. Tutorial Note 7

Laboratory 10. Required Components: Objectives. Introduction. Digital Circuits - Logic and Latching (modified from lab text by Alciatore)

LAB #4 SEQUENTIAL LOGIC CIRCUIT

CHAPTER 1 LATCHES & FLIP-FLOPS

Digital Circuits 4: Sequential Circuits

Solar Power for Small Hall

D Latch (Transparent Latch)

AIM: To study and verify the truth table of logic gates

Chapter. Synchronous Sequential Circuits

DIGITAL SYSTEM FUNDAMENTALS (ECE421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE422) LATCHES and FLIP-FLOPS

DEPARTMENT OF ELECTRICAL &ELECTRONICS ENGINEERING DIGITAL DESIGN

First Name Last Name November 10, 2009 CS-343 Exam 2

CHAPTER 4 RESULTS & DISCUSSION

Logic Design II (17.342) Spring Lecture Outline

To design a sequential logic circuit using D-Flip-flop. To implement the designed circuit.

CPSC 121: Models of Computation Lab #5: Flip-Flops and Frequency Division

Chapter 11 State Machine Design

Laboratory 7. Lab 7. Digital Circuits - Logic and Latching

1. Synopsis: 2. Description of the Circuit:

Introduction. Serial In - Serial Out Shift Registers (SISO)

Register Transfer Level in Verilog: Part II

Activity Sequential Logic: An Overview

CPS311 Lecture: Sequential Circuits

Combinational / Sequential Logic

COSC 243. Sequential Logic. COSC 243 (Computer Architecture) Lecture 5 - Sequential Logic 1

IT T35 Digital system desigm y - ii /s - iii

Lecture 12: State Machines

Digital Design, Kyung Hee Univ. Chapter 5. Synchronous Sequential Logic

Unit 12 Design Solutions Solutions to Unit 12 Design and Simulation Problems

Introduction to Digital Logic Missouri S&T University CPE 2210 Exam 2 Logistics

Administrative issues. Sequential logic

The word digital implies information in computers is represented by variables that take a limited number of discrete values.

Counter dan Register

CPSC 121: Models of Computation Lab #5: Flip-Flops and Frequency Division

CH 11 Latches and Flip-Flops

MC9211 Computer Organization

RS flip-flop using NOR gate

CHAPTER 4: Logic Circuits

Chapter 1: Switching Algebra Chapter 2: Logical Levels, Timing & Delays. Introduction to latches Chapter 9: Binary Arithmetic

Asynchronous (Ripple) Counters

B.Tech CSE Sem. 3 15CS202 DIGITAL SYSTEM DESIGN (Regulations 2015) UNIT -IV

Chapter 5 Synchronous Sequential Logic

Chapter 3. Boolean Algebra and Digital Logic

Sequential Logic. Introduction to Computer Yung-Yu Chuang

Topic D-type Flip-flops. Draw a timing diagram to illustrate the significance of edge

CSE Latches and Flip-flops Dr. Izadi. NOR gate property: A B Z Cross coupled NOR gates: S M S R Q M

Combinational vs Sequential

EXPERIMENT #6 DIGITAL BASICS

1. Convert the decimal number to binary, octal, and hexadecimal.

DIGITAL ELECTRONICS MCQs

Analysis of Clocked Sequential Circuits

PHYSICS 5620 LAB 9 Basic Digital Circuits and Flip-Flops

CHAPTER1: Digital Logic Circuits

Latches, Flip-Flops, and Registers. Dr. Ouiem Bchir

Chapter 8 Sequential Circuits

Transcription:

Outline Digital Systems flip-flops registers 2 Intrinsic Operations sorting words values of numbers given in words 3 queues and stacks using Python lists towers of Hanoi 4 Summary + Assignments MCS 26 Lecture Introduction to Computer Science Jan Verschelde, 3 February 26 Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 / 28

flip-flops and registers queues and stacks Digital Systems flip-flops registers 2 Intrinsic Operations sorting words values of numbers given in words 3 queues and stacks using Python lists towers of Hanoi 4 Summary + Assignments Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 2 / 28

Flip-Flops one bit memory Flip-Flops (and latches) are the simplest circuits to store one bit. D Q T D: input line T: clock line Q: output line Its behavior is as follows: When one arrives on the clock line, the output line is set to the value present on the input line. 2 The value at the output line is stored at the flip-flop, until a new one arrives on the clock line. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 3 / 28

Logic Gates A flip-flop is realized with NOT, NAND, and NOR gates: NOT NAND NOR Exercise: represent NOT ( x NOR ( NOT y ) ). Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 4 / 28

Realization of a Flip-Flop one NOT, two NANDs, and two NORs We simulate the latching ofaatdtoq,withatq. D T Q Exercise: verify the effect is the same for at Q. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

Realization of a Flip-Flop one NOT, two NANDs, and two NORs We simulate the latching ofaatdtoq,withatq. D T Q Exercise: verify the effect is the same for at Q. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

Realization of a Flip-Flop one NOT, two NANDs, and two NORs We simulate the latching ofaatdtoq,withatq. D T Q Exercise: verify the effect is the same for at Q. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

Realization of a Flip-Flop one NOT, two NANDs, and two NORs We simulate the latching ofaatdtoq,withatq. D T Q Exercise: verify the effect is the same for at Q. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

Realization of a Flip-Flop one NOT, two NANDs, and two NORs We simulate the latching ofaatdtoq,withatq. D T Q Exercise: verify the effect is the same for at Q. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

Realization of a Flip-Flop one NOT, two NANDs, and two NORs We simulate the latching ofaatdtoq,withatq. D T Q Exercise: verify the effect is the same for at Q. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

Realization of a Flip-Flop one NOT, two NANDs, and two NORs We simulate the latching ofaatdtoq,withatq. D T Q Exercise: verify the effect is the same for at Q. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

Realization of a Flip-Flop one NOT, two NANDs, and two NORs We simulate the latching ofaatdtoq,withatq. D T Q Exercise: verify the effect is the same for at Q. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

Realization of a Flip-Flop one NOT, two NANDs, and two NORs We simulate the latching ofaatdtoq,withatq. D T Q Exercise: verify the effect is the same for at Q. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

Behavior in Time how latching of bits works The evolution in time is D Q D T Q T D Q T D Q T D Q T D Q T t t 2 t 3 t 4 t 5 t 6 At t :atd,att,andatq At t 2 : at D, but at T and nothing happens At t 3 :att atdcopied to at Q At t 4 : at T and nothing happens At t 5 : at D, but at T and nothing happens At t 6 :att atdcopied to at Q Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 6 / 28

flip-flops and registers queues and stacks Digital Systems flip-flops registers 2 Intrinsic Operations sorting words values of numbers given in words 3 queues and stacks using Python lists towers of Hanoi 4 Summary + Assignments Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 7 / 28

Registers An 8-bit register is realized with 8 flip-flops. eight input lines and eight clock lines D T Q D2 T2 Q2 D3 T3 Q3 D4 T4 Q4 D5 T5 Q5 D6 T6 Q6 D7 Q7 T7 D8 Q8 T8 eight output lines Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 8 / 28

Copy Bits using 2 AND gates We want to copy a bit from one latch to the other. The bit is at the output line of the first latch, at Q and has to get to the output line of the second latch, at Q2. D T Q D2 T2 Q2 control signal system clock The copy is activated by the control signal. For synchronization, another signal from the system clock copies the bit from the input line at D2 to Q2. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 9 / 28

flip-flops and registers queues and stacks Digital Systems flip-flops registers 2 Intrinsic Operations sorting words values of numbers given in words 3 queues and stacks using Python lists towers of Hanoi 4 Summary + Assignments Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 / 28

sorting words program specification Input/Output problem statement: Input: string with words separated by spaces. Output: string with alphabetically sorted words. Running sortwords.py at the command prompt $: $ python sortwords.py Give words : this is my sentence Sorted words : is my sentence this $ Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 / 28

sorting words in the Python shell >>> s = this is my sentence >>> L = s.split() >>> L [ this, is, my, sentence ] Methods are different from functions: >>> max(l) this >>> min(l) is >>> L.sort() >>> L [ is, my, sentence, this ] >>>.join(l) is my sentence this Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 2 / 28

operations on strings and lists: split, join, and sort To sort a list L: >>> L.sort() A compare function can be given as argument in (). To split a string s into a list L of strings: >>> L = s.split() The default separator is a space, another separator (like a comma or colon) can be given as string in (). To join a list of strings L into one string s: >>> s =.join(l) The separator used between the strings in L is the string to which the method is applied to. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 3 / 28

sorting words a Python program The program sortwords.py: """ This program shows intrinsic operations on strings and lists, to sort words, given as a raw input string by the user. """ WORDS = raw_input( Give words : ) SPLITTED = WORDS.split() # spaces separate words SPLITTED.sort() # sort alphabetically SORTED =.join(splitted) # join the sorted list print( Sorted words :, SORTED) Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 4 / 28

flip-flops and registers queues and stacks Digital Systems flip-flops registers 2 Intrinsic Operations sorting words values of numbers given in words 3 queues and stacks using Python lists towers of Hanoi 4 Summary + Assignments Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 5 / 28

value of a number given in words Problem Statement: Input: string with at most two words, separated by exactly one space. Output: value of the number represented by the string. Running the Python code write_values.py: $ python write_values.py give a number in words : forty seven the value of forty seven is 47 Note: reverse of write_numbers.py of the previous lecture. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 6 / 28

the dictionary to translate words into values The keys are strings representing words, the values are the corresponding numbers. DIC = { \ zero :, one :, two :2, three :3, \ four :4, five :5, six :6, seven :7, \ eight :8, nine :9, ten :, \ eleven :, twelve :2, thirteen :3, \ fourteen :4, fifteen :5, sixteen :6, \ seventeen :7, nineteen :9, twenty :2, \ thirty :3, forty :4, fifty :5, \ sixty :6, seventy :7, eighty :8, \ ninety :9, hundred : \ } The dictionary solves 28 cases. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 7 / 28

dictionary is stored in write_values.py >>> from write_values import DIC as d >>> s = forty seven >>> s in d False >>> L = s.split( ) >>> L [ forty, seven ] >>> L[] in d True >>> d[l[]] 4 >>> d[l[]] 7 >>> v = d[l[]] + d[l[]] >>> v 47 Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 8 / 28

Python script write_values.py continued WORDS = raw_input( give a number in words : ) OUTCOME = the value of + WORDS + is if WORDS in DIC: OUTCOME += str(dic[words]) else: SPLITTED = WORDS.split( ) OUTCOME += str(dic[splitted[]] \ + DIC[SPLITTED[]]) print OUTCOME Alternative: do first L = s.split( ) and then test on len(l) == to determine outcome. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 9 / 28

flip-flops and registers queues and stacks Digital Systems flip-flops registers 2 Intrinsic Operations sorting words values of numbers given in words 3 queues and stacks using Python lists towers of Hanoi 4 Summary + Assignments Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 2 / 28

Queues and Stacks use of Python lists Two protocols to retrieve elements sequentially: FIFO: First In First Out, a queue think of a normal waiting list FILO: First in Last Out, a stack think of a pile of papers on a desk Intrinsic operations on a list L: L.append(<item>) appends <item> to L <item> = L.pop() removes last item added to L <item> = L.pop() removes first item added to L L.insert(,<item>) inserts <item> to front of L operations modify L! How to select from L, without modifications? >>> L[] >>> L[len(L)-] All these Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 2 / 28

Lists as Queues and Stacks a session in the Python shell >>> L = these are some words.split() >>> L [ these, are, some, words ] >>> L.append( and ) >>> L [ these, are, some, words, and ] >>> last = L.pop() >>> last and >>> first = L.pop() >>> first these >>> L [ are, some, words ] Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 22 / 28

flip-flops and registers queues and stacks Digital Systems flip-flops registers 2 Intrinsic Operations sorting words values of numbers given in words 3 queues and stacks using Python lists towers of Hanoi 4 Summary + Assignments Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 23 / 28

The Towers of Hanoi a mathematical puzzle Input: a stack of disks, all of varying size, no larger disk sits above a smaller disk, and two other empty stacks. Task: move the disks from the first stack to the second, obeying the following rules:. move one disk at a time, 2. never place a larger disk on a smaller one, you may use the third stack as buffer. How many moves does it take? Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 24 / 28

Towers of Hanoi for three disks in Python three lists A, B, C as stacks disks are represented as numbers < 2 < 3 Towers of Hanoi with 3 disks initially : A = [, 2, 3] B = [] C = [] move : A = [2, 3] B = [] C = [] move 2 : A = [3] B = [] C = [2] move 3 : A = [3] B = [] C = [, 2] move 4 : A = [] B = [3] C = [, 2] move 5 : A = [] B = [3] C = [2] move 6 : A = [] B = [2, 3] C = [] move 7 : A = [] B = [, 2, 3] C = [] Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 25 / 28

Towers of Hanoi for 3 disks """ To illustrate the use of stacks we solve the towers of Hanoi problem with three disks. """ print Towers of Hanoi with 3 disks A = [, 2, 3] B = [] C = [] print( initially : A =, A, B =, B, C =, C) Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 26 / 28

Towers of Hanoi: the moves for 3 disks B.insert(, A.pop()) print( move : A =, A, B =, B, C =, C) C.insert(, A.pop()) print( move 2 : A =, A, B =, B, C =, C) C.insert(, B.pop()) print( move 3 : A =, A, B =, B, C =, C) B.insert(, A.pop()) print( move 4 : A =, A, B =, B, C =, C) A.insert(, C.pop()) print( move 5 : A =, A, B =, B, C =, C) B.insert(, C.pop()) print( move 6 : A =, A, B =, B, C =, C) B.insert(, A.pop()) print( move 7 : A =, A, B =, B, C =, C) Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 27 / 28

Summary + Assignments In this lecture we covered more of section in Computer Science: an overview; pages 22-27 of Python Programming in Context. Assignments: Translate the realization diagram for a flip-flop into a logical expression involving the variables D, T, and Q, using NOT, NAND, and NOR. 2 Write a Python program to convert a date like 3 February 26 into 26-2-3. Names of the month are written in full. 3 Extend write_values.py so it works for all strings representing numbers less than one thousand. 4 Extend the Python code for the towers of Hanoi so that it works for four disks. Intro to Computer Science (MCS 26) flip-flops and registers L- 3 February 26 28 / 28