1 /10 2 /15 3 /16 4 /18 5 /14 6 /13 7 /14 - 6.004

21
M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE 6.004 Computation Structures Spring 2022 Quiz #1 Name Athena login name Score Recitation section o WF 10, 34-302 (Francis) o WF 2, 34-302 (Robert) o WF 12, 35-310 (Kendall) o WF 11, 34-302 (Francis) o WF 3, 34-302 (Robert) o WF 1, 35-310 (Kendall) o WF 12, 34-302 (Grace) o WF 10, 35-310 (Sara) o opt-out o WF 1, 34-302 (Grace) o WF 11, 35-310 (Sara) Please enter your name, Athena login name, and recitation section above. Enter your answers in the spaces provided below. Show your work for potential partial credit. You can use the extra white space and the backs of the pages for scratch work. Problem 1. Binary Arithmetic (10 points) (A) (4 points) Perform the following addition exercises in fixed width 2’s complement arithmetic. Show your work. Provide your result in binary, and decimal. For each computation also specify whether or not overflow occurred. (i) 10110 + 00110 Sum in binary: 0b_______11100__________ Sum in decimal: _______-4_____________ Did overflow occur? (Yes/No): ________No____________ (ii) 101100 + 110110 Sum in binary: 0b______100010__________ Sum in decimal: ______-30_____________ Did overflow occur? (Yes/No): ______No_____________ 1 /10 2 /15 3 /16 4 /18 5 /14 6 /13 7 /14

Transcript of 1 /10 2 /15 3 /16 4 /18 5 /14 6 /13 7 /14 - 6.004

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y

DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

6.004 Computation Structures Spring 2022

Quiz #1

Name

Athena login name

Score

Recitation section o WF 10, 34-302 (Francis) o WF 2, 34-302 (Robert) o WF 12, 35-310 (Kendall) o WF 11, 34-302 (Francis) o WF 3, 34-302 (Robert) o WF 1, 35-310 (Kendall) o WF 12, 34-302 (Grace) o WF 10, 35-310 (Sara) o opt-out o WF 1, 34-302 (Grace) o WF 11, 35-310 (Sara)

Please enter your name, Athena login name, and recitation section above. Enter your answers in the spaces provided below. Show your work for potential partial credit. You can use the extra white space and the backs of the pages for scratch work. Problem 1. Binary Arithmetic (10 points)

(A) (4 points) Perform the following addition exercises in fixed width 2’s complement arithmetic. Show your

work. Provide your result in binary, and decimal. For each computation also specify whether or not overflow occurred.

(i) 10110

+ 00110

Sum in binary: 0b_______11100__________

Sum in decimal: _______-4_____________

Did overflow occur? (Yes/No): ________No____________

(ii) 101100 + 110110

Sum in binary: 0b______100010__________

Sum in decimal: ______-30_____________

Did overflow occur? (Yes/No): ______No_____________

1 /10 2 /15 3 /16 4 /18 5 /14 6 /13 7 /14

(B) (1 point) What is the largest positive number that can be represented using 9-bits 2’s complement representation? Provide your answer in decimal, or as a mathematical expression.

Largest 9-bit 2’s complement value: ____28-1 = 255__________

(C) (1 points) A left shift by 4 is mathematically equivalent to which operation assuming no loss of significant

bits?

Mathematically equivalent operation: ____*16_______________

(D) (2 points) Compute the result of (0xA6 >>arith 3) ^ 0x77. >>arith is an arithmetic right shift. Show your

work. Provide your result in hexadecimal. 10100110 >>arith 3 = 11110100 11110100 ^ 01110111 = 10000011 = 0x83

(0xA6 >>arith 3) ^ 0x77 in hexadecimal: 0x____83________________

(E) (2 points) Given an unknown binary number with digits vwxyz, where each of v, w, x, y, and z could be a 0

or a 1, determine the two intermediate bitwise operations that should be performed on this number in order to end up with the result v1x0z. For each intermediate operation, specify both the operator and the value of the second operand (e.g., xor 11111) vwxyz | 01000 = v1xyz v1xyz & 11101 = v1x0z OR vwxyz & 11101 = vwx0z vwx0z | 01000 = v1x0z

First bitwise operation to perform on vwxyz:____ | 01000 ________

Second bitwise operation (performed on result of first operation):____ & 11101 _______

Flipping first and second operations is also correct.

Problem 2. RISC-V Assembly (15 points)

