/* CS 60, Fall 2001 Assignment 9 Due Sunday 11/18/01 Logic and Encodings For this assignment, simply edit into this file your rex implementation of the three requested functions and submit. However, you should turn in your Karnaugh maps (used in problem 3) on a separate sheet of paper, to your professor, either in class or in his mailbox in Olin 1240. One of the uses of programming languages, aside from actual computing, is to MODEL computations of various kinds. (Extending Hamming's notion that the purpose of computing is INSIGHT.) In this assignment, we will use rex to model logic functions, as if we are modeling hardware. Accordingly, there are various RESTRICTIONS on the functions you can use. Please heed them, otherwise your solution might not be accepted. It is understood that you might not do things the same way if arbitrary rex functions were allowed. The allowed rex functions are (n is arbitrary in each case): or(x1, x2, ..., xn), alternatively x1 || x2 || ... || xn and(x1, x2, ..., xn), alternatively x1 && x2 && ... && xn not(x1), alternatively !x1 The problems involve implementing logic for converting one kind of encoding to another. In each case, both the argument and result are lists, representing bundles of separate wires, each having values restricted to the domain {0, 1}. We give rex functions that define various encodings of the numbers {0, ..., 9}. These are enumerative, not the most succinct definitions we could give, but are in their current form for illustrative purposes. We also provide a function 'show' which will print out a seven-segment encoding in a manner simulating an LED display, e.g. rex > show(decimalToSevenSegment(9)); ****** * * * * * * ****** * * * PROBLEMS: Implement, using only a single equation defining the appropriate n-tuple and no functions other than logic gate functions: 1. oneHotToSevenSegment, using only the 'or' function. 2. sevenSegmentToBCD, using min-term expansion. 3. BCDtoSevenSegment, using sum-of-products, simplified using Karnaugh maps. Below, TBD is a placeholder for your answer: */ TBD = "To Be Defined"; /* Answer to Problem 1, oneHotToSevenSegment, using only the 'or' function */ oneHotToSevenSegment([x0, x1, x2, x3, x4, x5, x6, x7, x8, x9]) => TBD; /* Answer to Problem 2, sevenSegmentToBCD, using min-term expansion */ sevenSegmentToBCD([s0, s1, s2, s3, s4,s5, s6]) => TBD; /* Answer to Problem 3, BCDtoSevenSegment, using sum-of-products, simplified using Karnaugh maps. */ BCDtoSevenSegment([b3, b2, b1, b0]) => TBD; /* These rules define the various encodings, and are also used in the tests. */ decimalToSevenSegment(0) => [1, 1, 1, 0, 1, 1, 1]; decimalToSevenSegment(1) => [0, 0, 1, 0, 0, 1, 0]; decimalToSevenSegment(2) => [1, 0, 1, 1, 1, 0, 1]; decimalToSevenSegment(3) => [1, 0, 1, 1, 0, 1, 1]; decimalToSevenSegment(4) => [0, 1, 1, 1, 0, 1, 0]; decimalToSevenSegment(5) => [1, 1, 0, 1, 0, 1, 1]; decimalToSevenSegment(6) => [1, 1, 0, 1, 1, 1, 1]; decimalToSevenSegment(7) => [1, 0, 1, 0, 0, 1, 0]; decimalToSevenSegment(8) => [1, 1, 1, 1, 1, 1, 1]; decimalToSevenSegment(9) => [1, 1, 1, 1, 0, 1, 0]; sevenSegmentToDecimal([1, 1, 1, 0, 1, 1, 1]) => 0; sevenSegmentToDecimal([0, 0, 1, 0, 0, 1, 0]) => 1; sevenSegmentToDecimal([1, 0, 1, 1, 1, 0, 1]) => 2; sevenSegmentToDecimal([1, 0, 1, 1, 0, 1, 1]) => 3; sevenSegmentToDecimal([0, 1, 1, 1, 0, 1, 0]) => 4; sevenSegmentToDecimal([1, 1, 0, 1, 0, 1, 1]) => 5; sevenSegmentToDecimal([1, 1, 0, 1, 1, 1, 1]) => 6; sevenSegmentToDecimal([1, 0, 1, 0, 0, 1, 0]) => 7; sevenSegmentToDecimal([1, 1, 1, 1, 1, 1, 1]) => 8; sevenSegmentToDecimal([1, 1, 1, 1, 0, 1, 0]) => 9; decimalToOneHot(0) => [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]; decimalToOneHot(1) => [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]; decimalToOneHot(2) => [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]; decimalToOneHot(3) => [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]; decimalToOneHot(4) => [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]; decimalToOneHot(5) => [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]; decimalToOneHot(6) => [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]; decimalToOneHot(7) => [0, 0, 0, 0, 0, 0, 0, 1, 0, 0]; decimalToOneHot(8) => [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]; decimalToOneHot(9) => [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]; decimalToBCD(0) => [0, 0, 0, 0]; decimalToBCD(1) => [0, 0, 0, 1]; decimalToBCD(2) => [0, 0, 1, 0]; decimalToBCD(3) => [0, 0, 1, 1]; decimalToBCD(4) => [0, 1, 0, 0]; decimalToBCD(5) => [0, 1, 0, 1]; decimalToBCD(6) => [0, 1, 1, 0]; decimalToBCD(7) => [0, 1, 1, 1]; decimalToBCD(8) => [1, 0, 0, 0]; decimalToBCD(9) => [1, 0, 0, 1]; BCDtoDecimal([0, 0, 0, 0]) => 0; BCDtoDecimal([0, 0, 0, 1]) => 1; BCDtoDecimal([0, 0, 1, 0]) => 2; BCDtoDecimal([0, 0, 1, 1]) => 3; BCDtoDecimal([0, 1, 0, 0]) => 4; BCDtoDecimal([0, 1, 0, 1]) => 5; BCDtoDecimal([0, 1, 1, 0]) => 6; BCDtoDecimal([0, 1, 1, 1]) => 7; BCDtoDecimal([1, 0, 0, 0]) => 8; BCDtoDecimal([1, 0, 0, 1]) => 9; // show seven-segment code as a mock LED display show([s0, s1, s2, s3, s4, s5, s6]) => seq( print(s0 ? "******" : " "), print("\n"), print(s1 ? "* " : " "), print(s2 ? "*" : " "), print("\n"), print(s1 ? "* " : " "), print(s2 ? "*" : " "), print("\n"), print(s1 ? "* " : " "), print(s2 ? "*" : " "), print("\n"), print(s3 ? "******" : " "), print("\n"), print(s4 ? "* " : " "), print(s5 ? "*" : " "), print("\n"), print(s4 ? "* " : " "), print(s5 ? "*" : " "), print("\n"), print(s4 ? "* " : " "), print(s5 ? "*" : " "), print("\n"), print(s6 ? "******" : " "), print("\n"), print("\n") ); showAll() = map((N) => show(decimalToSevenSegment(N)), range(0, 9)); // Test that the seven segment conversions are correct test( map((N) => sevenSegmentToDecimal(decimalToSevenSegment(N)), range(0, 9)), range(0, 9)); // Test Problem 1 test( map((N) => sevenSegmentToDecimal(oneHotToSevenSegment(decimalToOneHot(N))), range(0, 9)), range(0, 9)); // Test Problem 2 test( map((N) => BCDtoDecimal(sevenSegmentToBCD(decimalToSevenSegment(N))), range(0, 9)), range(0, 9)); // Test Problem 3 test( map((N) => sevenSegmentToDecimal(BCDtoSevenSegment(decimalToBCD(N))), range(0, 9)), range(0, 9));