[Solved] ICS Problem sheet 9

$25

File Name: ICS_Problem_sheet_9.zip
File Size: 178.98 KB

SKU: [Solved] ICS Problem sheet 9 Category: Tag:
5/5 - (1 vote)
Problem 9.1: JK flip-flops

JK flip-flops, also colloquially known as jump/kill flip-flops, augment the behaviour of SR flip-flops. The letters J and K were presumably picked by Eldred Nelson in a patent application.

The sequential digital circuit shown below shows the design of a JK flip-flop based on two SR NAND latches. Assume the circuits output is Q = 0 and that the inputs are J = 0 and K = 0, and that the clock input is C = 0. (You can make use of the fact that we already know how an SR

NAND latch behaves.)

  1. Suppose J transitions to 1 and C transitions to 1 soon after. Create a copy of the drawing and indicate for each line whether it carries a 0 or a 1.
  2. Some time later, C transitions back to 0 and soon after J transitions to 0 as well. Create another copy of the drawing and indicate for each line whether it carries a 0 or a 1.
  3. Some time later, J and K both transition to 1 and C transitions to 1 soon after. Create another copy of the drawing and indicate for each line whether it carries a 0 or a 1.
  4. Finally, C transitions back to 0 and soon after J and K both transition to 0 as well. Create another copy of the drawing and indicate for each line whether it carries a 0 or a 1.

Problem 9.2: ripple counter using d flip-flops

The following circuit shows a 3-bit ripple counter consisting of three positive edge triggered D flip-flops and a negation gate on the clock input C.

  1. Complete the following timing diagram. Assume that gate delays are very short compared to the speed of the clock signal (i.e., you can ignore the impact of gate delays).
  2. Can you make ripple counters arbitrary long or is there a limit on the number of D flip flops that can be chained? Explain.

Problem 9.3: integer expression simplification (haskell)

Our goal is to simplify integer expressions that may include constants and variables and which are constructed using a sum and a product operator. For example, we want to write an program that can simplify (2y)(3+(22)) to 14y. We can represent expressions in Haskell using the following

data type:
1 data Exp = C Int a constant integer
2 | V String a variable with a name
3 | S Exp Exp a sum of two expressions
4 | P Exp Exp a product of two expressions
5 deriving (Show, Eq)

We use the following rules to simplify expressions:

S1 Adding two constants a and b yields a constant, which has the value a+b, e.g., 3+5 = 8.

S2 Adding 0 to a variable yields the variable, i.e., 0+x = x and x+0 = x.

S3 Adding a constant a to a sum consisting of a constant b and a variable yields the sum of the a+b and the variable, e.g., 3+(5+y) = 8+y.

P1 Multiplying two constants a and b yields a constant, which as the value a b, e.g., 3 5 = 15.

P2 Multiplying a variable with 1 yields the variable, i.e., 1 y = y and y 1 = y.

P3 Multiplying a variable with 0 yields the constant 0, i.e., 0 y = 0 and y 0 = 0.

P4 Multiplying a constant a with a product consisting of a constant b and a variable yields the product of a b and the variable, e.g., 3 (2 y) = 6 y.

The usual associativity rules apply. Note that we have left out distributivity rules.

  1. Implement a function simplify :: Expr -> Expr, which simplifies expressions that do not contain variables. In other words, simplify returns the (constant) value of an expression that does not contain any variables.
  2. Extend the function simplify to handle variables as described above.

Submit your Haskell code plus an explanation (in Haskell comments) as a plain text file. Below is a template providing a collection of test cases.

1 module Main (main) where

2

3 import Test.HUnit

4

  • data Exp = C Int a constant integer
  • | V String a variable with a name
  • | S Exp Exp a sum of two expressions
  • | P Exp Exp a product of two expressions
  • deriving (Show, Eq)

10

  • simplify :: Exp -> Exp
  • simplify _ = undefined

13

  • tI0 = TestList
  • [ simplify (C 3) ~?= C 3 3 = 3
  • , simplify (V y) ~?= V y y = y
  • ]

18

  • tS1 = TestList
  • [ simplify (S (C 3) (C 5)) ~?= C 8 3 + 5 = 8
  • ]