(a) (3 points) Determine the values stored in the following registers when the following program reaches the unimp instruction. If you can’t tell the value from the program, write CAN’T TELL.

Program start: li a0, 0 a0=0 li a1, 0xA0A0A0A0 a1=0xA0A0A0A0 addi a2, a0, -1 a2=0xFFFFFFFF calc: srai a1, a1, 16 a1=0xFFFFA0A0 xor a3, a2, a1 a3=0x00005F5F end: unimp

Register values when the program reaches the unimp instruction (in hexadecimal). a0: 0x_0______________

a1: 0x_FFFFA0A0______

a2: 0x_FFFFFFFF______

a3: 0x_00005F5F_______

(b) (6 points) Determine the values stored in the following registers when the following program reaches the

unimp instruction (i.e., reaches the end label). If you can’t tell the value from the program, write CAN’T TELL.

Program .=0x10 f1: li x6, 6 x6=6 li x7, 0 x7=0 lui x8, 2 x8=0x2000 f2: addi x6, x6, -1 x6=5:4:3:2:1:0 addi x7, x7, 1 x7=1:2:3:4:5:6 bne x6, x0, f2 f3: beqz x6, end x6=0 goto end srai x7, x8, 12 end: unimp

Register values when the program reaches the unimp instruction (in hexadecimal). x0: 0x_0_____________

x6: 0x_0_____________

x7: 0x_6_____________

x8: 0x_2000__________

pc: 0x_30____________

sp: 0x_CAN’T TELL___

ra: 0x_CAN’T TELL___

(c) (6 points) Determine the values stored in registers and in memory when the following program reaches the unimp instruction. If you can’t tell the value from the program, write CAN’T TELL.

Program rv: li a1, 0x2000 a1=0x2000 lw a0, 0(a1) a0=0x0D09F00D srli a2, a0, 12 a2=0x0000D09F andi a2, a2, 0x1 a2=0x1 slli a3, a2, 12 a3=0x1000 sw a3, 4(a1) end: unimp .=0x2000 .word 0x0D09F00D .word 0x89998212 .word 0xAB19000F

Register values when the program reaches the unimp instruction (in hexadecimal). a0: 0x_0D09F00D_____

a1: 0x_2000__________

a2: 0x_1_____________

a3: 0x_1000__________

Memory contents (in hexadecimal) when the program reaches the unimp instruction. Value stored at address 0x2000: 0x_0D09F00D_______ Value stored at address 0x2004: 0x_1000____________ Value stored at address 0x2008: 0x_AB19000F_______

Problem 3. Securing Fort Xonk using the RISC-V Calling Convention (16 points) Fort Xonk contains the world’s finest valuables. Its vaults are highly reputed and require maximum security. Unfortunately, a series of high-profile heists suggest that security at Fort Xonk is lacking. The management at Fort Xonk does not trust C compilers, so its security system is written entirely in RISC-V assembly. However, Fort Xonk’s programmers are not familiar with RISC-V’s calling convention, so their implementation is buggy. You’ve been hired to fix their implementation. Each of the following questions shows a different function of the security system. Fix the assembly code so that it obeys all calling conventions. The only changes you may make are: (1) changing which registers are used for any of the instructions, and (2) pushing and popping registers to and from the stack as needed. For full credit, you should minimize the number of instructions executed by your corrected code. You do not need to rewrite each function; you can cross out and replace individual instructions, or insert new instructions between existing ones. Write your changes in the space given on the right, as shown below.

Code Under Audit … addi t2, a0, 1 andi a1, a2, 0xF xori a0, t1, 0x0FF ret

Write changes here: addi s0, a0, 1 lw s0, 0(sp) addi sp, sp, 4

Note: Some of the code below uses MMIOs to interact with the outside world, as the comments describe. MMIOs are performed through loads and stores to addresses 0x40000000 or higher. You do not need to understand the MMIOs available or their behavior—the bugs in the code are with the calling convention. (A) (5 points)

Code under audit // This function takes a single // argument, an integer that // encodes a password, and // returns a hash of the password hash_password: li s1, 0x2000 slli x2, a0, 2 andi x2, x2, 0x3FF add x2, x2, s1 lw s2, 0(x2) xor s2, s2, a0 srli s2, s2, 8 xor t0, s2, a0 ret

Write changes here:

