> > End-of-chapter exercises, p 272: > 1 convert binary to decimal > 2 convert decimal to binary > 5 binary numbers that are all 1's: eg 1111, 11111111111 > 6 Adding a 0 to a binary number: 1101 -> 11010, etc > 10 PIPPIN tasks: (a) swap, (b) compare > 11 PIPPIN: X = X/2 > 14revised: Python terminates def, while, for, if lines with ":". > What would happen if we eliminated these colons from python? > 15 Draw parse trees > 16 describe code generation > > > End-of-chapter exercises, p 308: > 6 find logic table. that is, for inputs > (a,b) = (0,0), (0,1), (1,0), (1,1), find respective output x > 8 three-input AND, three-input OR > 9 majority circuit: 3 inputs: output is 1 <===> at least 2 inputs are 1 > 15 pipelining > > ======================================================================= > > 1. What is the value of s after execution of the following python code: > > n=1 > s=1 > while n<7: > s = s + n*n > n = n+2 We go through the loop for n=1,3,5; s = 1 + 1*1 + 3*3 + 5*5 = 36 > 2. What is the value of L after execution of the following python code: > Note L is a list. > > n = 0 > L = [] > while n < 5: > L = L + [2*n] > n = n + 1 We go through with n = 0,1,2,3,4, each time appending 2n to the end: L = [0,2,4,6,8] > 3. What is printed by the following: > > for i in range(1,5): > print range(0,i) Recall that range(0,i) is simply the list [0,1,2,...,i-1]. The four lists are printed one per line: [0] [0,1] [0,1,2] [0,1,2,3] > 4. What is string t after the following? > t = "" > s = "foobar" > for i in range(len(s)): > t = t + s[i] t contains the reverse of s: "raboof" > Pippin review deleted > 5. Give a parse tree for the following expression, and write PIPPIN instructions > to leave the value of the expression in the accumulator; > > (X+Y)/2 LOD X ADD Y DIV #2 > 6 Give a parse tree for the following expression, and write PIPPIN instructions > to leave the value of the following expression in the accumulator. > Hint: Store (X+Y) in the temporary location T1. > Unlike the previous example, this one cannot be done without temporary storage. > > 12/(X+Y) LOD X ADD Y STO T1 # store in temp loc LOD #12 # Load Acc with 12 DIV T1 # now divide 12 by what we worked out before > 7. Give parse trees for each of the following expressions. > (X+Y)*(X+2) > X*Y + 3*Z*(W+1) > > 8. Assume that the location P is initially 1, and N is initially 5. > Give the value in P at the end. > > LOD N > START: JMZ END # jump to END if Acc == 0 > MUL P # multiply Acc by P > STO P > LOD N # load the original N again > SUB #1 > STO N > JMP START > END: HLT Each time through the loop, N is decremented by one. Before that, we multiply P by N. So, the final value in N is 0, and the final value in P is 5*4*3*2*1 = 120 > 9. Give the output of the following for all inputs. > > x----+------+ > | NAND |--+ w > y----+------+ | > +----+------+ > | NAND |--output > z-------------------+------+ > > > x y z | output > 0 0 0 | > 0 0 1 | > 0 1 0 | > 0 1 1 | > 1 0 0 | > 1 0 1 | > 1 1 0 | > 1 1 1 | > > The table for one NAND gate is as follows: > > x y output > 0 0 1 > 0 1 1 > 1 0 1 > 1 1 0 I add a column "w" representing the output of the first NAND gate. Then we can use the NAND table to fill in the w column. To get the final output, use the NAND table and input values w and z. NAND(w,z)=1 whenever EITHER w=0 or z=0. x y w z | output 0 0 1 0 | 1 0 0 1 1 | 0 0 1 1 0 | 1 0 1 1 1 | 0 1 0 1 0 | 1 1 0 1 1 | 0 1 1 0 0 | 1 1 1 0 1 | 1