22

  • tS2 = TestList
  • [ simplify (S (C 0) (V y)) ~?= V y 0 + y = y
  • , simplify (S (V y) (C 0)) ~?= V y y + 0 = y
  • ]

27

  • tS3 = TestList
  • [ simplify (S (S (C 3) (V y)) (C 5)) ~?= S (C 8) (V y) (3 + y) + 5) = 8 + y
  • , simplify (S (S (V y) (C 3) ) (C 5)) ~?= S (C 8) (V y) (y + 3) + 5) = 8 + y
  • , simplify (S (C 3) (S (C 5) (V y))) ~?= S (C 8) (V y) 3 + (5 + y) = 8 + y
  • , simplify (S (C 3) (S (V y) (C 5))) ~?= S (C 8) (V y) 3 + (y + 5) = 8 + y
  • ]

34

  • tS4 = TestList
  • [ simplify (S (S (C 3) (C 5)) (C 8)) ~?= C 16 (3 + 5) + 8 = 16
  • , simplify (S (C 3) (S (C 5) (C 8))) ~?= C 16 3 + (5 + 8) = 16
  • , simplify (S (C 5) (V y)) ~?= S (C 5) (V y) 5 + y = 5 + y
  • , simplify (S (V y) (C 5)) ~?= S (V y) (C 5) y + 5 = y + 5
  • , simplify (S (V x) (V y)) ~?= S (V x) (V y) x + y = x + y
  • ]

42

  • tP1 = TestList
  • [ simplify (P (C 3) (C 5)) ~?= C 15 3 * 5 = 15
  • ]

46

  • tP2 = TestList
  • [ simplify (P (C 1) (V y)) ~?= V y 1 * y = y
  • , simplify (P (V y) (C 1)) ~?= V y y * 1 = y
  • ]

51

  • tP3 = TestList
  • [ simplify (P (C 0) (V y)) ~?= C 0 0 * y = 0
  • , simplify (P (V y) (C 0)) ~?= C 0 y * 0 = 0
  • ]

56

  • tP4 = TestList
  • [ simplify (P (P (C 3) (V y)) (C 2)) ~?= P (C 6) (V y) (3 * y) * 2) = 6 * y
  • , simplify (P (P (V y) (C 3) ) (C 2)) ~?= P (C 6) (V y) (y * 3) * 2) = 6 * y
  • , simplify (P (C 3) (P (C 2) (V y))) ~?= P (C 6) (V y) 3 * (2 * y) = 6 * y
  • , simplify (P (C 3) (P (V y) (C 2))) ~?= P (C 6) (V y) 3 * (y * 2) = 6 * y
  • ]

63

  • tP5 = TestList
  • [ simplify (P (P (C 3) (C 5)) (C 8)) ~?= C 120 (3 * 5) * 8 = 120
  • , simplify (P (C 3) (P (C 5) (C 8))) ~?= C 120 3 * (5 * 8) = 120
  • , simplify (P (C 5) (V y)) ~?= P (C 5) (V y) 5 * y = 5 * y
  • , simplify (P (V y) (C 5)) ~?= P (V y) (C 5) y * 5 = y * 5
  • , simplify (P (V x) (V y)) ~?= P (V x) (V y) x * y = x * y
  • ]

71

  • tM0 = TestList [
  • (2 * y) * (3 + (2 * 2)) = 14 * y
  • simplify (P (P (C 2) (V y)) (S (C 3) (P (C 2) (C 2)))) ~?= P (C 14) (V y)
  • x + (1 + -1) = x
  • , simplify (S (V x) (S (C 1) (C (-1)))) ~?= V x
  • (1 + -1) * x = 0
  • , simplify (P (S (C 1) (C (-1))) (V x)) ~?= C 0
  • (2 + -1) * x = x
  • , simplify (P (S (C 2) (C (-1))) (V x)) ~?= V x
  • (2 * 2) * (3 + 4) = 28
  • , simplify (P (P (C 2) (C 2)) (S (C 3) (C 4))) ~?= C 28
  • ]

84

85 main = runTestTT $ TestList [tI0, tS1, tS2, tS3, tS4, tP1, tP2, tP3, tP4, tP5, tM0 ]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] ICS Problem sheet 9[Solved] ICS Problem sheet 9
$25