hash_password: li t1, 0x2000 slli t3, a0, 2 andi t3, t3, 0x3FF add t3, t3, t1 lw t2, 0(t3) xor t2, t2, a0 srli t2, t2, 8 xor a0, t2, a0 ret

(B) (5 points)

Code under audit // This function repeatedly reads // a keypad, and returns only // when the correct password // is entered // This function takes no // arguments and does not return // a value wait_for_correct_password: loop: // Read keypad li t0, 0x40008000 lw a0, 0(t0)

// Hash entered password call hash_password

// Read stored secret lw a1, 4(t0)

// If they differ, try again bne a2, a1, loop

ret

Write changes here: wait_for_correct_password: addi sp, sp, -8 sw ra, 0(sp) sw s0, 4(sp) loop: // Read keypad li s0, 0x40008000 lw a0, 0(s0)

// Hash entered password call hash_password

// Read stored secret lw a1, 4(s0)

// If they differ, try again bne a0, a1, loop lw s0, 4(sp) lw ra, 0(sp) addi sp, sp, 8 ret

6.004 Spring 2022 - 7 of 21 - Quiz #1

(C) (6 points)

Code under audit // This function locks a vault’s // door, and opens it when the // correct password is entered // This function takes no // arguments and does not return // a value control_vault_door: // Engage the doorbolt li s0, 1 li t1, 0x40004000 sw s0, 0(t1) call wait_for_correct_password // Disengage the doorbolt li t0, 0x40004000 sw zero, 0(t0) // Wait for the door to close wait: li a6, 0x40004004 lw a0, 0(a6) beqz a0, wait ret

Write changes here: control_vault_door: addi sp, sp, -4 sw ra, 0(sp) // Engage the doorbolt li t0, 1 li t1, 0x40004000 sw t0, 0(t1) call wait_for_correct_password // Disengage the doorbolt li t0, 0x40004000 sw zero, 0(t0) // Wait for the door to close wait: li a6, 0x40004004 lw a0, 0(a6) beqz a0, wait lw ra, 0(sp) addi sp, sp, 4 ret

6.004 Spring 2022 - 8 of 21 - Quiz #1

Problem 4. Stack Detective (18 points) Below is the Python code implementing two recursive functions foo and bar that both take a single argument x. To the right is an implementation of these functions using RISC-V assembly. Pay attention to the differences. To help you, the differences between the functions have been italicized. def foo(x): def bar(x): if x == 0: if x == 0: return 0 return 0 else: else: if x & 1 == 1: if x & 1 == 1: return bar(x >> 1) return 1 else: else: return foo(x >> 1) return bar(x >> 1) (A) (2 points) What should be in the blanks on the lines labeled L1 and L2

to make the assembly implementation match the Python code?

L1: srli _s0, a0, 1_____

L2: srli _s0, a0, 1_____ We know we want to perform a right shift on x by 1. x is the first argument to both foo and bar so it resides in a0. Both foo and bar copy the value in s0 into a0 before executing any function calls. As a result, the destination of the shift for both is s0. (B) (2 points) How many words will be written to the stack by the functions

foo and bar?

Number of words pushed onto the stack by each call to function foo: __2__

Number of words pushed onto the stack by each call to function bar:

__2__ Both foo and bar subtract 8 from the stack pointer to make room for 8 bytes or 8/2=2 words.

foo: addi sp, sp, -8 sw s0, 0(sp) sw ra, 4(sp) beqz a0, foo_end andi a1, a0, 1 L1: srli ____________ beqz a1, foo_else mv a0, s0 call bar j foo_end foo_else: mv a0, s0 call foo foo_end: lw s0, 0(sp) lw ra, 4(sp) addi sp, sp, 8 ret bar: addi sp, sp, -8 sw s0, 0(sp) sw ra, 4(sp) beqz a0, bar_end andi a1, a0, 1 L2: srli ____________ beqz a1, bar_else li a0, 1 j bar_end bar_else: mv a0, s0 call bar bar_end: lw s0, 0(sp) lw ra, 4(sp) addi sp, sp, 8 ret

0xC04

0xC10

0xC4C

6.004 Spring 2022 - 9 of 21 - Quiz #1

The program’s initial call to the function foo occurs outside of the function definition via the instruction call foo. The program is interrupted during a recursive call to bar, just prior to the execution of the srli instruction at label L2. The diagram on the right shows the contents of a region of memory. All addresses and data values are shown in hex. The current value in the sp register is 0xEB0 and points to the location shown in the diagram.

