Digital Electronics & Computer Engineering (E85) Harris...
Transcript of Digital Electronics & Computer Engineering (E85) Harris...
-
Page 1 of 18
This is a closed-book take-home exam. Electronic devices including calculators are not allowed, except on the computer question on the last page. You are permitted two 8.5x11” sheets of paper with notes. You are bound by the HMC Honor Code while taking this exam. The first part of the exam is written, while the final page is done on the computer based on your E85 Lab 11. The entire Lab 11 that you use (including datapath and controller) must be your own work; it cannot, for example, include somebody else’s controller. The exam is intended to be doable in 3 hours if you have prepared adequately. However, there will be no limit on the time you are allowed except that the written portion must be completed in one contiguous block of time and the computer part must be completed in another contiguous block of time. A contiguous block of time is a period of time working at a desk without breaking for meals, naps, socializing, etc. Please manage your time wisely and do not let the exam expand to take more time than is justified. Return the exam to Sydney Torrey in the Engineering Department Office no later than Friday 5/11 at noon (5/4 at 5 pm for seniors). Alongside each question, the number of points is written in brackets. All work and answers should be written directly on this examination booklet, except for printouts. Use the backs of pages if necessary. Write neatly; illegible answers will be marked wrong. Show your work for partial credit.
Name: ___________________________________________
Do Not Write Below This Point Page 2: ____________________ / 6 Pages 3-4: ____________________ / 12 Page 5: ____________________ / 6 Page 6: ____________________ / 3 Page 11: ____________________ / 6 Page 12: ____________________ / 3 Page 13-16: ____________________ / 8 Page 18: ____________________ / 6 Total: ____________________ / 50
Digital Electronics & Computer Engineering (E85) Harris Spring 2018
Final Exam
-
Page 2 of 18
[1] Give an expression for the maximum value of an int in C on a 32-bit microprocessor?
Maximum Value: ____________________
[2] Give the closest approximation to p that you can represent with an 8-bit two’s complement fixed point number with four fractional bits. Express your result in hexadecimal.
Approximation of p: ____________________
[3] Determine the decimal value of the IEEE single precision floating point number C0C80000
Number: ______________________
-
Page 3 of 18
Consider the following “LFSR” circuit. Each flip-flop has a set input s to initialize its output to 1 when reset is applied.
[1] Show the sequence of values q takes on for the next 10 cycles after the circuit is reset.
Cycle q
1
2
3
4
5
6
7
8
9
10
[2] Give a succinct description of the circuit in Verilog. module lfsr(input logic clk, reset
output logic q)
endmodule
-
Page 4 of 18
The XOR has a propagation delay of 20 ps and a contamination delay of 10 ps. It’s input capacitance is 1 fF on each input pin and the leakage current is 10 nA. The flip-flop has a clock-to-Q propagation delay of 25 ps and contamination delay of 16 ps. Its setup time is 9 ps and its hold time is 12 ps. It’s input capacitance is 0.667 fF on the D pin and 2 fF on the CLK pin, and the leakage current is 30 nA. You also have buffers available with a propagation delay of 8 ps and contamination delay of 6 ps. The power supply is 0.8 V.
[2] What is the fastest clock rate at which the LFSR circuit could operate in the absence of skew?
Fastest Clock: _________________ (ps)
[2] What is the static power consumption Pstatic of the circuit?
Pstatic: _________________
[2] What is the dynamic power consumption of the circuit operating at 1 MHz Pdynamic-1MHz?
Pdynamic-1MHz: _________________ [1] Above what clock frequencies does the dynamic power consumption exceed the static consumption? Give your answer in terms of Pstatic and Pdynamic-1MHz.
Frequency: _________________
[2] Mark up the circuit with minimum modifications necessary for the circuit to operate correctly if the clock skew between flip-flops may be as much as 11 ps.
-
Page 5 of 18
[6] Translate the following function to ARM assembly language. str is passed in R0. Remember that R1-R3 and R12 do not need to be saved or restored across a function call. void toupper(char str[]) int i = 0; while (str[i]) { if (str[i] > 96) str[i] = str[i] – 32; i++; } }
Assembly language
-
Page 6 of 18
[3] Translate the following ARM assembly language into machine language. Refer to the instruction encodings on the next page. Express your instructions in hexadecimal.
do Machine Language LDR R2, [R5, R6] _____________________________
CMP R2, #42 _____________________________ BLE do _____________________________
-
Page 7 of 18
-
Page 8 of 18
-
Page 9 of 18
The STM32 has a 12-bit analog-to-digital converter (ADC). To initialize the ADC:
• Enable the ADC clock in the Reset and Clock Control register.
• Turn on the ADC by setting the ADEN bit.
• Wait until the ADRDY flag is set to indicate the ADC is ready for conversion
• Write 111 to the SMP bits to run the sampling clock sufficiently slow. To convert the voltage from channel n:
• Write a 1 to the CHSELn bit and 0s to other CHSEL bits to select channel n for conversion.
• Start a conversion by setting the ADSTART bit
• Wait for the ADSTART bit to go low to indicate the conversion is complete
• Read the answer from the ADC_DR data register Relevant register maps are given below:
-
Page 10 of 18
-
Page 11 of 18
[3] Complete the following function to initialize the ADC for a particular channel. The clock enabling code is provided for you. void adcInit(int channel) {
volatile unsigned long *RCC_APB2ENR = (unsigned long*)0x40021018;
// Enable ADC clock by writing 1 to ADCEN bit of RCC_APB2ENR
*RCC_APB2ENR |= 1
-
Page 12 of 18
Consider the 5-stage pipelined ARM processor with hazard unit from Chapter 7 running the following program. Assume that it has been enhanced to support the MOV instruction. The MOV instruction is issued on cycle 1. MOV R3, #1
ADD R4, R3, #7
SUB R5, R3, R3
LDR R6, R3, R4
ADD R7, R6, R3
[1] What operation does the ALU perform on cycle 4? ______________
[1] What is the output of the ALU on cycle 5? ______________
[1] In which cycle is R7 written? ______________
-
Page 13 of 18
The ARM MOV Rd, Rn instruction copies the value from Rn into Rd. It is a data processing instruction with a cmd field of 1101. MOVS does the same, and affects the N and Z flags. Modify the ARM multicycle processor to support the MOV and MOVS instructions, using as little additional hardware as feasible. [3] Mark up the attached multicycle processor diagram and ALU to handle the new instructions.
[2] Mark up the attached multicycle controller (including state transition diagram and truth tables) to handle the new instructions. [2] The attached multicycle memfile.s test code has highlighted modifications to test the new instruction. Translate these three new lines of assembly to machine language. Express your code in hexadecimal. The format for a data processing instruction is given below. The cmd field for ORR is 1100 and the cond field for ALWAYS is 1110.
MOV R9, R2: _____________________ ORR R9, R9, #17: _____________________
MOV R2, R9: _____________________
[1] Predict what value should be written to mem[248] at the last line of the program.
Predicted Value: _____________________
Data-processing
cond op cmd Rn Rd31:28 27:26 24:21 19:16 15:12 11:0 411:7 6:5
shshamt5 0
11:8
Rs sh6:5
1047
11:8
rot imm87:0
Src2 Rm
Rm
3:0
3:0
00 I25
S20
funct
I = 1
I = 0
Immediate
Register
Register-shifted Register
Figure B.1 Data-processing instruction encodings
Table B.1 Data-processing instructions
cmd Name Description Operation
0000 AND Rd, Rn, Src2 Bitwise AND Rd ← Rn & Src2
0001 EOR Rd, Rn, Src2 Bitwise XOR Rd ← Rn ^ Src2
0010 SUB Rd, Rn, Src2 Subtract Rd ← Rn – Src2
0011 RSB Rd, Rn, Src2 Reverse Subtract Rd ← Src2 – Rn
0100 ADD Rd, Rn, Src2 Add Rd ← Rn+Src2
0101 ADC Rd, Rn, Src2 Add with Carry Rd ← Rn+Src2+C
0110 SBC Rd, Rn, Src2 Subtract with Carry Rd ← Rn – Src2 – C
0111 RSC Rd, Rn, Src2 Reverse Sub w/ Carry Rd ← Src2 – Rn – C
1000 (S = 1) TST Rd, Rn, Src2 Test Set flags based on Rn & Src2
1001 (S = 1) TEQ Rd, Rn, Src2 Test Equivalence Set flags based on Rn ^ Src2
1010 (S = 1) CMP Rn, Src2 Compare Set flags based on Rn – Src2
1011 (S = 1) CMN Rn, Src2 Compare Negative Set flags based on Rn+Src2
1100 ORR Rd, Rn, Src2 Bitwise OR Rd ← Rn | Src2
1101 Shifts:I = 1 OR(instr11:4 = 0)
MOV Rd, Src2 Move Rd ← Src2
I = 0 AND(sh = 00;instr11:4 ≠ 0)
LSL Rd, Rm, Rs/shamt5 Logical Shift Left Rd ← Rm > Src2
(continued)
536 APPENDIX B ARM Instructions
-
Page 14 of 18
Multicycle Processor
ALU
before sending it to PCWrite, RegWrite, and MemWrite so that updatedcondition flags are not seen until the end of an instruction. The remainderof this section develops the state transition diagram for the Main FSM.
The Main FSM produces multiplexer select, register enable, andmemory write enable signals for the datapath. To keep the following statetransition diagrams readable, only the relevant control signals are listed.Select signals are listed only when their value matters; otherwise, theyare don’t care. Enable signals (RegW, MemW, IRWrite, and NextPC)are listed only when they are asserted; otherwise, they are 0.
The first step for any instruction is to fetch the instruction frommemoryat the address held in the PC and to increment the PC to the next instruction.The FSM enters this Fetch state on reset. The control signals are shown inFigure 7.32. The data flow on this step is shown in Figure 7.33, with theinstruction fetch highlighted in blue and the PC increment highlightedin gray. To read memory, AdrSrc= 0, so the address is taken from the PC.IRWrite is asserted to write the instruction into the instruction register, IR.Meanwhile, the PC should be incremented by 4 to point to the next instruc-tion. Because the ALU is not being used for anything else, the processor can
ExtImm
CLK
ARD
Instr / DataMemory
PC 01
PC' Instr
SrcB
ALUResult
SrcA
ALUOut
MemWrite
ALUSrcA
RegWrite
ALUFlags
ResultSrc
CLK
CLK
ALUControl
ALU
WD
WE
CLK
Adr
Data
CLK
CLK
A
WriteD
ata
4
CLK
ENEN
ALUSrcB
IRWrite
AdrSrcPCWrite
Re
adD
ata
A1
A3WD3
RD2
RD1WE3
A2
CLK
RegisterFile
R15
0 1
01
RegS
rc
19:16
15:12
23:0
3:0
15
000110
000110
Result
25:20
27:26 OpFunct
Cond
Flags
15:12 Rd
ControlUnit
ImmSrc
Extend
31:28
RA1
RA2
10
01
Figure 7.30 Complete multicycle processor
414 CHAPTER SEVEN Microarchitecture
it to perform subtraction:A+B + 1=A−B.) IfALUControl= 10, the ALUcomputes A AND B. If ALUControl= 11, the ALU performs AOR B.
Some ALUs produce extra outputs, called flags, that indicate infor-mation about the ALU output. Figure 5.16 shows the ALU symbolwith a 4-bit ALUFlags output. As shown in the schematic of this ALUin Figure 5.17, the ALUFlags output is composed of the N, Z, C, and Vflags that indicate, respectively, that the ALU output is negative or zeroor that the adder produced a carry out or overflowed. Recall that themost significant bit of a two's complement number is 1 if it is negativeand 0 otherwise. Thus, the N flag is connected to the most significantbit of the ALU output, Result31. The Z flag is asserted when all of the bitsof Result are 0, as detected by the N-bit NOR gate in Figure 5.17. The Cflag is asserted when the adder produces a carry out and the ALU is per-forming addition or subtraction (ALUControl1= 0).
Overflow detection, as shown on the left side of Figure 5.17, is trickier.Recall from Section 1.4.6 that overflow occurs when the addition oftwo same signed numbers produces a result with the opposite sign.So, V is asserted when all three of the following conditions are true: (1)the ALU is performing addition or subtraction (ALUControl1= 0), (2)A and Sum have opposite signs, as detected by the XOR gate, and, as
ALU
N N
N
2
A B
Result
ALUControl
4
ALUFlags{N,Z,C,V}
Figure 5.16 ALU symbol withoutput flags
+
00
A B
Cout
Result
01
ALU
Control0
ALUControl
Sum
NN
N
N
N NNN
N
2011011
Zero
ALUControl1
Result31
NegativeCarry
ALUControl0
A31B31
ALUFlags4
ZN VC
Sum31
oVerflow
Figure 5.17 N-bit ALU with outputflags
250 CHAPTER FIVE Digital Building Blocks
-
Page 15 of 18
Multicycle Controller
ImmSrc1:0
MemW
ResultSrc1:0ALUSrcA
ALUControl1:0
Decoder
RegW
Cond3:0
Op1:0
Funct5:0
Rd3:0
RegSrc1:0
FlagW1:0
ALUFlags3:0
MemWriteRegWrite
PCWritePCSNextPC
IRWrite
ALUSrcB1:0
AdrSrc
Conditional Logic
MainFSM
ALUOp
ALUDecoder
Op1:0
Funct5:0
Rd3:0
5,0
PC Logic PCS
FlagW1:0
ALUControl1:0
ImmSrc1:0
ALUSrcA
RegSrc1:0
MemWRegW
4:0
NextPCIRWrite
AdrSrcResultSrc1:0
ALUSrcB1:0
InstrDecoderOp1:0
Cond3:0
Flags3:2
CLK
CLKALUFlags3:0
Flags1:0
[3:2]
[1:0]
PCS
[1]
[0]
Condition C
heck
FlagW1:0
PCWrite
MemWrite
RegWrite
Co
ndEx
MemW
RegW
NextPC
CLK
CLK
Branch
(a) Control Unit
Decoder(b) (c) Conditional Logic
RegisterEnables
Multiplexer Selects
CLK
Flag
Write
1:0
Figure 7.31 Multicycle control unit
7.4 Multicycle Processor 415
S0: FetchAdrSrc = 0AluSrcA = 1
ALUSrcB = 10ALUOp = 0
ResultSrc = 10IRWriteNextPC
S1: DecodeALUSrcA = 1ALUSrcB = 10
ALUOp = 0ResultSrc = 10
S2: MemAdrALUSrcA = 0ALUSrcB = 01
ALUOp = 0
S3: MemReadResultSrc = 00
AdrSrc = 1
S8: ALUWBResultSrc = 00
RegW
S5: MemWriteResultSrc = 00
AdrSrc = 1MemW
S7: ExecuteIALUSrcA = 0ALUSrcB = 01
ALUOp = 1
S9: BranchALUSrcA = 0ALUSrcB = 01
ALUOp = 0ResultSrc = 10
Branch
Reset
Memory Op = 01
Data RegOp = 00Funct5 = 0
Branch Op = 10
LDR STR
S4: MemWBResultSrc = 01
RegW
State Datapath µOpFetch Instr ←Mem[PC]; PC ← PC+4Decode ALUOut ← PC+4MemAdr ALUOut ← Rn + ImmMemRead Data ← Mem[ALUOut]MemWB Rd ← DataMemWrite Mem[ALUOut] ← RdExecuteR ALUOut ← Rn op RmExecuteI ALUOut ← Rn op ImmALUWB Rd ← ALUOutBranch PC ← R15 + offset
S6: ExecuteRALUSrcA = 0ALUSrcB = 00
ALUOp = 1
Data ImmOp = 00Funct5 = 1
Funct0 = 1 Funct0 = 0
Figure 7.41 Complete multicycle control FSM
7.4 Multicycle Processor 423
-
Page 16 of 18
; memfile.dat
MAIN SUB R0, R15, R15 ; R0 = 0 1110 000 0010 0 1111 0000 0000 0000 1111 E04F000F 0x00 ADD R2, R0, #5 ; R2 = 5 1110 001 0100 0 0000 0010 0000 0000 0101 E2802005 0x04 ADD R3, R0, #12 ; R3 = 12 1110 001 0100 0 0000 0011 0000 0000 1100 E280300C 0x08 SUB R7, R3, #9 ; R7 = 3 1110 001 0010 0 0011 0111 0000 0000 1001 E2437009 0x0c ORR R4, R7, R2 ; R4 = 3 OR 5 = 7 1110 000 1100 0 0111 0100 0000 0000 0010 E1874002 0x10 AND R5, R3, R4 ; R5 = 12 AND 7 = 4 1110 000 0000 0 0011 0101 0000 0000 0100 E0035004 0x14 ADD R5, R5, R4 ; R5 = 4 + 7 = 11 1110 000 0100 0 0101 0101 0000 0000 0100 E0855004 0x18 SUBS R5, R5, #10 ; R5 = 11 - 10 = 1 1110 001 0010 1 0101 0101 0000 0000 1010 E255500A 0x1c SUBSGT R5, R5, #2 ; R5 = 1 - 2 = -1 1100 001 0010 1 0101 0101 0000 0000 0010 C2555002 0x20 ADD R5, R5, #12 ; R5 = -1 + 12 = 11 1110 001 0100 0 0101 0101 0000 0000 1100 E285500C 0x24 SUBS R8, R5, R7 ; R8 = 11 - 3 = 8 1110 000 0010 1 0101 1000 0000 0000 0111 E0558007 0x28 BEQ END ; not taken 0000 1010 0000 0000 0000 0000 0000 1100 0A00000F 0x2c SUBS R8, R3, R4 ; R8 = 12 - 7 = 5 1110 000 0010 1 0011 1000 0000 0000 0100 E0538004 0x30 BGE AROUND ; should be taken 1010 1010 0000 0000 0000 0000 0000 0000 AA000000 0x34 ADD R5, R0, #0 ; should be skipped 1110 001 0100 0 0000 0101 0000 0000 0000 E2805000 0x38 AROUND SUBS R8, R7, R2 ; R8 = 3 - 5 = -2 1110 000 0010 1 0111 1000 0000 0000 0010 E0578002 0x3c ADDLT R7, R5, #1 ; R7 = 11 + 1 = 12 1011 001 0100 0 0101 0111 0000 0000 0001 B2857001 0x40 SUB R7, R7, R2 ; R7 = 12 - 5 = 7 1110 000 0010 0 0111 0111 0000 0000 0010 E0477002 0x44 STR R7, [R3, #224] ; mem[12+224] = 7 1110 010 1100 0 0011 0111 0000 0101 0100 E58370E0 0x48 LDR R2, [R0, #236] ; R2 = mem[236] = 7 1110 010 1100 1 0000 0010 0000 0110 0000 E59020EC 0x4c ADD R15, R15, R0 ; PC
-
Page 17 of 18
END OF WRITTEN PORTION OF EXAM
DO NOT PROCEED PAST THIS POINT UNTIL YOU ARE PREPARED TO CEASE ALL WORK ON THE WRITTEN PORTION AND MOVE ON TO THE
COMPUTER PORTION.
-
Page 18 of 18
COMPUTER PORTION OF EXAM Once you start this question, you may refer to the written portion of the exam, but may not spend any more time on the written portion or change any of your answers on that portion.
Modify your ARM multicycle processor from Lab 11 to support the MOV instruction. Modify your memfile.dat to add the three new lines of machine language code from the previous question. Simulate your modified code.
[2] Print out your Verilog code and circle or highlight the lines you modified.
[4] Print out a simulation waveform showing at least the value being written to memory location 248 on the last cycle. Circle this value in the waveform.