CSM51Ach2

CSM51Ach2 - 16 Chapter 2 Speci cation of combinational systems In this chapter we present and discuss The high-level and binary-level speci cations

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 16 Chapter 2 Speci cation of combinational systems In this chapter, we present and discuss The high-level and binary-level speci cations. The representation of data elements (signal values) by binary variables (signals) and the standard codes for positive integers and characters. The representation by switching functions and switching expressions. The not, and, or, nor, xor, and xnor switching functions and their representation. Gate symbols. The sum of products (sop) and product of sums (pos) expressions. The transformation of switching expressions using the switching algebra. The use of various speci cation methods in some examples. The use of the vhdl description language. 2.1 Combinational systems: de nition and speci cation levels A combinational system is a digital system in which the value of the output at any instant depends only on the value of the input at that same instant (and not on previous values). As depicted in Figure 2.1, this is expressed as z (t) = F (x(t)) 17 18 Chapter 2. Speci cation of combinational systems x z Time t Figure 2.1: Combinational system. High-level specification F x Coding C xb n Binary specification Fb zb m z Decoding D Figure 2.2: High-level and binary-level speci cation. Since the function F is not time dependent, there is no need to have an explicit time dependency in the variables and we can write z = F (x) Combinational systems are speci ed at two levels, as illustrated in Figure 2.2: a high-level and a binary-level. In a high-level speci cation, the system is described by a function on nite sets and represented by tables or expressions. In contrast, in a binary-level speci cation all variables are binary, that is each variable has only two values, denoted 0 and 1. This is expressed by z b = Fb(xb ) wherein xb and z b are vectors (ordered collections) of binary variables, and Fb is a binary function. Each binary variable is called a bit (binary digit), and a vector of binary variables is called a bit-vector. The correspondence between these two speci cation levels is given by the coding and decoding functions (see Figure 2.2). The coding function describes how each value of the input x is represented by a di erent combination of values of the bits in xb. Similarly, the decoding function describes the relationship among z and z b. For a variable of v values, a bit-vector of at least dlog2 v e bits is needed to represent these v values. This is so because k binary variables (taken as a vector) have 2k di erent values. 2.1. Combinational systems: de nition and speci cation levels 19 Example 2.1 A combinational system has as input a decimal digit and as output the remainder when the input is divided by three. The high-level speci cation of this system is Input: x 2 f0 1 2 3 4 5 6 7 8 9g Output: z 2 f0 1 2g Function: F is described by the following table x 0123456789 z = F (x) 0 1 2 0 1 2 0 1 2 0 or by the arithmetic expression z = x mod 3, where a mod b is the remainder obtained when dividing integer a by integer b. To obtain a binary speci cation, the input x is encoded into the bit-vector xb and the output z into the bit-vector z b . Moreover, the function F is mapped onto the function Fb . Many alternative codes are possible. Since the number of values of x is nine, at least four binary variables are needed. We use the standard code discussed in the next sections, which in this case is as follows: x 0 1 2 3 4 5 6 7 8 9 xb = C (x) 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 zb 00 01 10 z = D(z b) 0 1 2 The function Fb is obtained by replacing the values in the table of the high-level speci cation. The resulting binary speci cation is: Input: xb = (x3 x2 x1 x0) xi 2 f0 1g Output: z b = (z1 z0) zi 2 f0 1g Function: Fb is described by the following table xb 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 zb = Fb(xb ) 00 01 10 00 01 10 00 01 10 00 As will be apparent throughout the text, a high-level speci cation is preferable whenever possible because it is easier to understand and use. The binary level is primarily used for implementation purposes because, due to technological considerations, the implementation of digital system uses binary variables. In this chapter, we limit the discussion to the functional speci cation of a system. Other aspects of a system required for a complete speci cation, such as delay and size constraints, are discussed in following chapters. 20 Chapter 2. Speci cation of combinational systems 2.2 High-level speci cation of combinational systems We address now in more detail the high-level speci cation of combinational systems. This speci cation consists of the following three components: The set of values for the input, called the input set The set of values for the output, called the output set and The speci cation of the input-output function. Input and output sets The nite input and output sets can be described by listing their elements or by some condition (property) that uniquely identi es the elements. For example, fup down left right fireg describes a set of ve elements, whereas the conditional form fx j (5 x 104 ) and (x mod 3 = 0)g describes the nite set of integers between 5 and 104 that are multiples of 3. In the most general case, the input and output sets contain arbitrary elements, such as in the rst example above. On the other hand, some frequently used sets correspond to the values taken by physical quantities (numerical values) and to representation of the written language (characters). In many cases, it is convenient to de ne input and output sets consisting of composite elements, which are constructed as structures of primitive elements. The simplest, and most used of these structures, is the vector (or onedimensional array) which is an ordered set of primitive elements. The number of elements is the length of the vector. A particular element within the vector is identi ed by an index, which is usually an integer in the range from 1 to `length' (or from 0 to `length - 1'). The elements in a vector are of the same type and have the same set of values. Depending on the type of the primitive element, we can have integer-vectors (also called digit-vectors), character-vectors (also called character strings), set-vectors, and bit-vectors. Examples of these vector types are given in Figure 2.3. In general, the elements of a vector are written separated by a comma, as depicted in Figure 2.3 for simplicity, whenever it is clear from the context, vector elements may also be written without the commas, and the entire vector without the parenthesis, as illustrated for the bit-vector case in Figure 2.3. Input-output function The input-output function can be de ned in the following alternatives ways: 2.2. High-level speci cation of combinational systems 21 Vector type Example Digit x = (xn;1 xn;2 : : : x0) x = (7 0 6 3) xi 2 f0 1 2 : : : 9g Character c = (cn;1 cn;2 : : : c0 ) c = (B O O K ) ci 2 f A B : : : Z g Set s = (sn;1 sn;2 : : : s0) s = (red blue blue) si 2 fred blue whiteg Bit y = (yn;1 yn;2 : : : y0 ) y = (1 1 0 1 0 0) yi 2 f0 1g y = 110100 Figure 2.3: Examples of vectors. 1. A table, since the input set is nite. This representation is useful only if the input set is small. For example, x A B C D E z 65 66 67 68 69 2. An arithmetic expression, if the elements of the input and output sets are numeric values. For example, z = 3x + 2y ; 2 3. A conditional expression, if the function can be partitioned into subfunctions. Each of the subfunctions can be represented by any of the methods presented here. For example, 8 a + b if c > d < z = : a ; b if c = d 0 if c < d 4. A logical expression (a proposition), if the output set of the function is fT,Fg (True, False). For example, z = (switch1 = closed ) and ( switch2 = open ) or ( switch3 = closed) 22 Chapter 2. Speci cation of combinational systems 5. A composition of simpler functions. The primitive functions used in the composition should be de ned by one of the other methods. For example, the maximum of four elements is obtained by the following composition of the primitive function greater: max(v w x y) = greater(v greater(w greater(x y))) in which a if a > b greater(a b) = b otherwise The choice among these representations depends on the type of system being described and on the use to be given to the representation. In general, one should use the most expressive and compact representation which is compatible with the desired objective. Example 2.2 A combinational system has as input a string (vector) of four characters, a single character, and an integer with range from 0 to 3. The output also consists of a string of four characters. The system performs character replacement. A high-level description is Inputs: x = (x3 x2 x1 x0), xi 2 fA B : : : Z a b : : : zg y 2 fA B : : : Z a b : : : zg k 2 f0 1 2 3g Outputs: z = (z3 z2 z1 z0), zi 2 fA B : : : Z a b : : : zg xj if j 6= k j 2 f0 1 2 3g y if j = k That is, the output of the system corresponds to the input string vector x whose k;th character is replaced by the character in y. An example is Input: x = (c,a,s,e) , y = r , k = 1 Output: z = (c,a,r,e) In this case, a tabular speci cation is impractical due to the large input set. Function: zj = 2.3 Data representation and coding To obtain a binary description of a combinational system it is necessary to represent the elements of the input and output sets by vectors of binary variables (bit-vectors) according to codes. These codes establish a correspondence between the high-level sets of values and those of the binary vectors. Di erent codes can be used for a given set of elements. Some codes have xed length, that is the same number of bits for all high-level elements, whereas other codes have variable length. A xed-length code using bitvectors of k bits can represent n = 2k elements. The following example illustrates some codes. 2.3. Data representation and coding 23 Example 2.3 Consider a set with the following elements: fAl Bert Dave Jerry Leng Since the set has ve elements, the bit-vector representing them using a xed-length code must have at least three bits. Three possible codes are: Fixed-length Variable-length Code 1 Code 2 Code 3 Al 000 0110 01 Bert 010 0101 001 Dave 100 0011 0001 Jerry 110 1001 00001 Len 111 1111 000001 Note that in this case we have written the bit-vectors without the commas separating the elements, and without the parenthesis. Some standard codes are used for the representation of characters and integers they are of the xed-length type. We now present some examples of such codes. The early codes used for the representation of alphanumeric characters had ve bits, so that only 32 characters could be represented. Currently, the standard codes have seven or eight bits per character, resulting in sets of 128 or 256 characters, respectively. Table 2.1 lists the representation of several uppercase letters, digits and special signs for two standard codes. ASCII (American Standard Code for Information Interchange) is a 7-bit code representing a 128character set. Its code words are extended to 8 bits by inserting an extra bit at the left end. This extra bit, unless used for error detection, is set to 0. EBCDIC (Extended Binary-Coded Decimal Interchange Code) uses 8-bit code words to encode a 256-character set. For example, the 6-character string \A CAB." is represented in 8-bit ASCII as follows: A blank C A B . 01000001 00100000 01000011 01000001 01000010 00101110 We consider only positive integers for the time being (signed integers are discussed in Chapter 10). The representation of these integers is done at two levels (see Figure 2.4): 2.3.1 Representation of characters 2.3.2 Representation of positive integers 24 Chapter 2. Speci cation of combinational systems Table 2.1: Examples of alphanumeric codes. Character A B C .. . Y Z 0 1 2 .. . 8 9 blank . ( + .. . Codes ASCII EBCDIC 100 0001 1100 0001 100 0010 1100 0010 100 0011 1100 0011 .. .. . . 101 1001 1110 1000 101 1010 1110 1001 011 0000 1111 0000 011 0001 1111 0001 011 0010 1111 0010 .. .. . . 011 1000 1111 1000 011 1001 1111 1001 010 0000 0100 0000 010 1110 0100 1011 010 1000 0100 1101 010 1011 0100 1110 .. .. . . Level 1: the integer is represented by a digit-vector, which is composed of digits that take values from a reduced set of integers. Level 2: each of the digits is represented by a bit-vector. An integer is represented by a digit-vector using a number system. The most used one is the radix-r conventional number system (or just radix-r system). In this system, the digit-vector x = (xn;1 xn;2 : : : x1 x0) represents the integer x such that x= n1 i=0 Representation by digit-vector ; X xi r i 2.3. Data representation and coding 25 6 3 0 Level 1: Integer (Digit-vector) 5 Level 2: Bit-vector 1 0 1 1 1 0 0 1 1 0 0 0 Figure 2.4: Two-level representation of integers. where the digit xi takes values from the set f0 1 : : : r ; 1g and r is the radix. Each digit in this system is called a radix-r digit. The set of representable values is 0 x rn ; 1 In the radix-2 case (also called a binary representation) each digit has two values, 0 and 1. For example, the digit-vector x = (1 0 0 1 0 1) represents the integer thirty-seven because 1 25 + 0 24 + 0 23 + 1 22 + 0 21 + 1 20 = (37)10 wherein the subscript 10 indicates that it corresponds to the radix-10 representation (also called the decimal representation). As another example, the digit-vector x = (1 2 1 0) represents the integer one-hundred in the radix-4 number system. A particular digit-vector represents di erent integers for representations with di erent radices. For example, the digit-vector x = (7 3 2 2) represents the integer seven-thousand-three-hundred-twenty-two in the radix-10 system and the integer three-thousand-seven-hundred-ninetyfour in the radix-8 system because x10 = 7 103 + 3 102 + 2 101 + 2 = (7322)10 x8 = 7 83 + 3 82 + 2 81 + 2 = (3794)10 Note that here we write the name of the integer in words to distinguish it from its many representations and that, by convention, the name is associated to the 26 5 Chapter 2. Speci cation of combinational systems 6 3 0 101110011000 Figure 2.5: Bit-vector representation using the binary code. decimal representation. When no radix is speci ed, we assume a radix-10 or radix-2 representation and distinguish among the two by the context. In digital systems, the most frequently used radices are of the form r = 2k , because this simpli es the representation by a bit-vector and produces more e cient implementation of the operations. The representation is binary for r=2, quaternary for r=4, octal for r=8, and hexadecimal for r=16. Also used is r = 10 (decimal) due to the advantages for a human user in having decimal input and output. Representation of digits In the second level of the representation, each of the digits in the digit-vector is represented by a bit-vector according to a code. We now consider these codes. For radix-2, the digit is directly represented by one bit, so no code is needed and there is no di erence between the digit-vector and the bitvector. For radix 2k , a bit-vector of at least k bits is needed to represent a digit. The most used code is the binary code in which the digit is represented in the radix-2 number system. That is, the bit-vector (dk;1 dk;2 : : : d0) represents the digit value d= ; X i=0 k1 di2i as depicted in Table 2.2. The digit-vector is then represented by the concatenation of the bit-vectors for each digit, as illustrated in Figure 2.5. Other ways of encoding the digits are used in some special cases. For example, the Gray code has the property that the bit-vectors corresponding to consecutive digit values di er only in one bit, as shown in Figure 2.6 for octal digits. This property leads to simpler and more reliable implementations of some systems such as analog-to-digital converters. 2.3. Data representation and coding 27 Table 2.2: Binary codes for digits with r = 2k values. Binary Quaternary Octal Hexadecimal Digit Value (Symbol) k = 1 k=2 k=3 k=4 d0 d1d0 d2d1d0 d3d2d1 d0 0 0 00 000 0000 1 1 01 001 0001 2 10 010 0010 3 11 011 0011 4 100 0100 5 101 0101 6 110 0110 7 111 0111 8 1000 9 1001 10 (A) 1010 11 (B) 1011 12 (C) 1100 13 (D) 1101 14 (E) 1110 15 (F) 1111 Digit Gray code 0 000 1 001 2 011 3 010 4 110 5 111 6 101 7 100 (a) 6 5 4 3 101111110010 (b) Figure 2.6: a) Gray code. b) Gray-code bit-vector representation of a digit-vector. 28 Chapter 2. Speci cation of combinational systems Table 2.3: Codes for decimal digits. Digit Value 0 1 2 3 4 5 6 7 8 9 BCD 8421 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 2421 Excess-3 2-Out-of-5 0000 0011 00011 0001 0100 11000 0010 0101 10100 0011 0110 01100 0100 0111 10010 1011 1000 01010 1100 1001 00110 1101 1010 10001 1110 1011 01001 1111 1100 00101 For decimal digits, a minimum of four bits is needed to represent a digit. Several codes which use this minimum are described in Table 2.3. The rst two are weighted codes and the integers over the corresponding columns are the weights. A code is weighted when the digit value is obtained as k ;1 X d = di wi wherein the wi 's are the weights and k is the number of bits. For the BCD (Binary-Coded-Decimal) code, the weights are 8,4,2,1 (and, therefore, is also called the 8-4-2-1 code). Since this is the same as for the hexadecimal code, some systems used for operations for the radix-16 representation can also be used for radix-10. This is one of the reasons for the popularity of the BCD code. The 2-4-2-1 code, which is also weighted, has the property that to obtain the complement of the digit with respect to 9 (that is, the value 9 ; d) each bit of the representation is complemented with respect to 1 (1 ; di). This simple complementation is useful when performing operations such as subtraction. The Excess-3 code is not weighted but it has the same complementation property as the 2-4-2-1 code. The 2-out-of-5 code uses ve bits and represents each value by a bitvector that has two 1's. The ine ciency of using ve bits, instead of the minimum of four, is counter-balanced by the property that an error in a i=0 2.4. Binary speci cation of combinational systems 29 single bit can be detected if a single 0(1) is changed to 1(0), the resulting vector does not represent a digit because it does not have two 1's. Since the decimal representation requires four bits to represent each digit (10 values instead of the 16 values available), the decimal representation is less e cient than a radix-2k representation. That is, for the same range of integers, more bits are needed in a decimal representation than in a radix-2k representation. For example, the representation of a 6-digit decimal integer (ranging from 0 to 106 ; 1) requires 24 bits (four bits per digit), whereas a binary representation requires only 20 bits because (220 ; 1) > 106. 2.4 Binary speci cation of combinational systems We now discuss the speci cation of combinational systems at the binary level. This level is obtained by applying coding functions to the inputs and outputs of a high-level speci cation. The resulting binary systems are implemented by combinational networks, as illustrated later in this chapter and discussed in detail in Chapters 4, 5 and 6. A combinational system with n (binary) inputs and m (binary) outputs (see Figure 2.7a) is represented by a set of m functions, each having as domain the set of binary n-tuples and as range the set f0,1g. Example 2.1 illustrates the representation using two of these functions. The functions with range f0,1g are called switching functions and are central to the study of combinational systems. A switching function of n variables f (xn;1 : : : x1 x0) is a mapping from the set f0 1gn (the set of binary n-tuples) into the set f0,1g. This is illustrated for n = 3 in Figure 2.7b. Note that 0 and 1 are generic names for the two elements of the set and do not necessarily represent the corresponding integers. 2.4.1 Switching functions Tabular representation of switching functions Like any function with a nite domain, a switching function can be represented by a table (which for switching functions is sometimes called a truth table). The table has one row for each value of the domain (input set), so that for n variables the table has 2n rows. To simplify the notation in the table, an integer j is associated with each binary n-tuple in such a way that the n-tuple is the binary representation of j (where the elements 0 and 1 correspond to the integers 0 and 1). That is, for 30 Chapter 2. Speci cation of combinational systems {0,1} 000 x0 x1 Combinational system x x n- 2 n- 1 3 {0,1} z0 z1 001 0 010 011 z m-2 z m-1 (a) 100 101 110 111 (b) 1 Figure 2.7: a) Binary combinational system. b) A switching function for n = 3. the n-tuple (xn;1 : : : x0), xi 2 f0 1g, we have j= n1 i=0 ; X xi2i Example 2.4 The following table depicts a switching function of three variables, both in the binary and in the simpli ed notation. n-tuple notation Simpli ed notation x2x1x0 f (x2 x1 x0) j f (j ) 000 0 0 0 001 0 1 0 010 1 2 1 011 1 3 1 100 0 4 0 101 0 5 0 110 1 6 1 111 1 7 1 Due to the number of rows, the table representation is useful only for functions with a small number of variables. A more manageable representation is obtained when the table is converted into a two-dimensional array by partitioning the variables into two groups. Example 2.5 The followingtwo-dimensional array represents a switching function of ve variables. 2.4. Binary speci cation of combinational systems 31 x2 x1x0 x4x3 000 001 010 011 100 101 110 111 00 0 0 1 1 0 1 11 01 0 1 1 1 1 0 11 10 1 1 0 1 1 0 11 11 0 1 0 1 1 0 10 f (x4 x3x2x1 x0) Since the range of the function is the set f0,1g, it is redundant to specify the whole table it is su cient to list the set of values of j for which the function has value 1. This set is called the one-set of the function. Similarly the zeroset is de ned as the set of values of j for which the function has value 0. The most compact of the two can be used moreover, an arithmetic expression that represents the set is also possible in some cases. For instance, the function in Example 2.4 can be represented by f (x2 x1 x0) = one-set(2,3,6,7) or by f (x2 x1 x0) = zero-set(0,1,4,5) An example of an arithmetic expression to describe a one-set is f (x9 : : : x0) = one-set fj j (j + 1) mod 3 = 0 0 j 1023g This expression represents the function which has value 1 for j = 2 5 8 ::: 1022. It is a very compact representation of a function whose table has 1024 rows. The one-set and zero-set are also referred to as on-set and o -set, respectively. Other useful representations for functions with large n are discussed later in this chapter. One-set and zero-set representations Important switching functions We now present some important switching functions. The four functions of one variable are de ned in Table 2.4. The most interesting of them is the complement (or not) function, which has value 1 when the input has value 0, and value 0 when the input has value 1. The sixteen switching functions of two variables are shown in Table 2.5 because of their importance, some of these functions have special names, as indicated in the table. The 2-variable functions named in Table 2.5 generalize as follows for n variables: the and function of n variables has the value 1 only when all input variables are 1 the or function of n variables has the value 1 when at least one input variable is 1 32 Chapter 2. Speci cation of combinational systems Table 2.4: Switching functions of one variable. x 0 1 0-constant f0 (always 0) 0 0 complement 1-constant (equal to x) (not) (always 1) identity f1 0 1 f2 1 0 f3 1 1 Table 2.5: Switching functions of two variables. x1x0 Function 00 01 10 11 f0 0000 f1 0 0 0 1 and f2 0010 f3 0011 f4 0100 f5 0101 f6 0 1 1 0 exclusive-or (xor) f7 0 1 1 1 or f8 1 0 0 0 nor f9 1 0 0 1 equivalence (xnor) f10 1010 f11 1011 f12 1100 f13 1101 f14 1 1 1 0 nand f15 1111 2.4. Binary speci cation of combinational systems 33 the xor (Exclusive-or) function of n variables has the value 1 when an odd number of input variables is 1. Its name for two variables comes from the fact that it has value 1 whenever one input has value 1 (but not both). The nand and nor functions are the complement of the and and or functions, respectively. The xnor function is the complement of the xor function, that is, it has value 1 when an even number of inputs is 1. The name of equivalence for the two-variable case comes from the fact that it has value 1 when both inputs have the same value. Incomplete switching functions An incomplete switching function is a switching function that is undened for some n-tuples of the domain. The value of the function for these n-tuples is called a don't care and is indicated by a { (a dash) in the tabular representation.1 More formally, an incomplete switching function is a mapping from the set f0 1gn into the set f0,1,{g. Example 2.6 The following table describes an incomplete switching function: xyz 000 001 010 011 100 101 110 111 f 0 1 0 { 1 0 { 1 In a similar fashion as for completely speci ed functions, incomplete functions can be described by the one-set, zero-set, and dc-set. Since now the function has three possible values, two of the three sets are required. For instance, function f (x y z ) in Example 2.6 can be represented by any of the following pairs of sets: one-set(1,4,7), zero-set(0,2,5) ] one-set(1,4,7), dc-set(3,6) ] zero-set(0,2,5), dc-set(3,6) ] Incomplete switching functions occur whenever some n-tuple value is not allowed at the input of a combinational system. 1 Other symbols used in the literature for the don't care value are x, d, dc, and . 34 Chapter 2. Speci cation of combinational systems Example 2.7 Consider a system whose input set is a decimal digit repre- sented in the BCD code. That is, the input set consists of the bit-vectors I = f0000 0001 :: : 1001g. The output z is equal to 1 if the input digit is odd and is 0 otherwise. The switching function corresponding to this system is incomplete because the values of the domain 1010, 1011, 1100, 1101, 1110, and 1111 do not represent any value of the input set and, therefore, never occur. Complicated switching functions can be represented by combining several elementary functions. Such combinations are called compositions. Since the values 0 and 1 in the range of the function are also the values of the components of the argument x, a composition of switching functions is also a switching function. For example: and(x3 x2 x1 x0 ) = and(and(x3 x2 ) and(x1 x0 )) xor(x1 x0 ) = or(and(not(x0 ) x1 ) and(x0 not(x1 ))) maj(x3 x2 x1 x0 ) = or(and(x3 x2 x1 ) and(x3 x2 x0 ) and(x3 x1 x0 ) and(x2 x1 x0 )) Composition of switching functions The majority function maj has value 1 when more than half of the variables have value 1. Consequently, for four variables it can be described by the or function of the and functions of all combinations of three variables. These identities can be checked by constructing the tables of the functions. Composition of switching functions is also the basis for the network implementation of combinational systems, as discussed in Chapter 4. 2.4.2 Switching expressions Switching expressions (also called formulas or forms) are used to represent completely speci ed switching functions in a way similar to that in which arithmetic expressions represent numerical functions. In structure these switching expressions are almost the same as arithmetic expressions, except for the inclusion of the additional operator complement. This is shown by the following rules for construction of a valid switching expression. A switching expression (SE) of n variables is a string of symbols for the variables, the binary operators and , the unary operator 0 , and (). It is formed as follows: 1. The symbols 0 and 1 are SEs. 2. A symbol representing a binary variable is a SE. 3. If A and B are SEs, then 2.4. Binary speci cation of combinational systems 35 (A)0 is a SE. This is referred to as \A complement." An alternative symbol to denote A complement is A. (A) (B ) is a SE. This is referred to as \A or B " it is also called \A plus B " or \sum" due to the similarity with the corresponding arithmetic symbol. (A) (B ) is a SE. This is referred to as \A and B " it is also called \A times B " or \product" due to the similarity with the corresponding arithmetic symbol. Some parentheses can be eliminated from a SE due to the associativity of and of that is, (a b) c can be written a b c, whereas (a b) c can be written as a b c. Also, the can be omitted to simplify the notation. For example, the expression ((x1)0 x2) (x3 ((x4 x5) (x6 )0 )) x7 can be written as (x01x2 x3 x4 x5x06 )x7 To determine whether a given string is a switching expression, it is necessary to check whether it can be constructed by application of the rules. The following are well-formed switching expressions x0 (x1 0 x2 )x3 x1 x2 x03 1 0(x y) whereas the following ones are not \This is a switching expression00 As mentioned, the syntactic rules are very similar to those used for arithmetic expressions with + and (or ). The only di erence is that the symbol 0 is also included in switching expressions. Since both arithmetic and switching expressions appear in the text, the symbol + denotes addition, whereas is used in switching expressions. The preceding de nition is syntactical: it gives rules for the construction of switching expressions but does not assign any meaning to the string. The semantics are obtained by relating a switching expression with a switching function. To do this, we introduce a particular Boolean algebra (see Appendix A) called switching algebra which is used to evaluate switching expressions. precedence rules for the operations: 0 precedes which precedes 36 Chapter 2. Speci cation of combinational systems , , and 0 which are called or, and, and not (complement), respectively. These operations are de ned by the following tables, in which the columns correspond to the values of one operand, the rows to the values of the other, and the entries to the result of the operation: 0 01 01 001 000 01 111 101 10 Note the correspondence between these operations and the switching functions or, and, and not. The switching algebra is used to evaluate switching expressions. Each of the variables appearing in an expression is assigned a value from the set f0,1g and the evaluation is done using the de nition of the operators in the switching algebra. To assign values unambiguously, the variables appearing in the switching expression are ordered to form a vector. For example, E (x y z ) = xyz 0 y0 z is evaluated for assignment (0 1 1) by making x = 0, y = 1, and z = 1. We call E (0 1 1) the value of the expression E for assignment (0 1 1). Example 2.8 Consider the switching expression E (x2 x1 x0) = x2 x02 x1 x1x00 The value of E for assignment (1 0 1) is E (1 0 1) = 1 10 0 0 10 = 1 0 0 = 1 When an expression is evaluated for all the possible assignments of values to the variables, the set of pairs (assignment, value) is a switching function. We say that the expression represents the resulting function. Example 2.9 The switching expression E (x2 x1 x0) = x2 x02x1 x1x00 represents the switching function f : x2x1x0 f 000 0 001 0 010 1 011 1 100 1 101 1 110 1 111 1 Switching algebra and expression evaluation The switching algebra consists of two elements 0 and 1, and the operations Representing switching functions by switching expressions 2.4. Binary speci cation of combinational systems 37 In particular, the following expressions represent the switching functions described in Table 2.5. These can be checked by comparing the function de nition in Table 2.5 with the tables obtained by evaluating the expressions. 2 variables n variables and x1x0 xn;1xn;2 : : :x0 or x1 x0 xn;1 xn;2 : : : x0 xor x1x00 x01 x0 xnor x01x00 x1 x0 nand (x1x0)0 (xn;1xn;2 : : :x0)0 0 nor (x1 x0 ) (xn;1 xn;2 : : : x0 )0 As discussed in detail in Chapter 3, a gate is a module implementing a simple switching function. These gates are the basic building blocks used for implementing more complex combinational modules. Figure 2.8 shows the symbols for gates corresponding to the basic switching functions of one and two variables. The corresponding switching expressions are also given. The symbols generalize for more inputs, as illustrated for and and or gates in Figure 2.9. Switching functions and gates function. We write E1 = E2 to denote that E1 and E2 are equivalent. Example 2.10 The following two switching expressions are equivalent W = x1x0 x01 Z = x01 x0 The corresponding switching functions are x1x0 W Z 00 1 1 01 1 1 10 0 0 11 1 1 The set of switching expressions is divided into classes and all switching expressions in a class represent the same function, as shown in Figure 2.10. Equivalence of expressions is important because it allows us to choose from a class the expression that is most suitable for a speci cation. In addition, since switching expressions are related to some implementations, it is possible to choose the expression that results in the best implementation. Equivalent switching expressions Two switching expressions are equivalent if they represent the same switching 38 Gate type NOT Chapter 2. Speci cation of combinational systems Symbol Switching expression x x x1 x0 x1 x0 x1 x0 x1 x0 x1 x0 x1 x0 or z z z z = x’ AND z = x1x0 OR z z = x 1+ x 0 NAND z z = ( x 1 x 0 )’ NOR z z = ( x 1+ x 0 )’ XOR z z = x 1x ’ + x ’ x 0 0 1 = x1 + x0 z = x1 x ’ + x 1x 0 ’0 XNOR z Figure 2.8: Gate symbols. Gate type Symbol Switching expression AND x n-1 x n-2 z x0 x n-1 x n-2 z = x n-1 x n-2 .... x 0 OR z x0 z = x n-1 + x n-2 ....+x 0 Figure 2.9: n-input and and or gate symbols. 2.4. Binary speci cation of combinational systems Set of switching functions Set of switching expressions 39 Equivalent expressions Figure 2.10: Correspondence between switching functions and switching expressions. Table 2.6: The principal identities of Boolean algebra. 1. a b =b a ab 2. a (bc) = (a b)(a c) a(b c) 3. a (b c) = (a b) c a(bc) =a b c 4. a a =a aa 5. a a =1 aa 6. 1 a =1 0a 7. 0 a =a 1a 8. (a ) = a 9. a ab = a a(a b) 10. a ab =a b a(a b) 11. (a b) = a b (ab) 0 0 0 0 0 0 0 0 0 0 = ba = (ab) (ac) = (ab)c = abc =a =0 =0 =a =a = ab =a b 0 0 Commutativity Distributivity Associativity Idempotency Complement Identity Involution Absorption Simpli cation DeMorgan's Law Algebraic method of obtaining equivalent expressions Since the switching algebra is a Boolean algebra, all Boolean algebra identities can be used to transform a switching expression without changing its value. Consequently, we can apply an algebraic method to obtain equivalent expressions. Table 2.6 lists the identities that are most useful for this purpose proofs of these identities are provided in Appendix A. Example 2.11 The following expressions are equivalent: E1(x2 x1 x0) = x2x1 x2x01 x2 x0 E2(x2 x1 x0) = x2 Applying the transformations allowed in the Boolean algebra, we get 40 Chapter 2. Speci cation of combinational systems x2 x1 x2x01 x2x0 = x2 (x1 x01 ) x2x0 = x2 1 x2 x0 = x2 (1 x0) = x2 1 = x2 using ab ac = a(b c) using a a0 = 1 using ab ac = a(b c) using 1 a = 1 using a 1 = a We now consider a special form of switching expression, namely the sum of products (sop) form. Moreover, we de ne minterms and show that each switching function is uniquely represented by a sum of minterms. A literal is either an uncomplemented or a complemented variable. A product term (P) is either a single literal, or the and (product) of literals. A sum of products (SOP) is a switching expression consisting either of a single product term, or the or (sum) of product terms. These de nitions are illustrated by the following examples: Literals x, y, z 0, x0 Product terms x0 , x2x1 , x3x1 x00 Sum of products x02 x03x1 x03x01x0 The correspondence among sums of products and and-or gate networks is illustrated in Figure 2.11. A minterm of n variables is a product term of n literals, in which each variable appears exactly once either in uncomplemented or complemented form. For example, for n = 3, x2x01 x00 and x02 x01x0 are minterms whereas x2 x01 and x1x1 x1x0 are not. There are 2n minterms of n variables. These minterms are denoted m0 , m1 ,...,mj ,...,m2n;1, wherein j is the integer whose binary representation is obtained when a 1 is associated with each uncomplemented variable and a 0 with each complemented variable in the minterm. For example, the minterm x3x02 x01x0 is denoted m9 because 1001 represents the integer nine. This representation is called the m-notation. Each minterm has value 1 only for one assignment of the variables. This is so because the product has value 1 only when all literals have value 1 and this occurs only for one assignment, since all other assignments produce at least one literal with value 0. For example consider the minterm m11 = x3 x02x1x0 This has value 1 for the assignment (x3 = 1 x2 = 0 x1 = 1 x0 = 1) and value 0 for all other assignments. As a consequence, minterm mj represents the switching function whose oneset has only element j that is, the function has only one 1 in its table and this 1 is in row j . This is illustrated for n = 3 as follows: Sum of products and sum of minterms 2.4. Binary speci cation of combinational systems x3 x1 41 x0 z = x 3 x 1x’0 (a) x2 x3 x1 x1 x0 x’2 z = x’2 + x’3x 1 + x’3x’1x 0 x’3x 1 x’3x’1x 0 (b) Figure 2.11: Sum of products and and-or gate network: a) Product term. b) Sum of products. x2 x1 x0 000 001 010 011 100 101 110 111 m0 m1 m2 m3 m4 m5 m6 m7 x2 x1 x0 x2 x1 x0 x2 x1 x0 x2 x1 x0 x2 x1 x0 x2 x1 x0 x2 x1 x0 x2 x1 x0 0 0 0 0 0 0 0 0 0 0 0 0 A sum of minterms is a sum of products in which all products are minterms and no minterm is repeated. For example, E (x2 x1 x0) = x02x01 x0 x02 x1x00 x2 x1x00 is a sum of minterms of three variables. This can be written as E (x2 x1 x0) = m1 m2 m6 or in the compact notation X E (x2 x1 x0) = m(1 2 6) 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 42 x2 x0 x0 x1 x2 x1 Chapter 2. Speci cation of combinational systems x1 m1 m2 z =Σ m(1,2,6) m6 Figure 2.12: Gate network corresponding to E (x2 x1 x0) = P m(1 2 6). Note that, since the order of the products does not change the value of the expression, we put the minterms in ascending order. A gate network for this expression is shown in Figure 2.12. Since each of the minterms has value 1 for one assignment, the sum of minterms has value 1 for as many assignments as minterms in the expression. In the example above, the sum of minterms has value 1 for three assignments, namely, for (x2 = 0 x1 = 0 x0 = 1), for (x2 = 0 x1 = 1 x0 = 0), and for (x2 = 1 x1 = 1 x0 = 0). Consequently, this sum of minterms represents the function that has value 1 for those same assignments. Any switching function can be represented by a sum of minterms. This expression is the sum of the minterms corresponding to the elements in the one-set representation of the function. That is, if E (x ) = then E represents f because the sum evaluates to 1 whenever one of the minterms evaluates to 1 and minterm mj evaluates to 1 only when the assignment corresponds to x = j. The minterms that appear in the sum of minterms that represents function f are called the minterms of f . X m(fj j f (j ) = 1g) Example 2.12 The sum of minterms that represents the following function 2.4. Binary speci cation of combinational systems 43 j x2 x1 x0 0 000 1 001 2 010 3 011 4 100 5 101 6 110 7 111 is E= f 0 0 1 1 0 1 0 0 X m(2 3 5) = x02x1 x00 x02 x1x0 x2 x01x0 The sum of minterms that represents a function is unique, so it is a canonical representation such an expression is also called a canonical sum of products (CSP). Since every function is represented by a sum of minterms, every switching expression has an equivalent sum of minterms. The equivalent sum of minterms of a given expression can be obtained by rst constructing the tabular representation of the function or by applying algebraic transformations as shown in the following example. Example 2.13 The sum of minterms equivalent to the expression E (x2 x1 x0) = x2 (x1x0 )0 x1x00 is obtained by application of algebraic identities as follows: E (x2 x1 x0) = x2x01 x2x00 x1x00 = x2x01 (x0 x00 ) x2x00 (x1 x01 ) x1x00 (x2 x02 ) = x2x01 x0 x2x01 x00 x2 x00x1 x2x00x01 x1x00x2 x1x00 x02 = Px1 x00 x2x01 x00 x2 x01x0 x2x1x00 x02 = m(2 4 5 6) Alternatively, the sum of minterms can be obtained by constructing the table of the function. This is done by evaluating the expression for all assignments, as follows: implies that the function is 1 for assignments x1x00 = 1 010 and 110 x2(x1x0 )0 = 1 100, 101, and 110 The corresponding tabular representation is 44 Chapter 2. Speci cation of combinational systems j f (j ) 00 10 21 30 41 51 61 70 Since the table of the function has value 1 for rows 2,4,5,6, the sum of minterms P is E (x2 x1 x0) = m(2 4 5 6). In an analogous way to the sum of products and sum of minterms, we now de ne product of sums (pos) and product of maxterms. All the development in this part can be obtained from the discussion in the previous one by replacing product by sum (and vice versa), 0 by 1 (and vice versa), and uncomplemented by complemented (and vice versa). This is due to the duality properties of the operations and and or in Boolean algebras (see Appendix A). We follow the same sequence as in the earlier discussion but with less explanation. A sum term (S) is either a literal or a sum of literals. For example, x2, (x5 x6 ), and (x1 x02 x4) are sum terms. A product of sums (POS) is a switching expression consisting of a single sum term or several sum terms connected by the and operator (product). An example is x0(x03 x2)(x03 x02 x1). The correspondence between products of sums and or-and gate networks is illustrated in Figure 2.13. A maxterm of n variables is a sum term in which each variable appears exactly once either in uncomplemented or complemented form. For example, for n = 3, x02 x1 x0 and x2 x01 x00 are maxterms whereas x2 x1 is not. There are 2n maxterms of n variables. These maxterms are denoted by M0 , M1 ,: : : ,Mj ,: : : ,M2n ;1 , wherein j is the integer whose binary representation is obtained when a 0 is associated with each uncomplemented variable and a 1 with each complemented variable. For example, the maxterm (x3 x02 x01 x0) is denoted M6 because 0110 represents the integer six. This representation is called the M -notation. Note the di erence with respect to the notation for minterms, in which uncomplemented variables are associated with 1 and complemented with 0. Product of sums and product of maxterms 2.4. Binary speci cation of combinational systems x4 x2 x1 (a) 45 z = x 4 + x’2 + x 1 x3 x2 x1 x2 x0 x 2 + x’3 (b) x’3+ x’2 + x 1 z = x 0( x 2 + x’3 )( x’3+ x’2 + x 1) Figure 2.13: Product of sums and or-and gate network. a) Sum term. b) Product of sums. Each maxterm has value 0 only for one assignment of the variables. This is so because the sum has value 0 only when all literals have value 0. For example, the maxterm M10 = x03 x2 x01 x0 has value 0 only for the assignment x3 = 1 x2 = 0 x1 = 1 x0 = 0. Maxterm Mj represents the function whose zero-set contains only element j , that is, the function has only one 0 in its table and this 0 is in row j . A product of maxterms is a product of sums in which each product is a maxterm and there are no repeated terms. The compact notation for a product of maxterms is E (x) = Y M (fj jf (j ) = 0g) Example 2.14 The product of maxterms E (x2 x1 x0) = (x2 x1 x0)(x02 x1 x00)(x02 x01 x0) can also be denoted using M -notation by E (x2 x1 x0) = M0 M5 M6 Q M (0 5 6) = A gate network for this expression is shown in Figure 2.14. 46 x2 x0 x1 Chapter 2. Speci cation of combinational systems M0 x1 x2 x0 x1 M5 z = Π M(0,5,6) x0 M6 Figure 2.14: Gate network corresponding to E (x2 x1 x0) = M (0 5 6). A product of k maxterms represents a switching function that has value 0 for k assignments. The representation of a function by a product of maxterms is unique this is a canonical representation also called a canonical product of sums. This representation is more compact than sum of minterms when the number of zeros is small. Q Example 2.15 The product of maxterms that represents the following function j x2x1 x0 0 000 1 001 2 010 3 011 4 100 5 101 6 110 7 111 f 0 1 1 0 1 1 1 0 is E (x2 x1 x0) = M (0 3 7) = (x2 x1 x0)(x2 x01 x00 )(x02 x01 x00) Q Switching expressions for incompletely speci ed functions Incompletely speci ed switching functions can be represented by two expressions: one corresponding to the 1's (or 0's) of the function and the other to the don't cares. Example 2.16 The following incompletely speci ed function 2.5. Examples of speci cations 47 x1 x0) 1 0 1 1 0 0 is described by P m(0 4 5) and P d:c:(2 3). x2x1x0 f (x2 000 001 010 011 100 101 110 111 Conversion among canonical forms The conversion among canonical forms is straightforward the sum of minterms corresponds to the one-set of the function, whereas the product of sums corresponds to the zero-set. Therefore, obtaining one canonical form knowing the other consists of including the non-appearing indices. That is, X m(fj j f (j ) = 1g) = Y M (fj j f (j ) = 0g) Example 2.17 The m-notation representing a function f (x y z ) is X m(0 4 7) Since the function has three variables, the equivalent expression in M -notation is Y M (1 2 3 5 6) 2.5 Examples of speci cations We now give three examples of binary speci cation of combinational systems, illustrating the various description methods discussed in the previous sections. Example 2.18 The high-level speci cation of a lock control is Inputs: CLASS 2 f0,1,2,3g GROUP 2 fA,B,Cg Outputs: LOCK 2 fopen,closedg Function: LOCK = open closed if CLASS 2 and GROUP = A otherwise This function can also be given by the following table: 48 Chapter 2. Speci cation of combinational systems LOCK To obtain a binary description, we code the input and output. A possible coding is LOCK L GROUP G1G0 CLASS C1 C0 open 1 A 11 0 11 closed 0 B 10 1 10 C 00 2 01 3 00 Using these codes, the corresponding switching function is G1 G0 C1C0 00 01 10 11 00 0 - 0 1 01 0 - 0 1 10 0 - 0 0 11 0 - 0 0 L and a switching expression for the output is 0 L = G0 C1 Example 2.19 A radix-4 digit-comparatormodule compares two radix-4 digits and produces one output with values G(reater), E(qual), and S(maller). The high-level speci cation is Inputs: x y 2 f0 1 2 3g Output: z 2 fG,E,Sg 0 1 CLASS 2 3 A closed closed open open GROUP B closed closed closed closed C closed closed closed closed The tabular description of this function is 0 1 x2 3 0 E G G G 8 G if x > y < Function: z = : E if x = y S if x < y 1 S E G G y 2 S S E G 3 S S S E z 2.5. Examples of speci cations 49 To obtain a binary description we have to code the input and output values on bit-vectors. As discussed in Section 2.3, the most used code is the binary code in which the radix-4 digit is represented by the corresponding radix-2 bit-vector. That is, x = 2x1 + x0 and y = 2y1 + y0 wherein (x1 x0) and (y1 y0) are the bit-vectors representing x and y, respectively. The three-valued output requires at least two binary variables. To simplify the binary description, we use three binary variables and the following code: z z2 z1 z0 G 100 E 010 S 001 The resulting binary system can be described by the following logical expressions: 1 if x1 > y1 or (x1 = y1 and x0 > y0 ) z2 = 0 otherwise 1 if x1 = y1 and x0 = y0 z1 = 0 otherwise 1 if x1 < y1 or (x1 = y1 and x0 < y0 ) z0 = 0 otherwise From these logical expressions, we can obtain the switching functions described by the following table: y1 y0 x1x0 00 01 10 11 00 010 001 001 001 01 100 010 001 001 10 100 100 010 001 11 100 100 100 010 z2 z1 z0 The sum of minterms are described in m-notation by z2 (x1 x0 y1 y0) = z1 (x1 x0 y1 y0) = z0 (x1 x0 y1 y0) = X m(4 8 9 12 13 14) X m(0 5 10 15) X m(1 2 3 6 7 11) 50 Chapter 2. Speci cation of combinational systems Example 2.20 A combinational system has two 8-bit inputs, representing al- phanumeric characters, and a binary output. The system performs matching of the input characters. The high-level speci cation is Inputs: x y 2 fA B : : : Z a b : : : z 0 1 : : : 9 + = : ::g Outputs: z 2 f0 1g 1 if x = y 0 if x 6= y The input bit-vectors are x = (x7 : : : x0) and y = (y7 : : : y0). Since there are 16 binary input variables a table is impractical. We can obtain directly a switching expression by noticing that the output is 1 only when the two bit-vectors are bitwise equal. That is, 0 0 0 z = (x7 y7 x07y7 )(x6 y6 x06y6 )(: : :)(x0y0 x00y0 ) Function: z = As stated earlier, the speci cation of a combinational system consists of the input set, output set, and the input-output function. In principle, any way of describing these components is acceptable. However, to be able to communicate these speci cations, and to have a version which can be used to simulate the behavior of the system in a computer, some standard languages have been developed. These languages are called hardware description languages (hdl) because they are used to describe hardware. Several hardware description languages have been proposed in the past, with capabilities to describe the speci cation and implementation of hardware systems at di erent levels. Two such languages, namely vhdl and Verilog, have recently become standards both are widely used nowadays. These languages have become popular among designers, vendors and developers as a medium to describe and communicate hardware designs for the purposes of speci cation, simulation, description of implementation, and synthesis (automatic realization) with them, a single representation is used throughout the entire design process, including simulation driven by the hdl-based description. Languages such as vhdl or Verilog support behavioral speci cations at a high-level as well as at the binary level. In other words, using the language one can rst provide a rough speci cation of the system (its overall behavior), which can be re ned later. Moreover, at any time the speci cation is \complete" in the sense that it can be used for other phases in the design process (such as simulation). In this section we present speci cations using the language vhdl (a subset of vhdl), which has been derived with the objective of providing a simpler language suitable as an introduction to the eld, but which follows the features of its ancestor. Indeed, the vhdl descriptions used in this book are executable 2.6 Speci cation using vhdl 2.6. Speci cation using vhdl 51 Module Inputs (Function and delays) Outputs Figure 2.15: Basic component in vhdl in a computer after compiling them using a vhdl compiler. Only some vhdl statements and constructs are available in vhdl vhdl features not used in this book are not included in vhdl (in other words, vhdl has capabilities which we will not explore). Some elements of vhdl are quite intuitive and can be inferred from programming languages, so we use them without formal introduction. We focus rst on the elements of the language required for behavioral speci cation of combinational systems. (Additional features of the language suited only for describing the implementations are given later.) Elements of Modules: entity and architecture inputs outputs function and delays. vhdl The basic component described in vhdl is a module (see Figure 2.15), which is speci ed by: Since for the time being we are concerned only with the functional speci cation, we omit the delays. The inputs and outputs are speci ed by a design ENTITY, composed by an entity name and an entity declaration, in which each input and each output is represented by a PORT declaration (we use upper case characters to represent reserved words in the language, although the language is case insensitive). An example of an entity is as follows: ENTITY adder IS PORT(x,y: IN BIT z : OUT BIT) END adder 52 Chapter 2. Speci cation of combinational systems This declaration speci es a design entity named adder, which has two input ports (x,y) and one output port (z), all of them of type BIT (the concept of type is described later in this section). Input ports are identi ed by the keyword IN, whereas output ports are identi ed by the keyword OUT. The function of the module is described by ARCHITECTURE bodies a given module may have several architecture bodies, which may correspond to di erent levels of detail in the description, or to alternative versions of the module. There are two types of architecture bodies: Behavioral architecture: the functionality of the entire module is described as a whole, using high-level expressions and language constructs. The behavior of the module is described as a process whose body consists of a set of statements. Structural architecture: the module is described as the interconnection of simpler modules (hierarchical description) the simpler modules are described independently. The functionality of the higher-level modules is determined from the behavior of the simpler modules and their interconnection. We consider now only behavioral architectures structural architectures are discussed in the chapters on implementation. The overall format of a behavioral architecture body is ARCHITECTURE arch_name OF module_name IS BEGIN PROCESS process_declarations BEGIN behavioral_description_statements END PROCESS END arch_name This declaration speci es an architecture named arch name of a module (design entity) called module name arch name is an arbitrary name, whereas module name is the name given to the module in the ENTITY declaration. The architecture consists of a PROCESS, which contains the statements describing the behavior of the module. Example: speci cation of a radix-4 digit-comparator Before addressing the details of vhdl, let us illustrate the language with an example the speci c language constructs used in this example, as well as general concepts regarding the language, are described later in this section. Let us consider the behavioral description of the radix-4 digit-comparator speci ed in Example 2.19, both at a high-level as well as at the binary level. 2.6. Speci cation using vhdl 53 High-level speci cation The following entity declaration describes a radix-4 digit-comparator module which consists of two input ports of type Radix4 (integers in the range 0 to 3), as well as an output port of type MagnComp=fG,E,Sg: USE WORK.chap2_defs.ALL ENTITY radixfour_comp IS PORT(x,y : IN Radix4 z : OUT MagnComp) END radixfour_comp -- package contains definition of -- Radix4 and MagnComp -- inputs -- output A corresponding architecture body is ARCHITECTURE behavioral OF radixfour_comp IS BEGIN PROCESS (x,y) BEGIN IF (x > y) THEN z <= G ELSIF (x = y) THEN z <= E ELSE z <= S END IF END PROCESS END behavioral This architecture body contains a signal assignment statement to z, which depends on the result from comparing the input operands. Binary speci cation Let us consider now a binary description of the radix-4 digit-comparator. At this level, the operands and result are represented in the radix-2 number system by bit-vectors. In such a case, the entity declaration indicates that ports are bit-vectors, as follows: USE WORK.chap2_defs.ALL ENTITY binary_radixfour_comp IS PORT(x,y : IN BitVector2 z : OUT BitVector3) END binary_radixfour_comp -- package contains definition of -- BitVector2 and BitVector3 -- inputs -- outputs 54 Chapter 2. Speci cation of combinational systems The corresponding architecture body consists of a process whose statements operate on bit-vectors, as follows: ARCHITECTURE behavioral OF binary_radixfour_comp IS BEGIN PROCESS (x,y) BEGIN IF (to_natural(x) > to_natural(y)) THEN z <= "100" ELSIF (to_natural(x) = to_natural(y)) THEN z <= "010" ELSE z <= "001" END IF END PROCESS END behavioral The behavior of the module is described by a conditional statement which compares the value of the input signals, and assigns the corresponding code of the result to the output signal. The function to natural is required to convert each input signal (of type BitVector2) into an integer number so they can be used in the arithmetic comparison. The descriptions given above use some user-de ned elements (constructs which are not part of vhdl), such as BitVector2 and the function to natural these elements must be speci ed separately through a construct called PACKAGE, as follows: PACKAGE chap2_defs IS SUBTYPE Radix4 IS TYPE MagnComp IS TYPE BitVector2 IS TYPE BitVector3 IS INTEGER RANGE 0 TO 3 (G,E,S) ARRAY (1 DOWNTO 0) OF BIT ARRAY (2 DOWNTO 0) OF BIT FUNCTION to_natural(x: BitVector2) RETURN NATURAL END chap2_defs PACKAGE BODY chap2_defs IS FUNCTION to_natural(x: BitVector2) RETURN NATURAL IS BEGIN CASE x IS WHEN "00" => RETURN(0) WHEN "01" => RETURN(1) WHEN "10" => RETURN(2) WHEN "11" => RETURN(3) 2.6. Speci cation using vhdl END CASE END to_natural END chap2_defs 55 With these examples in mind, let us now address the features of the language. As already stated, in this chapter we only describe features required for the speci cation of combinational systems features used for other type of descriptions are introduced in later chapters, as needed. Values are represented in vhdl by SIGNALS, which are time-functions. Ports are the physical channels through which input/output values are transmitted into and out from a module input and output signals are attached to the input and output ports, respectively. Input signals are \used" inside the modules, whereas output signals are \assigned" values inside the modules. In particular, a signal is used in a behavioral architecture when it appears in the righthand side of an expression a behavioral architecture assigns values to an output signal through a signal assignment statement denoted by the symbol <=, such as x <= '1' x <= u + y -- binary value 1 is assigned to x -- value of (u+y) is assigned to x Signals, variables and constants (the symbol \--" denotes the start of a comment which ends at the end of the line) VARIABLEs are used to aid in the description of a module, such as in the decomposition of a complex function into steps using variables to keep intermediate results. For example, a function that counts the number of bits set to 1 in a bit-vector can keep the partial count in a variable while a loop traverses the vector. Variables receive values by variable assignments, denoted by the symbol \:=". An example is a := x + y In addition to signals and variables, vhdl descriptions may use CONSTANTs, which maintain a constant value. The values of signals, variables, and constants can correspond to di erent data TYPEs, such as INTEGER, REAL, BIT, and non-numeric sets. Data types are characterized by a name, a set of values, and a set of operations. vhdl has the following classes of types: Data types and object declarations 56 Chapter 2. Speci cation of combinational systems scalar types: includes integer, oating point, types de ned by an enumeration of their values, and physical types and composite types: these correspond to arrays of scalar types. Prede ned vhdl scalar types are: TYPE INTEGER IS RANGE -2,147,483,647 TO 2,147,483,647 -- -(2**31 - 1) to 2**31 - 1 TYPE REAL IS RANGE -1.0E+38 TO 1.0E+38 TYPE BOOLEAN IS (FALSE, TRUE) TYPE BIT IS ('0', '1') TYPE CHARACTER IS (....,'A','B','C',...,'a','b','c',...'0','1',...) TYPE TIME IS RANGE 0 TO 2,147,483,647 UNITS ps ns us sec min hr END UNITS Note that type BIT is de ned as the enumeration of characters '0' and '1', not the integers with the same name. The prede ned type CHARACTER corresponds to the enumeration of all the characters available in the ascii set. Individual characters are enclosed in single quotes, whereas a string of characters is enclosed in double quotes (i.e., 'a',"abc"). Values of type TIME must be speci ed in any of the units indicated. Prede ned array types in vhdl are TYPE STRING IS ARRAY(POSITIVE RANGE <>) OF CHARACTER TYPE BIT_VECTOR IS ARRAY(NATURAL RANGE <>) OF BIT Note that the de nition of type STRING and BIT VECTOR do not specify the size of the corresponding array this is known as an unconstrained array speci cation. The de nition of a signal of this type must specify the range. In addition to the prede ned types, it is possible to de ne types (called user-de ned types). Examples of user-de ned enumerated types are: TYPE FivePrimes TYPE Vowels TYPE Colors IS (1,3,5,7,11) IS ('a','e','i',o','u') IS (blue, green, red, yellow) Examples of user-de ned array types are TYPE BitVector4 IS ARRAY (3 DOWNTO 0) OF BIT TYPE BitVector8 IS ARRAY (7 DOWNTO 0) OF BIT TYPE Memory IS ARRAY(INTEGER RANGE <>) OF BitVector8 A SUBTYPE is a subset of a type obtained by constraining its range vhdl prede ned subtypes are SUBTYPE NATURAL IS INTEGER RANGE 0 TO 2,147,483,647 SUBTYPE POSITIVE IS INTEGER RANGE 1 TO 2,147,483,647 Examples of user-de ned subtypes are 2.6. Speci cation using vhdl SUBTYPE ByteInt SUBTYPE TComplByteInt SUBTYPE LowerCase IS INTEGER RANGE 0 TO 255 IS INTEGER RANGE -128 TO 127 IS CHARACTER RANGE 'a' TO 'z' 57 teger objects are assigned the smallest value, whereas enumerated type objects are assigned the rst value in the enumeration list. For example: SIGNAL SIGNAL SIGNAL SIGNAL CONSTANT VARIABLE VARIABLE clk : m,n : x_in : y_in : count_limit: count : z : BIT INTEGER BitVector4:= ('0','1','0','0') BitVector4:= ("0101") INTEGER:= 20 INTEGER:= 1 BitVector8:= (1=>'1',3=>'1',others=>'0') The data type of signals, variables and constants are speci ed with object declarations, which also assign an initial value to the object by default, in- In these examples, signal clk is assigned the initial default value '0' and m,n are assigned the default value -2,147,483,647 all other objects have initial values assigned explicitly. In the case of x in, y in, the initial value of the elements of the arrays are indicated in left-to-right order, either as a set of characters (enclosed in single quotes) or as a string (enclosed in double quotes) on the other hand, in z the elements are given in arbitrary order. de ned for the type of the corresponding data objects, otherwise the expression is illegal. The result of an expression is a data object of the type generated by the expression, which can be assigned to a signal or variable of the same type. Examples are SIGNAL x,y,z: INTEGER VARIABLE a,b,c: BitVector4 x+y+z a OR b ----------produces an INTEGER result produces a result of type BitVector4, according to the definition of the operator OR for this type produces a result of the type defined by operator func for operand of type INTEGER produces a result of the type defined by operator op for operands of type BitVector4 and INTEGER illegal if such a definition does not exist Expressions Expressions are built from data objects and operators. The operators must be func(x) a op x Basic arithmetic operators (such as +, -, *, /) are de ned for the di erent data types, including operations on digit-vectors. These operators accept 58 Chapter 2. Speci cation of combinational systems operands of a given type, and produce a result also of the same type. For example, the operator + is prede ned for operands of type BIT VECTOR, in which case these operands (and the result) are interpreted as the radix-2 representation of integers. The basic logic operations (such as AND,OR,XOR) are used with operands of type BIT or BOOLEAN bit operands are normally used for binary (hardwarerelated) expressions, whereas boolean operands are used for logic (languagerelated) expressions. These operators also accept operands of type BIT VECTOR, in which case the operation is performed on the corresponding bits of the operands. These are referred as bitwise operations. For example, VARIABLE a: BitVector4 := ('0','1','1','1') VARIABLE b: BitVector4 := ('1','1','0','0') VARIABLE c: BitVector4 c := a AND b -- produces c:=('0','1','0','0') Subtypes use the operators de ned for the corresponding type, and generate a result of the type. For example, if x,y are signals of subtype ByteInt, then x+y produces a result of type INTEGER such a result may also be of subtype ByteInt if it ful lls the corresponding range constraint. Control ow statements used to describe the behavior of modules include IF statement, such as IF (clk = '1') AND (x = '1') THEN z := a OR b ELSIF (clk = '0') THEN z := '0' END IF Control ow statements CASE statement, such as CASE Data IS WHEN "000" => k := 1 WHEN "111" => k := 0 WHEN others => k := k+1 END CASE in which the di erent values of Data appear preceded by the keyword WHEN the default case is indicated by the line WHEN others, which, if it exists, must be the last entry of the CASE statement. 2.6. Speci cation using vhdl FOR LOOP 59 statement, such as FOR i IN 1 TO 20 LOOP count := count + a(i) END LOOP FOR i IN 20 DOWNTO 1 LOOP count := count + a(i) END LOOP WHILE LOOP statement, such as WHILE (a = b) LOOP i:= i+1 a:= x(i) b:= y(i) END LOOP The execution of loop statements can be interrupted with statements NEXT and EXIT. NEXT forces execution to continue with the next iteration of a loop, whereas EXIT forces execution to continue at the statement that follows the loop. Functions and procedures are used to encapsulate speci c functionalities, in the same way as in programming languages. These constructs are useful to represent speci c hardware functions that are part of a module, or to contain some functionality needed by the description. Functions return a single result, whereas procedures may return more than one result. The format of these constructs is: FUNCTION func_name(parameter_list) RETURN return_type IS function_declarations BEGIN function_statements RETURN(return_variable) END FUNCTION PROCEDURE proc_name(parameter_list) IS procedure_declarations BEGIN procedure_statements END PROCEDURE Functions and procedures 60 Chapter 2. Speci cation of combinational systems The declarations section of these statements de nes types, variables and constants used by the function or procedure the statements section contains the statements that describe the corresponding behavior. Functions contain a RETURN statement with a single argument of the type speci ed in the function header. The following example illustrates these features. Example 2.21 The structure of functions and procedures in vhdl, as well as their use, is as follows: USE WORK.chap2_defs.ALL FUNCTION compare(x,y: Radix4) RETURN MagnComp IS BEGIN IF (x > y) THEN RETURN(G) ELSIF (x = y) THEN RETURN(E) ELSE RETURN(S) END IF END compare PROCEDURE comp_two(w,x,y: IN Radix4 z1,z2: OUT MagnComp) IS BEGIN IF (w > x) THEN z1 <= G ELSIF (w = x) THEN z1 <= E ELSE z1 <= S END IF IF (w > y) THEN z2 <= G ELSIF (w = y) THEN z2 <= E ELSE z2 <= S END IF END comp_two A function is used as part of an expression, whereas a procedure is a statement by itself. For example, res := compare(a,b) comp_two(a,b,c,r1,r2) Processes The PROCESS statement is used to encapsulate the behavior of a module an architecture body containing the behavioral description of a module may have 2.6. Speci cation using vhdl 61 only one process which embodies its entire functionality, or may have multiple processes. In this chapter, we consider only the case of a single PROCESS in an architecture body. The format of the PROCESS statement is illustrated in the following example. Example 2.22 The following architecture body describes the PROCESS statement: ENTITY recode PORT(x_in z0_out z1_out END recode IS : IN : OUT : OUT INTEGER RANGE 0 TO 9 INTEGER RANGE -5 TO 5 BIT) ARCHITECTURE behavioral OF recode IS BEGIN PROCESS (x_in) -- process declarations VARIABLE d_0 : INTEGER VARIABLE d_1 : BIT BEGIN -- process body IF (x_in < 5) THEN d_0 := x_in d_1 := '0' ELSE -- x_in >= 5 d_0 := x_in - 10 d_1 := '1' END IF z0_out <= d_0 z1_out <= d_1 END PROCESS END behavioral The action of a process consists of the interpretation of its statements whenever any of the signals listed next to the PROCESS are assigned a value. The statements are then interpreted sequentially. The declarations section de nes types, variables and constants used by the PROCESS. In the example above, the process is interpreted each time the input signal x in is assigned a value when that occurs, the statements in the body of the process are interpreted, assigning values to output signals z0 out, z1 out. Packages and libraries vhdl-based descriptions are vhdl-compliant, so they can be used in a vhdl environment to simulate the behavior of the system. In addition to the lan- 62 Chapter 2. Speci cation of combinational systems guage constructs presented earlier, vhdl de nes some other facilities which are helpful for simulation. Such facilities are described now. A PACKAGE is a collection of elements, such as data types, subprograms, and constants. A package can be regarded as a collection of tools used to build modules. Packages allow sharing (globally) these tools among di erent modules. A package consists of two parts: Package declaration, which de nes the interface for the package (in a similar way to an entity de ning the interface for a module) and Package body, which speci es the details of the package (in a similar way to an architecture body de ning the behavior of a module). Subprograms declared in a package declaration must have a corresponding subprogram body in the package body. The package body may contain local declarations that are used only within the package body these declarations are not visible outside the package. A vhdl-based simulation environment uses a library called WORK to store representations of facilities that can be used by the modules. For example, the elements of a PACKAGE are placed in library WORK, so they become part of the library. The components of library WORK are visible to any module that uses the library through a USE clause. In a system with multiple modules, the USE clause must precede the entity declaration of each module in other words, the scope of the USE clause extends only to the end of the entity that follows the clause. Example 2.23 The following illustrates a package declaration and package body: PACKAGE sample_pkg IS CONSTANT max : INTEGER := 255 FUNCTION check_max(a: INTEGER) RETURN BIT END sample_pkg PACKAGE BODY sample_pkg IS FUNCTION check_max(a: INTEGER) RETURN BIT IS BEGIN IF (a > MAX) THEN RETURN('1') ELSE RETURN('0') END IF END check_max END sample_pkg 2.6. Speci cation using vhdl 63 This package declares a constant of type INTEGER and a function these elements are available to be used in a module after accessing the package, as follows: USE WORK.sample_pkg.ALL ENTITY use_sample_pkg IS PORT(x : IN INTEGER z : OUT BIT) END use_sample_pkg ARCHITECTURE behavioral OF use_sample_pkg IS BEGIN PROCESS (x) BEGIN z <= check_max(x) END PROCESS END behavioral -- uses all elements of package sample_pkg -- which are stored in library WORK The clause USE WORK.sample pkg.ALL speci es that this module uses all the declarations in the package sample pkg which is stored in library WORK. As a consequence, the elements of the package can be used in the module, without further declaration. Appendix B includes a package with the elements required to execute the vhdl descriptions given throughout the book. The behavior of a combinational module, namely its output changing as a consequence of a change in any of the inputs, is described directly using the elements of vhdl already presented in this chapter. In fact, the examples given in this section correspond to speci cations of this type. As stated earlier, the description of systems may use variables as an aid to simplify complex functions such functions can be decomposed into partial terms or steps, using variables to save the intermediate results. In the case of combinational systems, the value of those variables is generated and used in the same interpretation of the PROCESS describing the behavior of the system. As also stated earlier, one of the advantages of using a hardware-description language is the ability to simulate the speci cation of a system and verify that its behavior is as expected. This level of \testing" can be carried directly with an speci cation as the ones described in this chapter, by providing values to the Functional vhdl-based speci cation of combinational systems Simulating the speci cation 64 Chapter 2. Speci cation of combinational systems input signals and observing the values of the output signals. The details of the mechanisms for this objective are dependent on the speci c compiler/simulator environment used. Typically, these mechanisms consist of simulation statements such as force x 1 assign value 1 to input signal x list y observe the output signal y run simulate for the given input 2.7 Further readings A more detailed discussion of switching theory and some aspects of the speci cation methods for combinational systems is given in books on switching theory, such as Switching and Automata Theory, by Z. Kohavi, New York: McGrawHill, 1978, Logic Design Principles by E. McCluskey, Englewood Cli s, NJ: Prentice-Hall, 1986, and Introduction to Digital Logic Design by J.P. Hayes, Reading, Mass: Addison-Wesley, 1993. They concentrate on the binary specication methods, without giving much attention to the high-level techniques. The more mathematical aspects are treated in textbooks on discrete mathematics such as Discrete Mathematical Structures by H.S. Stone, Chicago: Science Research Associates, 1973, and Introduction to Discrete Structures by F.P. Preparata and R.T. Yeh, Reading, Mass: Addison-Wesley, 1973. For an historical perspective on the development of data representation see Coded Character Sets, History and Development by C.E. Mackenzie, Reading, Mass: Addison-Wesley, 1980. vhdl and its use in digital design are discussed in The Designer's Guide to VHDL by P. Ashenden, San Franciso: Morgan Kaufmann Publishers, Inc., 1996 VHDL by D.L. Perry, New York: McGraw-Hill, 1991 VHDL Analysis and Modeling of Digital Systems by Z. Navabi, New York: McGraw-Hill, 1993 and Structured Logic Design with VHDL by J.P. Armstrong and F.G. Gray, Englewood Cli s, NJ: Prentice-Hall, 1993, to mention few of many available books. 2.8. Exercises 65 2.8 Exercises digit. The output z is the square of x if x is greater than 4 otherwise, the output z is two times x. a) Give a high-level description of the system using expressions. b) Show a table of the function. Ex. 2.2 A combinational system has two inputs, x = (x15 : : : x0) and y = (y1 y0 ), with xi and yi having values 0, 1, or 2. There is one output z = (z13 : : : z0 ) obtained by deleting the leftmost instance of the pattern y from the input x. If x does not contain the pattern speci ed by y, the output z has all elements zi = 0. For example, if x = (0 1 2 1 2 0 1 2 0 0 0 1 2 2) and y = (1 2) then z = (0 1 2 0 1 2 0 0 0 1 2 2) Give a high-level speci cation of this system. How many rows would a tabular description have? Ex. 2.3 Give a high-level speci cation of a combinational system that computes the distance between two 1's in the input bit-vector x = (xn;1 : : : x0). Assume that x has exactly two 1's. For instance, if x = (1 0 1 0 0) then the distance is 2. Ex. 2.4 A pattern detector has as input a 4x4 matrix whose elements take values a, b, c, or d. The output is 1 if the matrix contains one b surrounded by eight a's and 0 otherwise. Give a high-level description of the system in terms of conditional logic expressions. How many rows would a tabular description have? Ex. 2.5 A combinational incrementer/decrementer has as inputs an integer in the range 0 to 216 ; 1 and a binary control signal. If the control signal has value 1, the system increments modulo-216 (that is, it computes z = (x +1) mod 216), otherwise it decrements modulo-216. Give a high-level description of the system in terms of a conditional arithmetic expression. Can you give a tabular representation of the function? Ex. 2.6 The table shown below de nes two three-valued functions. Determine the table for the function f (a b) = f2(b f1 (a b)). f1 a f2 a b012 b012 0202 0200 1011 1020 2210 2002 High-level description Ex. 2.1 A combinational system has one input x, which represents a decimal 66 Chapter 2. Speci cation of combinational systems Codes for data representation Ex. 2.7 What is the minimum number of binary variables required to represent Ex. 2.8 a variable which can take integer values from 10 to 25? Give a table describing a possible coding function. a) Give a binary code to represent the month of a year. b) How many bits is the minimum needed to represent the date (month, day, year)? Use a vector of three components and represent each component in the binary number system. Consider dates up to the year 2500. c) What is the minimum needed for the date of b) if the representation of the day and of year are done in decimal (two digits for the day and four digits for the year)? d) What is the minimum number of bits required for the date of b) if just one component is used. What is the disadvantage of this representation ? Ex. 2.9 Is there a unique code for representing the decimal digits using the weight vector 2-4-2-1? If not, give two such codes and determine how many di erent codes there are. Ex. 2.10 Consider a weighted code for decimal digits using four bits. Determine conditions that the weights have to satisfy, for weights that are positive integers. Ex. 2.11 a) For the integer with decimal representation 34567, give the corresponding bit-vectors for the BCD code and for the Excess-3 code. b) Perform the subtraction of z10 = (9999910 ; 3456710) for the integers represented in BCD and in the 2-4-2-1 codes. Use the fact that in the 24-2-1 code the complement with respect to 9 is obtained by complementing each bit. Ex. 2.12 Consider a ve-bit vector x that represents a decimal digit in a 2out-of-5 code: a) Give a table of the 32 possible values of x and indicate which values are valid representations of decimal digits. b) Give a high-level description of a combinational system that has an output of 1 when the vector x represents a valid digit in a 2-out-of-5 code. 2.8. Exercises 67 Ex. 2.13 a) Determine the radix-16 representation of the integer whose radix-2 representation is 1001010100011110. Hint: partition the radix-2 vector into groups of four bits and determine the radix-16 digit values which are coded by each group (using the binary code). b) Determine the radix-2 representation of the integer whose radix-8 representation is 3456. Hint: code each radix-8 digit using the binary code and concatenate the resulting groups of three bits. c) Using the hints above, give a procedure to convert from radix-2 to radix-2k and vice-versa. three of its arguments are 1. By comparison of the tabular descriptions, show that M a b M (c d e)] = M M (a b c) d M (a b e)] Since the tables of the 5-variable functions are quite large, a simpler approach might be to consider separately the cases a = b = 0, a = b = 1, and a 6= b. Ex. 2.15 Prove or disprove the following equalities, by constructing the corresponding tables. a) fxor (fand (x1 x0) fand (x1 x0)) = fequivalence (x1 x0) b) fnand (fnand (x1 x0) fnand (x1 x0)) = fand (x1 x0) Ex. 2.16 Determine the number of di erent switching functions of n variables. Ex. 2.17 A symmetric switching function is a function whose value does not change when its arguments are permuted. a) Give a table of a symmetric switching function of three variables. b) Determine how many symmetric switching functions of three variables exist. c) Show that a symmetric switching function must have the same value for all arguments that have the same number of 1's. Using this fact, show that a symmetric switching function of n variables can be described by a subset A of the set of integers f0 1 ::: ng such that integer i is in A if the function has value 1 whenever i variables are 1. Binary description - switching functions Ex. 2.14 The majority switching function M (x y z ) is equal to 1 when two or 68 Chapter 2. Speci cation of combinational systems d) Give the table of the symmetric switching function of four variables whose set A is f0,2,3g. e) Using the result of part (c), determine how many symmetric functions of n variables exist. f) Is the composition of symmetric switching functions a symmetric function? Consider, for instance, the function f (x y z ) = and(or(x y) z ). g) Determine the table of the function f = f1 (f2 (a b c) f1(b c a) c) wherein f1 and f2 are the symmetric switching functions with sets A1 = f0 1g and A2 = f0 3g, respectively. h) Given the set A of a symmetric function f , determine the set Ac of the complement of f . Illustrate for the 4-variable symmetric function with A = f0 1g. whenever wi xi > T and 0 otherwise the values wi's are integers called the weights, xi is a binary variable interpreted as the integers 0 and 1, and T is an integer called the threshold. a) Give the table that represents the threshold function of three variables with w1 = 1 w2 = 2 w3 = ;1, and T = 2. Give also the one-set or the zero-set. b) Determine a set of weights and a threshold for the switching function of three variables described by one-set(3,5,7). Hint: Write the inequalities (in terms of the weights and the threshold) for each value of (x2 x1 x0) and nd a solution to the system of inequalities. c) Show that the xor function of two variables is not a threshold function that is, show that no weights and threshold can be found to describe this function. Hint: Show that the system of inequalities does not have a solution. d) Determine the weights and threshold for the majority function of four variables, that is, the function that has the value 1 whenever three or four variables have the value 1. the input bit-vector x = (x3 x2 x1 x0), which has exactly two 1's. For example, for x = (0 1 0 1) the distance is 2. That is, if the two ones are at positions i and j , distance is jj ; ij. a) Give a description in terms of switching functions. Ex. 2.18 P threshold switching-function is a function which has value 1 A Ex. 2.19 A combinational system computes the distance between two 1's in 2.8. Exercises 69 b) Give the one-set, the zero-set, and the d.c.-set. Ex. 2.20 In Exercise 2.1, obtain the description in terms of incompletely speci ed switching functions for the BCD code presented in Table 2.3. Use the simpli ed notation of Example 2.4, two-dimensional tables of Example 2.5, and give the one-set and d.c.-set description. Ex. 2.21 In Exercise 2.1, obtain the description in terms of incompletely speci ed switching functions for the Excess-3 code presented in Table 2.3. Use the simpli ed notation of Example 2.4, two-dimensional tables of Example 2.5, and give the one-set and d.c.-set description. Ex. 2.22 In Exercise 2.1, obtain the description in terms of incompletely speci ed switching functions for the 2-out-of-5 code presented in Table 2.3. Use the simpli ed notation of Example 2.4, two-dimensional tables of Example 2.5, and give the one-set and d.c.-set description. Ex. 2.23 Determine the number of incompletely speci ed switching functions of n variables. Appendix A, prove each of the following: a) a0b0 ab a0b = a0 b b) a0 a(a0b b0 c)0 = a0 b c0 c) (a0 b0 c)(a b)(b0 ac)0 = a0 bc d) ab0 b0 c0 a0c0 = ab0 a0c0 e) wxy w0 x(yz yz 0 ) x0(zw zy0 ) z (x0 w0 y0 x) = xy z f) abc0 bc0 d a0 bd = abc0 a0 bd Ex. 2.25 Given xy0 x0 y = z , show that xz 0 x0 z = y. Hint: replace z by xy0 x0 y and simplify. Ex. 2.26 Simplify algebraically the following expression: a a0 b a0 b0c a0 b0c0 d a0 b0 c0d0e Ex. 2.27 An operation is de ned for two-valued variables a and b as follows: a b = ab a0b0 Let c = a b. Determine which of the following identities are valid: Boolean algebra Ex. 2.24 Using the postulates of Boolean algebra and the theorems given in 70 Chapter 2. Speci cation of combinational systems a) a = b c b) a bc = 1 Ex. 2.28 Show that ab = ac does not imply b = c. Ex. 2.29 Consider the system consisting of three elements 0,1, and 2 and the operators # and & de ned by the tables below. Determine whether this system is a Boolean algebra (see Appendix A). If not, indicate which postulates are not satis ed. #012 &012 0000 0012 1011 1112 2012 2222 Ex. 2.30 Show the operation tables for a Boolean Algebra of four elements. Hint: call the elements a b c d, choose among them the two identity elements, and construct tables so all the postulates are satis ed. Ex. 2.31 Show that the nand and nor operators are not associative. Ex. 2.32 The xor operator is denoted by the symbol and de ned by the identity x1 x0 = x01x0 x1x00 (that is, x1 x0 represents the XOR function). a) Show that xor operator is (i) commutative, (ii) associative, and, (iii) distributive with respect to and. b) Prove or disprove the following: if x y = 0 then x = y x0 y = ( x y ) 0 x y = x0 y0 if x y = z y then x = z . x x : : : x is 0 for an even number of x's and x for an odd number of x's. a) (a b0 c)(d0 e0 ) f 0 g k0 i0 b) (a b c)(d0 e) c) a 10 (a0 ba0 b c(b0 a)b0 Ex. 2.34 Evaluate the following switching expressions for the assignments (0,1,1,0) and (1,1,1,0): Description by switching expressions Ex. 2.33 Determine whether the following are switching expressions 2.8. Exercises 71 a) E (w x y z ) = w x0 (x y)(w z )0 b) E (x3 x2 x1 x0) = x2 x1 x3 Ex. 2.35 Prove the following identity for switching expressions, by evaluating them for all possible assignments. xyz yw x0z 0 xy0 = y0 z 0 yw xz x0yz 0 Ex. 2.36 Determine the switching function represented by the following switching expressions (show a truth table): a) E (x y) = xy xy0 b) E (x y z ) = xyz x0y xyz 0 Ex. 2.37 Using tables, determine all pairs of equivalent switching expressions from the set of expressions given below: x0y0 xz x0z 0 y0 z x0z 0 xyz xy x0 y0 yz 0 x0y0 x0z 0 xyz xyz x0y0 z x0z 0 xyz 0 Ex. 2.38 Reduce the following switching expressions to the number of literals speci ed 4 literals a) abc0d ab0c bc0 d ab0c0 acd a0 bcd b) acb ac0d bc0d0 a0b0 c0 ab0c0 d0 bc0d 3 literals Ex. 2.39 Find the canonical expressions for the following switching function: abcf 0000 0011 0101 0111 1000 1011 1100 1110 Ex. 2.40 Obtain the equivalent sum of minterms and product of maxterms for the following expressions. Use m- and M -notation. 72 a) b) c) Chapter 2. Speci cation of combinational systems a0b ac bc (ab c)(d0e f ) a0b(ab c)(b c0 d) Ex. 2.41 Determine the sum of minterms and product of maxterms that are equivalent to E (x y z ) = x0 x(x0y y0 z )0 Ex. 2.42 Convert the following SEs into sums of minterms: a) ((a b a0c0 )c d)0 ab]0 b) (w0 (xy xyz 0 (x z )0 )0 (z 0 w0 )]0 Ex. 2.43 Convert the following SEs into product of maxterms without obtaining the sum of minterms rst: a) xyz yw x0 z 0 xy0 b) (abc ab0)0 (a0 b c0) Ex. 2.44 Convert the following canonical expressions of (w x y z) into the other canonical forms. P a) m(0 1 3 4 11 12 14 15) Q b) M (0 1 3 5 6 9 10 13) Ex. 2.45 Express the complement of f (x y z ) = Q M (0 1 4 6 7) as a sum of minterms and a product of maxterms. 0 to 3. The adder should have a carry-in and a carry-out to connect several of these modules to construct a multi-digit (radix 4) adder. Give the following descriptions: a) High-level using arithmetic expressions. b) A table of the arithmetic function. c) A tabular description of the switching functions, with inputs and outputs coded in the binary code. Give also the corresponding one-set. Ex. 2.47 Describe an incrementer/decrementer system whose input is an integer in the range 0 to 15. A control input determines whether the system increments or decrements. Give the following descriptions: Examples of systems Ex. 2.46 Describe an adder whose inputs A and B are integers in the range 2.8. Exercises 73 a) High-level using arithmetic expressions. b) A table of the arithmetic function. c) A tabular representation of the switching functions, with the inputs and outputs in a binary code. Give also the zero-set. Ex. 2.48 Describe a system that counts the number of 1's in a four-bit vector x. Give the following descriptions, if practical: a) High-level using arithmetic expressions. b) Table of the arithmetic function. c) A tabular representation of the switching functions, with the inputs and outputs in a binary code. Give also the one-set. Ex. 2.49 Describe a 2x2-bits multiplier, that is each operand represents an integer in the range 0 to 3. Give the following descriptions: a) High-level using arithmetic expressions. b) Table of the arithmetic function. c) A tabular representation of the switching functions, with the inputs and outputs in a binary code. Give also the one-set. Ex. 2.50 An open stairwell has four oors and one switch per oor to control the light. If all switches are o , the light is o any single change in the position of any switch changes the \state" of the light. Describe the combinational system required to control the light. Give a) High-level description. b) Table of switching functions. c) Switching expressions. Hint: the \state" of the light is also an input. Ex. 2.51 A combinational system has as input a decimal digit and as output the 9's complement of the input. Describe the system giving a) A high-level description. b) Tabular and (one-set, dc-set) description of the functions for one of the following codes: Excess-6 (de ned in a similar manner as the Excess-3 code, that is, 0 is represented by 0110, etc.) 74 Chapter 2. Speci cation of combinational systems 2-out of-5 weighted with weights 4,3,2,1 and with weights 8,-4,2,-1. These codes are de ned using the expression of Section 2.3.2. c) Switching expressions for the functions in (b). Ex. 2.52 Describe a binary-to-decimal converter that has a 4-bit input vector and the output in the BCD representation (two digits) a) Give a high-level description. b) Give switching expressions. Ex. 2.53 Describe a combinational system that has two hexadecimal digits as inputs and the same digits ordered by magnitude as outputs. a) Give a high-level description b) Give switching expressions when the digits are represented in the binary code. Use the intermediate variables g, e, and s obtained from the comparison of the hexadecimal digits. Ex. 2.54 A priority encoder has eight binary inputs and an integer output. The inputs are numbered 0 to 7, whereas the value of the output is the integer that corresponds to the largest index of the input having value 1. For example, for input x = (0 1 0 1 1 1 0 0) the output is z = 6. Describe the system giving: a) A high-level speci cation. b) Switching expressions for a binary representation of the output. c) Switching expressions for a Gray-code representation of the output. To simplify the description, decompose the system into two cascaded subsystems, as shown in Figure 2.16. The rst system is a priority-resolution system that gives a 1 output corresponding to the highest-priority input that has value 1 (all other outputs are 0) the second system is an encoder, that is, its output is an integer representing the index of the input with value 1. Ex. 2.55 Describe a combinational comparator, similar to Example 2.19, for hexadecimal input digits. Hint: generalize the following description of the 2-bit comparator: 0 0 z2 = x1 y1 e1 x0y0 z1 = e1 e0 z0 = x01 y1 e1 x00y0 where ei = xiyi x0i yi0 . 2.8. Exercises 75 x7 x6 x5 x4 x3 x2 x1 x0 Priority resolution w7 w6 w5 w4 w3 w2 w1 w0 Encoder z??? 2 z1 z0 Figure 2.16: Cascaded subsystems for priority encoder Speci cation using vhdl Any of the exercises under the heading \Examples of Systems" can be done using vhdl. ...
View Full Document

This note was uploaded on 03/26/2010 for the course CS 187154200 taught by Professor Ercegovac,m.d. during the Winter '09 term at UCLA.

Ask a homework question - tutors are online