(C) (2 points) Fill out the two missing spaces in the stack. Write CAN’T TELL if you cannot tell from the stack provided.

Value in memory at address: 0xEA8 = 0x_CAN’T TELL______

0xEAC = 0x_CAN’T TELL______

We have paused the program before any of the calls to foo or bar have returned. As a result, the stack is still growing and all values above the top of the stack are uninitialized.

(D) (5 points) What are the values in the following registers right when the execution of bar is interrupted? Write CAN’T TELL if you cannot tell from the stack provided.

Address Data

0xEA4 0xC4C

0xEA8 ???

0xEAC ???

sp→ 0xEB0 0x1

0xEB4 0xC4C

0xEB8 0x2

0xEBC 0xC4C

0xEC0 0x4

0xEC4 0xC04

0xEC8 0x9

0xECC 0xC10

0xED0 0x13

0xED4 0xB08

Current value of: ra = 0x__C4C___________

s0 = 0x__1_____________

a0 = 0x__1_____________

a1 = 0x__1_____________

pc = 0x__C34___________

Working backwards from the current stopping point, we can determine the current values of ra and s0 by reading from the stack: ... call bar ... sw s0, 0(sp) // 0x1 sw ra, 4(sp) // 0xC4C ... <STOPPED AT L2> Using the current value of s0, we can determine a0 and a1 by the surrounding instructions and going back to the previous call to bar (see Part D for justification): ... call bar

6.004 Spring 2022 - 10 of 21 - Quiz #1

... mv a0, s0 call bar ... sw s0, 0(sp) // 0x1 sw ra, 4(sp) // 0xC4C ... andi a1, a0, 1 ... <STOPPED AT L2> For pc calculation, see Part D for justification. (E) (3 points) What are the hex addresses of the call foo and call bar instructions within the

functions foo and bar? Write CAN’T TELL if you cannot tell from the stack provided.

Address of foo’s call bar instruction: 0x__C00___________

Address of foo’s call foo instruction: 0x__C0C___________

Address of bar’s call bar instruction: 0x__C48___________

(F) (2 points) What is the hex address of the call foo instruction that made the initial call to foo? Write CAN’T TELL if you cannot tell from the stack provided.

Address of instruction that made the initial call to foo: 0x__B04___________

(G) (2 points) What were the values of the argument x at the beginning of the initial call to foo?

Write CAN’T TELL if you cannot tell from the stack provided.

Argument at beginning of initial call: x = 0x__12______________ To answer this part, we need to gather more information from the stack. Using the information provided in the problem preamble, we know we are stopped in a recursive call to bar and that the program started with an initial call to foo. But we don’t yet know how many recursive calls were made to foo or bar. Visually, our call tree looks something like: ... call foo ... call bar ... call bar ... <STOPPED AT L2> If we go backwards from L2 to the previous instructions, we reach instructions pushing ra onto the stack so we can directly read that value (and recall that call bar is a pseudo-instruction for jal ra, bar which sets ra to pc + 4):

6.004 Spring 2022 - 11 of 21 - Quiz #1

... call foo ... call bar ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC4C ... <STOPPED AT L2> As a result, the value ra pushed onto the current stack frame corresponds to the return address of the recursive call bar instruction. By subtracting 4, we get the address of the recursive call bar instruction to be 0xC48. With a little math, we can also determine the addresses of the recursive call foo and initial call bar instructions (0xC0C and 0xC00, respectively). Now that we know the addresses of all call points (except the initial call foo, we’ll get that later), we can work down the stack frames and trace back the execution to the initial call to foo. The next stack frame pushes the same value for ra indicating it was also a recursive call to bar: ... call foo ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC4C ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC4C ... <STOPPED AT L2> The next stack frame pushes a different value of ra to the stack indicating it was the initial call bar instruction inside foo (you can also match this value with the address of foo’s call bar instruction we calculated earlier as 0xC00): ... call foo ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC04 ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC4C ... call bar // ra <- pc + 4 ...

6.004 Spring 2022 - 12 of 21 - Quiz #1

