3
points.A
We are given an array of unique uint32_t
that represent nodes in a directed graph. We say there is an edge between A and B if A < B
and the Hamming distance between A and B is exactly 1
. A Hamming distance of 1
means that the bits differ in 1
(and only 1) place. As an example, if the array were {0b0000, 0b0001, 0b0010, 0b0011, 0b1000, 0b1010}
, we would have the edges shown as following:
See also: LeetCode 461. Hamming Distance
Construct an edgelist_t
(specified below) that contains all of the edges in this graph.
Our solution used every line provided, but if you need more lines, just write them to the right of the line they are supposed to go after and put semicolons between
them. All of the necessary #include
statements are omitted for brevity; do not worry about checking for malloc
, calloc
, or realloc
returning NULL
. Make sure L->edges
has no unused space when L
is eventually returned.
- A01 = ?
- A02 = ?
- A03 = ?
- A04 = ?
B
Consider the following circuit:
You are given the following information:
Clk
has a frequency of 50 MHzX
changes 10ns after the rising edge of Clk
Reg1
and Reg2
have a clock-to-Q delay of 2 nsThe clock period is . This means that if X
changes, it changes 10 ns after the clock positive edge.
What is the longest possible setup time such that there are no setup time violations? (Please include ns in your answer.)
B01 = ?
What is the longest possible hold time such that there are no hold time violations? (Please include ns in your answer.)
B02 = ?
Represent the circuit above using an equivalent FSM, shown in the following, where X is the input and Q is the output, with the state labels encoding Reg1Reg2 (e.g., 01
means Reg1 = 0
and Reg2 = 1
). We did one transition already.
- B03 = ?
- B04 = ?
C
What is the FULLY SIMPLIFIED (fewest primitive gates) circuit for the equation below? You may use the following primitive gates: AND, NAND, OR, NOR, XOR, XNOR, and NOT. (You can use the LaTeX syntax \overline A
to represent )
- C01 = ?
D
Consider the following RISC-V assembly code.
Recall that immediate values are generated from instructions with the following table:
We will refer to the number produced after this process is completed as the "immediate value."
What are the fields for the machine code generated for beq s1, x0, End
(line 4)?
Immediate value
- D01 = ?
funct3
- D02 = ?
opcode
- D03 = ?
rs1
- D04 = ?
rs2
- D05 = ?
E
Consider the following pipelined circuit. Assume all registers have their clock inputs correctly connected to a global clock signal and that logic gates have the following parameters:
When shopping for registers, we find two different models and want to determine which would be best for our circuit.
Register Type
Register Type
- E01 = ?
- E02 = ?
F
Consider the following RISC-V code:
bltu
instruction?
- F01 = ?
7
bits). This justifies taking out the funct3
field from the R, I, S, and SB instructions, allowing you to allocate bits to other instruction fields except the opcode field. Assume register s0 = 0x1000 0000
, s1 = 0x4000 0000
, PC = 0xA000 0000
. Let's analyze the instruction: jalr s0, s1, MAX_POS_IMM
where MAX_POS_IMM
is the maximum possible positive immediate for jalr
. After the instruction executes, what are the values in the following registers? (Answer in HEX)
s0
= F02s1
= F03PC
= F04
- F02 = ?
- F03 = ?
- F04 = ?
G
Consider the following circuit:
Assume input A and input B come from registers. Assume all 2-input logical gates have a 10 ns propagation delay. The NOT
gate has a 5 ns delay. All registers have a clk-to-q of 15 ns and setup time of 20 ns.
- G01 = ?
- G02 = ?
H
We wish to implement a function, reverse
, that will take in a pointer to a string, its length, and reverse it. Assume that the argument registers, a0
and a1
, hold the pointer to and length of the string, respectively. Complete the following code skeleton to implement this function.
- H01 = ?
- H02 = ?
- H03 = ?
- H04 = ?
J
Take a look at the following circuit:
We have a register clk-to-Q time of 5ps, a hold time of 2ps, and a setup time of 3ps. AND and NAND gates have a delay of 5ps, OR and XOR gates have a delay of 6ps, and
NOT gates have a delay of 1ps. Assume that our inputs A, B, C, and D arrive on the rising edge of the clock.
Which gates make up the critical path in the circuit above? Your answer should be correctly ordered from left to right, e.g. NOT OR NAND.
- J01 = ?
What is the critical path delay in the circuit?
- J02 = ?
Let us now consider only the portion of the circuit between Reg2
and Reg3
. Assume that the clock period (rising edge to rising edge) is 100 ps, registers have a clk-to-Q delay of 25ps and a setup and hold time of 20ps, and all gates have a delay of 5ps. Choose the waveform with the correct outputs for Reg2
and Reg3
.
Notation: For reference, in the diagram below, the first region indicates an "undefined" signal, the second region indicates a signal of "high" or 1, and the third region indicates a signal of "low" or 0.
J03 = ?
K
Consider the following program that computes the Fibonacci sequence recursively. The C code is shown on the left, and its translation to RISC-V assembly is provided on the right. You are told that the execution has been halted just prior to executing the ret instruction. The SP label on the stack frame (part 3) shows where the stack pointer is pointing to when execution halted.
Complete the missing portion of the ble
instruction to make the assembly implementation match the C code.
- K01 = ?
How many distinct words will be allocated and pushed into the stack each time the function fib
is called?
- K02 = ?
Please fill in the values for the blank locations in the stack trace below. Please express the values in HEX.
Notation | address |
---|---|
Smaller address | 0x280 |
0x1 | |
K03 | |
SP | K04 |
K05 | |
0x0 | |
0x280 | |
0x3 | |
0x0 | |
0x2108 | |
0x4 | |
0x6 | |
Larger address | 0x1 |
- K03 = ?
- K04 = ?
- K05 = ?
What is the hex address of the done
label? (Answer in HEX)
- K06 = ?
What was the address of the original function call to fib
? (Answer in HEX)
- K07 = ?
L
Suppose we want to create a system that decides if the concatenation of its previous 2 single-bit inputs is a power of 2 (where the MSB is the input from 2 cycles ago and the LSB is from 1 cycle ago). If the previous 2 bits (prior to the current input) are a power-of-two the system outputs a 1, otherwise it outputs 0. Before any input is sent, assume the initial previous 2 bits are 2'b00.
A partial finite state machine diagram of this circuit is shown below:
Before receiving any inputs the FSM is in state A.
For this FSM to provide the correct answer, to what existing states must D transition to (A, B, C, or D), and what output does D give (0 or 1)?
- L01 = ?
- L02 = ?
- L03 = ?