sw ra, 4(sp) // 0xC4C ... <STOPPED AT L2> Then, the next stack frame must belong to a call to foo. We don’t immediately know if this is the initial call to foo or if this is a recursive call. We work backwards until we reach instructions where foo is pushing ra onto the stack. ... call foo // ra <- pc + 4 ... sw ra, 4(sp) // 0xC10 ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC04 ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC4C ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC4C ... <STOPPED AT L2> Looking back to the addresses of the call foo instruction we calculated earlier, we see that this matches and thus we are in a recursive call to foo: ... call foo // ra <- pc + 4 ... sw ra, 4(sp) // 0xB08 ... call foo // ra <- pc + 4 ... sw ra, 4(sp) // 0xC10 ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC04 ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC4C ... call bar // ra <- pc + 4 ... sw ra, 4(sp) // 0xC4C ...

6.004 Spring 2022 - 13 of 21 - Quiz #1

<STOPPED AT L2> This foo, however, pushes a value of ra that we haven’t seen before. As a result, it must be from the initial call to foo and we have completed the call tree. (The address of the initial call foo instruction is thus 0xB04.) Now that we know where the initial stack frame is, we can step forward to determine the initial value of x. Notice that the initial stack frame is insufficient to tell us the initial value of x because the value pushed onto the stack for s0 is some value set by the original caller which is garbage to us. However, if we continue forward into the first recursive call to foo, we can get enough information. ... call foo ... sw s0, 0(sp) // GARBAGE ... srli s0, a0, 1 ... foo_else: mv a0, s0 call foo ... sw s0, 0(sp) // 0x9 ... We know from this that x = 0b1001? where the question mark indicates an unknown bit value so we have narrowed it down to 0x12 and 0x13. If we add a little more context, we can determine what that lowest most bit must be: ... call foo ... sw s0, 0(sp) // GARBAGE ... andi a1, a0, 1 srli s0, a0, 1 beqz a1, foo_else ... foo_else: mv a0, s0 call foo ... sw s0, 0(sp) // 0x9 ... Given that we jumped to foo_else, we know that a1 is equal to 0 and thus the lowest most bit is also 0 yielding a final answer of x = 0x12.

6.004 Spring 2022 - 14 of 21 - Quiz #1

F A

B out

Problem 5. Static Discipline (14 points) The F module below outputs 0.5V when 0.5 ∗ 𝑉! + 𝑉" > 2𝑉 for 25ns and outputs 5V when 0.5 ∗ 𝑉! + 𝑉" < 1.5𝑉 for 25ns. Furthermore, 𝑉! and 𝑉" are both between 0 and 5V. This is summarized in the equation below:

𝑉#$% = -0.5𝑉, 0.5 ∗ 𝑉! + 𝑉" > 2𝑉

5𝑉, 0.5 ∗ 𝑉! + 𝑉" < 1.5𝑉0 ≤? ? ?≤ 5𝑉, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

(A) (2 points) If we apply constant 𝑉!, 𝑉" for 25ns and then measure a 𝑽𝒐𝒖𝒕 = 𝟓, what can we

conclude about 𝑉"?

C1: 𝑉" < 1.5𝑉 C2: 𝑉" ≤ 2𝑉 C3: 𝑉" > 2𝑉 C4: 𝑉" ≥ 1.5𝑉 C5: None of the above

Best conclusion about 𝑽𝑩 (Circle one): C1 … C2 … C3 … C4 … C5

(B) (2 points) If we apply constant 𝑉!, 𝑉" for 25ns and then measure a 𝑽𝒐𝒖𝒕 = 𝟒, what can we conclude about 𝑉!?

C1: 𝑉! < 3𝑉 C2: 𝑉! ≤ 4𝑉 C3: 𝑉! > 4𝑉 C4: 𝑉! ≥ 3𝑉 C5: None of the above

Best conclusion about 𝑽𝑨 (Circle one): C1 … C2 … C3 … C4 … C5

(C) (2 points) What Boolean expression does the F module implement? Specify an equation using 𝐴 and B.

Boolean Expression: out = ____𝑨 + 𝑩_____________

(D) (4 points) What are the parameters that produce a maximum noise immunity for the F module shown above?

𝑽𝑶𝑳 = ___𝟎. 𝟓___ , 𝑽𝑰𝑳 = ___𝟏___ , 𝑽𝑰𝑯 = ___𝟒___ , 𝑽𝑶𝑯 = ___𝟓____

Noise Immunity = _____0.5___________

IfVout=5then0.5 ∗ 𝑉! + 𝑉" ≤ 2𝑉𝑉" ≤ 2𝑉

𝑉" ≤2𝑉

IfVout=4then1.5𝑉 ≤ 0.5 ∗ 𝑉! + 𝑉" ≤ 2𝑉𝑉! ≤ 4𝑉

6.004 Spring 2022 - 15 of 21 - Quiz #1

(E) (4 points) Now suppose we have a new device G, whose voltage transfer characteristic (VTC) is depicted below. We want to use both F and G in the same circuit, but we want to use the same signaling specification for both devices. What are the parameters that will produce a maximum noise immunity while satisfying both devices?

𝑽𝑶𝑳 = ___𝟎. 𝟓___ , 𝑽𝑰𝑳 = ___𝟎. 𝟕𝟓___ , 𝑽𝑰𝑯 = ___𝟒. 𝟐𝟓___ , 𝑽𝑶𝑯 = ___𝟓____

Noise Immunity = ___0.25_____________

Vin

Vout

0.75V

5V

0.5V

4.25 V

6.004 Spring 2022 - 16 of 21 - Quiz #1

Problem 6. Boolean Algebra and Combinational Logic (13 points) (A) (2 points) Consider the schematic of the circuit F(A, B, C) below. Derive its truth table.

A B C F

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 1

1 1 0 0

1 1 1 0

6.004 Spring 2022 - 17 of 21 - Quiz #1

(B) (3 points) Find the normal form and a minimal sum-of-products expression for G(A, B, C).

A B C G

0 0 0 1

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

1. Normal form for G = _________𝑎#𝑏#𝑐̅ + 𝑎#𝑏#𝑐 + 𝑎#𝑏𝑐 + 𝑎𝑏#𝑐 + 𝑎𝑏𝑐 __________

2. Minimal sum of products for G = _____𝑐 +𝑎#𝑏#_____________________

𝑎#𝑏#𝑐̅ + 𝑎#𝑏#𝑐 + 𝑎#𝑏𝑐 + 𝑎𝑏#𝑐 + 𝑎𝑏𝑐 = 𝑎#𝑏#𝑐̅ + 𝑎#𝑐 + 𝑎𝑐 = 𝑎#𝑏#𝑐̅ + 𝑐 = 𝑐 +𝑎#𝑏#

(C) (2 points) Is the circuit G(A, B, C) functionally complete? Explain.

F is functionally complete as we can construct a NOR gate. F(A, B, 0) = NOR(A, B).

6.004 Spring 2022 - 18 of 21 - Quiz #1

(D) (4 points) Simplify the following Boolean expressions by finding a minimal sum-of-products expression for each one. (Note: These expressions can be reduced into a minimal SOP by repeatedly applying the Boolean algebra properties we saw in lecture.)

1. (𝑥 + 𝑦)(𝑥 + 𝑦K)(�̅� + 𝑧)(�̅� + 𝑧̅) = (𝑥 + 𝑥𝑦 + 𝑥𝑦 + 𝑦𝑦)(𝑥 +𝑥𝑧 + 𝑥𝑧 + 𝑧𝑧)

= 𝑥𝑥 = 0

2. (𝑥 + 𝑦 + 𝑧)(𝑥 + 𝑦K + 𝑧̅) = 𝑥 + 𝑥𝑦 + 𝑥𝑧 + 𝑥𝑦 + 𝑦𝑦 + 𝑦𝑧 + 𝑥𝑧 + 𝑦𝑧 + 𝑧𝑧 = 𝑥 + 𝑦𝑧 + 𝑦𝑧

(E) (2 points) For each of the expressions in part D, find a set of variable assignments that makes

the expression true or explain why the expression cannot be satisfied with any variable assignment.

1. 𝑥 = ____,𝑦 = ____,𝑧 = ____orUNSATISFIABLE.

2. 𝑥 = __1__,𝑦 = __0__,𝑧 = __0__orUNSATISFIABLE.

1xx, x10, and x01 are all valid solutions.

6.004 Spring 2022 - 19 of 21 - Quiz #1

Problem 7: CMOS (14 points) (A) (3 points) The following 5-input circuit consists of two 2-input NAND gates, an inverter, and

a 3-input AND gate. Write a Boolean expression for the function Z. If the function Z can be implemented using a single CMOS gate, please draw the corresponding single CMOS gate. For full credit, use a minimum number of FETs. If it cannot be implemented using a single CMOS gate, explain why not.

𝑍(𝐴, 𝐵, 𝐶, 𝐷, 𝐸) = (𝐴𝐵KKKK)(𝐶̅)(𝐷𝐸KKKK) = (�̅� + 𝐵K)(�̅�)(𝐷_ + 𝐸K) The function Z is inverting (note we can express Z as a function of only the negations of the inputs) so we can implement Z using a single CMOS gate. Pullup (pFETs): (A in parallel with B) in series with C in series with (D in parallel with E) Pulldown (nFETs): (A in series with B) in parallel with C in parallel with (D in series with E).

6.004 Spring 2022 - 20 of 21 - Quiz #1

(B) (3 Points) A single CMOS gate, consisting of an output node connected to a single pFET-based pullup circuit and a single nFET-based pulldown circuit (as described in lecture), computes F(A, B, C, D). It is observed that F(0, 1, 1, 1) = 1. What can you say about the following values? Circle one of the options (0, 1, can’t tell).

a. F(1,1,0,1)=0…1…can’ttell

This has both rising and falling inputs compared to the reference we are given, so we can’t predict what will happen to the output.

b. F(0,1,0,0)=0…1…can’ttell This has falling inputs compared to the reference, so the output must either stay the same or rise. Since the reference output is 1 the output cannot rise, so it must stay the same.

c. F(1,1,1,1)=0…1…can’ttell An inverting function (a single CMOS gate can only implement inverting functions) must output 0 when the input is all 1s.

(C) (8 Points) For each of the following Boolean functions, choose the appropriate pullup design,

i.e., the one which, properly connected, implements that gate’s pullup using the minimum number of active transistors (a FET that is never on is not active). You can connect one of the inputs (A, B, C, or D) or a constant (GND, or VDD) to each pFET. For each expression, circle the name of your chosen pullup design (e.g. PU1) and label each pFET in your chosen design with the appropriate input or constant. You can use a design more than once. If none of the above pullups implements the function’s pullup, circle “NONE”.

a. 𝐹(𝐴, 𝐵, 𝐶, 𝐷) = (𝐴𝐵𝐶KKKKKK)𝐷_

𝐹(𝐴, 𝐵, 𝐶, 𝐷) = (𝐴𝐵𝐶KKKKKK)𝐷_ = (�̅� + 𝐵K + 𝐶̅)𝐷_ The pullup circuit has (A in parallel with B in parallel with C) in series with D.

6.004 Spring 2022 - 21 of 21 - Quiz #1

b. 𝐹(𝐴, 𝐵, 𝐶, 𝐷) = (𝐴 + 𝐵)(𝐶̅ + 𝐷_)KKKKKKKKKKKKKKKKKKKK

𝐹(𝐴, 𝐵, 𝐶, 𝐷) = (𝐴 + 𝐵)(𝐶̅ + 𝐷_)KKKKKKKKKKKKKKKKKKKK = 𝐴 + 𝐵KKKKKKKK + 𝐶̅ + 𝐷_KKKKKKKK = �̅�𝐵K + 𝐶𝐷 This function is non-inverting (note the presence of C and D in the expression for F) so the answer is NONE.

c. 𝐹(𝐴, 𝐵, 𝐶, 𝐷) = (𝐵 + 𝐶KKKKKKKK)(�̅�)(𝐵𝐷KKKK)

(𝐴, 𝐵, 𝐶, 𝐷) = (𝐵 + 𝐶KKKKKKKK)(�̅�)(𝐵𝐷KKKK) = 𝐵K𝐶̅�̅�(𝐵K + 𝐷_) = 𝐵K𝐶̅�̅�𝐵K + 𝐵K𝐶̅�̅�𝐷_ = 𝐵K𝐶̅�̅� +𝐵K�̅��̅�𝐷_ =𝐵K𝐶̅�̅�(1 + 𝐷_) = 𝐵K𝐶̅�̅� The pullup circuit has A, B, and C all in series. This can be implemented using PU4, or using PU5 with the additional parallel pFET connected to VDD (both solutions have the same number of active transistors since the pFET connected to VDD is never on).

d. 𝐹(𝐴, 𝐵, 𝐶, 𝐷) = (�̅� + �̅�)(𝐵K)(𝐷 + 𝐷_)

(𝐴, 𝐵, 𝐶, 𝐷) = (�̅� + 𝐶̅)(𝐵K)(𝐷 + 𝐷_) = (�̅� + �̅�)(𝐵K) The pullup circuit has (A in parallel with C) in series with B. This can be implemented using PU2 by connecting the extra parallel pFET to VDD.

END OF QUIZ 1!