Title | Cs2100exam 1516s2 ans - Past year papper from CS2100. Question 7 to 11 |
---|---|
Author | Zelin Hang |
Course | Computer Organisation |
Institution | National University of Singapore |
Pages | 16 |
File Size | 1.1 MB |
File Type | |
Total Downloads | 180 |
Total Views | 225 |
NATIONAL UNIVERSITY OF SINGAPORECS2100 – COMPUTER ORGANISATION(Semester 2: AY2015/16)Time Allowed: 2 HoursINSTRUCTIONS TO CANDIDATES1. Please write your Student Number on odd‐numbered pages of ...
CS2100
Answer
NATIONALUNIVERSITYOFSINGAPORE
CS2100–COMPUTERORGANISATION (Semester2:AY2015/16) TimeAllowed:2Hours
INSTRUCTIONS TO CANDIDATES 1. PleasewriteyourStudentNumberonodd‐numberedpagesoftheANSWERBOOKLET provided.Donotwriteyourname. 2. ThisassessmentpaperconsistsofELEVEN(11)questionsandcomprisesTEN(10)printed pages. 3. AnswerallquestionsandwriteyouranswersintheANSWERBOOKLETprovided. 4. ThisisaCLOSEDBOOKassessment.TwohandwrittenA4referencesheetsareallowed. 5. Calculatorsarenotallowed. 6. Youmayusepenciltowriteyouranswers. 7. Thelastthreepagesareforyourroughwork.Theycontainblank,K‐maps,statetableand timingchartsforyouruse. 8. YouaretosubmitonlytheANSWERBOOKLETandnootherdocument.
CS2100
Questions 1 ‐ 6: Each question has only one correct answer. Write your answers in the boxes provided in the Answer Booklet. One mark is awarded for a correct answerandno penaltyforwronganswer.
1. Giventhefollowingjumpinstruction,originallyencodedas0x087B00A7: target: .............
#
j target
Supposetheprogrammerlaterremove1oftheinstructionsin.Whatis thenewencodingforthejumpinstruction? A. B. C. D. E.
0x087B00A3 0x087B00A6 0x087B00A7 0x087B00A8 Noneoftheabove.
Commented [SYJ1]: Answer. The target instruction address is not affected.
2. Givenaprogramwith40%,40% and20%ofinstructiontypesA,BandCrespectively, whichofthefollowingchangesreducestheexecutiontimebyexactly40%ifCPIsforA, BandCare1,2and4respectively? i. SpeedupexecutiontimeforinstructiontypeAby2xandtypeCby4x. ii. SpeedupexecutiontimeforinstructiontypesBandCby2x. iii. SpeedupexecutiontimeforinstructiontypesAandBby2x. A. B. C. D. E.
Commented [SYJ2]: Time proportion for A, B and C are 40x1 , 40x2, 20 x 4 = 40, 80, 80 = 20%, 40%, 40% Commented [SYJ3]: 20/2 + 40 + 40/4 = 10 + 40 + 10 = 60 (40% reduction) Commented [SYJ4]: 20 + 40/2 + 40/2 = 60 (40% reduction)
Only(i)isTRUE. Only(i)and(ii)areTRUE. Only(ii)and(iii)areTRUE. (i),(ii)and(iii)areallTRUE. Noneoftheabove.
Commented [SYJ5]: 20/2 + 40/2 + 40 = 10 + 20 + 40 = 70 (30% reduction) Commented [SYJ6]: Answer
3. Suppose the cache index for the 16‐bit memory address 0xABCD is 0xE, which of the followingstatementsisTRUEregardingtheconfigurationofthiscache?
A. B. C. D. E.
Cachetag=4bits;Offset=8bits Cachetag=5bits;Offset=7bits Cachetag=6bits;Offset=6bits Cachetag=7bits;Offset=5bits Noneoftheabove.
Page2of16
Commented [SYJ7]: A B C D 1010 1011 1100 1101 E = 1110 The bolded portion is the only possibility.
Commented [SYJ8]: Answer
CS2100
4. Ifajumpinstruction,encodedas0x087B00A7isexecutedbythesinglecycle5‐stage MIPSprocessor,whatisthereadregisternumber2suppliedtotheregisterfileduring decode? A. B. C. D. E.
Registernumber=2710 Registernumber=2210 Registernumber=1110 Registernumber=710 Noneoftheabove
Commented [SYJ9]: 0 8 7 B 0 …….. 0000 1000 0111 1011 0000 ……….. The bolded portion is the read register number 2, i.e. 27 Commented [SYJ10]: Answer
5. The nop is a MIPS instruction that does nothing at all (i.e. the execution does not change the register / memory content in any way). Which of the following control signalsshouldbean'X'(don’tcare)forthenopinstruction? i. ALUSrc ii. MemToReg iii. RegDst A. B. C. D. E.
Only(i)isTRUE. Only(i)and(ii)areTRUE. Only(ii)and(iii)areTRUE. (i),(ii)and(iii)areallTRUE. Noneoftheabove.
Commented [SYJ11]: Answer
6. Suppose the "isBranch" control signal generated by a faulty control unit is always '1'. Which of the following instructions will cause this processor to branch to instruction addressotherthan(PC+4)afterexecution?YoucanassumethePCoftheinstructionis at0x04000000. i.
xor $t0, $s0, $s0#$s0containsrandomvalue
ii. andi $t0, $zero, 0xABCD iii. lw $s0, 0( $zero ) A. B. C. D. E.
Commented [SYJ14]: result is zero and immediate field is not 0
Commented [SYJ16]: Answer.
Page3of16
Commented [SYJ13]: result is zero and immediate field is not 0
Commented [SYJ15]: result is zero but immediate field is 0, i.e. BTA = PC+4 + Immd x 4 = PC+4.
Only(i)isTRUE. Only(i)and(ii)areTRUE. Only(ii)and(iii)areTRUE. (i),(ii)and(iii)areallTRUE. Noneoftheabove.
Commented [SYJ12]: Essentially looking for instructions where calculation result is 0 AND the immediate field is not 0.
CS2100
7. [12marks] Design a sequential circuit that takes a 1‐bit input X. When X = 0, the circuit cycles throughthe3‐bitGraycodesasfollow: 000001011010110111101100000….(repeats) WhenX=1,thecircuitcyclesthroughthesame3‐bitGraycodesequencebutinreverse order: 000100101111110010011001000….(repeats) Thestatesarerepresentedby3‐bitvaluesABC.Implementthesequentialcircuitusinga Dflip‐flopfor A,aTflip‐flopforB,andaJKflip‐flopfor C.Usethepartiallyfilledstate tablegivenonpage8tohelp. a. WriteoutthesimplifiedSOPexpressionsforalltheflip‐flopinputs.
[4marks]
b. ImplementDAusinga4‐to‐1Multiplexer.TheselectorlineshavebeenfixedtoS1=C andS0=X,soyouonlyneedtofillintheinputlines.Theinputsarerestrictedtonon‐ primedliterals,primedliteralsandconstants(0/1)only. [4marks]
Commented [SYJ17]: Seepage11forworking. DA=B.C'.X'+B'.C'.X+A.C TB=A'.B'.C.X'+A'.B.C.X+A.B.C.X'+A.B'.C.X JC=A'.B'.X'+A'.B.X+A.B.X'+A.B'.X KC=A'.B'.X+A'.B.X'+A.B.X+A.B'.X' Commented [SYJ18]: See page 12 for (b), (c) and (d).
c. ImplementJCusingnomorethantwo2‐inputgates(AND,OR,XORorXNOR).Only non‐primedliteralsandconstantsareavailable. [3marks] d. Using an additional 2‐input XOR or XNOR gate, implement KC by utilizing the JC function (i.e. use JC as one of the possible inputs). Only non‐primed literals and constantsareavailable. [1mark] 8. [5marks]IEEE‐754singleprecisionformatencodesafloatingpointvaluein32bits:
SupposeanIEEE‐754floatingpointvalueisstoredinregister$s0,attemptthefollowing. a. Use1MIPSinstructiontoextractthesign‐bitintoregister$t0,i.e.$t0stores0or1 attheend. [1marks] b.Useatmost3MIPSinstructionstoextractthebias‐127exponentintoregister$t1, i.e.$t1stores‐127to128attheend. [2marks] c. Recall that the mantissa was normalized to 1.X and only the fraction X (23 bits) is stored in the IEEE754 format. Suppose someone extracted the fraction bits and addedtheleading'1'inregister$t2foryou(i.e.$t2nowstoresa24‐bitvaluewith leading zeroes). Use the sign bit $t0 from part (a) and $t2 to produce a 2s complementof themantissa inregister $s1. Fillin thetwo missinginstructions in thepartialcodingintheanswersheet. [2marks] Page4of16
Commented [SYJ19]: srl $t0, $s0, 31
Commented [SYJ20]: sll $t0, $s0, 1 #drop sign bit srl $t0, $t0, 24 #drop fraction addi $t1, $t0, -127 #bias
Commented [SYJ21]: add $s1, $zero, $t2 #make a copy beq $t0, $zero, end #check for negative sub $s1, $zero, $t2 #get 2s end: #2s complement of mantissa in $s1
CS2100
9. [8marks] # $s0 initialized to a user given value # $s1 initialized to 0 addi $t2, $zero, 0x1004 #I1 add $t0, $zero, $zero #I2 Loop: bne $t0, $zero, end #I3 slti $t3, $t2, 0x101C #I4 beq $t3, $zero, end #I5 lw $t1, -4($t2) #I6 bne $s0, $t1, lEnd #I7 addi $t0, $t0, 1 #I8 lw $s1, 0($t2) #I9 lEnd: addi $t2, $t2, 8 #I10 beq $zero, $zero, Loop #I11 end: .............. #irrelevant instruction not shown (a) Givetheinstructionencodinginhexadecimalforthebne $t0, $zero, end and slti $t3, $t2, 0x101C instructions.Opcodefor bne = 0x5,slti = 0xA and registers $t0 to $t7 == $810 to $1510. The register ordering for sltiissimilartolwduringencoding. [2marks] (b) GivetheALUSrcandRegDstsignalsforthesltiinstruction.
[2marks]
(c) Translate instructions #I3 to #I5 into high level programming language equivalent.Usetheregisternameasthevariablename. [2marks]
Commented [SYJ22]: bne 8, 0, 8 = 000101 01000 00000 0000000000001000 = 0001 0101 0000 0000 0000 0000 0000 1000 = 0x1500 0008 slti 10, 11, 0x101c #note ordering =001010 01010 01011 0001000000011100 =0010 1001 0100 1011 0001000000011100 =0x294B101C Commented [SYJ23]: ALUSrc = 1 (immediate value) RegDst = 0 (Rt) Commented [SYJ24]: while ($t0 == 0 AND $t2 < 0x101c)
(d)Giventhememorymap(addressandcontentinhexadecimal)ontheright,givethe resultin$s1 forthefollowingcases. i)
$s0is0x1004.[1mark]
ii)
$s0is0x102C.[1mark]
Page5of16
Address 0FFC16
Content 101816
100016
0FFC16
100416
101416
100816
100C16
100C16
102016
101016
100416
101416
102C16
101816
100816
101C16
100016
102016
101416
Commented [SYJ25]: This code is a {key,value} lookup table. -4($t2) is the key 0 ($t2) is the value $s1 = 0x102C Commented [SYJ26]: Key 0x102C cannot be found $s1 = 0
CS2100
10. [10marks] ThisquestionusesthesamecodefromQ9,reproducedbelowforyourconvenience. # $s0 initialized to a user given value # $s1 initialized to 0 addi $t2, $zero, 0x1004 #I1 add $t0, $zero, $zero #I2 Loop: bne $t0, $zero, end #I3 slti $t3, $t2, 0x101C #I4 beq $t3, $zero, end #I5 lw $t1, -4($t2) #I6 bne $s0, $t1, lEnd #I7 addi $t0, $t0, 1 #I8 lw $s1, 0($t2) #I9 lEnd: addi $t2, $t2, 8 #I10 beq $zero, $zero, Loop #I11 end: .............. #irrelevant instruction not shown Considerthefollowingexecutionscenario:
OneiterationfromInstructionsI1toI11 BranchesI3andI5arenottaken. BranchI7istaken.
Forthefollowingparts,totalnumberofcyclesincludesthecyclesneededforthelast instruction(I11)toreachwrite‐back(W)stage.
a) If there is no mechanism for handling data and control hazards, what is the total numberofcyclesneededbytheexecutionscenario? [2marks] b) Supposedataforwardingandearlybranchareused,answerthefollowing: i. InstructionI6isfetchedonwhichcycle? ii. Whatisthetotalcycleneededbytheexecutionscenario? [3marks] c) Supposedataforwardingandpredict‐takenbranchpredictionisusedwithoutearly branching,answerthefollowing: i. InstructionI6isfetchedonwhichcycle? ii. Whatisthetotalcycleneededbytheexecutionscenario? [3marks] d) Using the configuration in (c), what is the total cycle needed for the entire execution? The execution starts from I1 and eventually takes the branch at I5. RemembertoincludethecyclesneededforthelastI5toreachwrite‐backstage. [2marks] Page6of16
Commented [SYJ27]: See working and answers on page 13
CS2100
11. [9marks] Given below are two equivalent codes for modifying the elements of array A[]. The threearraysA[],B[]andC[]areall32‐bitintegerarrayswith64elements. VersionX:
VersionY:
for (i = 0; i < 64; i = i+2)
for (i = 0; i < 32; i = i+1) {
A[i] = B[i] + C[i];
j = i*2; A[j] = B[j] + C[j];
for (i = 1; i < 64; i = i+2)
A[j+1] = B[j+1] – C[j+1];
A[i] = B[i] - C[i]; }
Furthermore, we know that array A[] is allocated starting at 0x1000DDA0, B[] at 0x1000EE68andC[]at0x1000FF30.Attemptthefollowingquestionsassumingadirect‐ mappedcachewith4blocks,eachblockcontaining4words(eachwordis32‐bit). (a) GivethecacheindicesforthecacheblocksholdingB[0]andC[4]. [2marks] (b) IgnoringthewriteaccessesofA[],andconsideringonlythereadaccessesonB[] andC[],whatisthetotalcachemissesforcodeversionsXandY? [3marks] (c) We will now consider the impact of write accesses of A[]. Suppose the cache implements write‐allocate policy, what is the number of cold and conflict cache missesforcodeversionsXandY? [4marks]
Commented [SYJ28]: Cache Tag = 26 bits Cache Index = 2 bits Offset = 4 bits B[0] is at 0x1000EE68 0x6 = 0110 Index = 2 C[4] is at 0x1000FF30 + 4 x 4 = 0x1000FF40 0x4 = 0100 Index = 0
~~ENDOFPAPER~~~ (BlankK‐maps,partialstatetableandtimingchartsareprovidedinthenextthreepages.)
Page7of16
Commented [SYJ29]: See page 15 for working and answer. Commented [SYJ30]: See page 16 for working and answer.
CS2100
A
B
C
X
A+
B+
C+
0
0
0
0
0
0
1
0
0
0
1
1
0
0
0
1
0
0
1
0
0
1
1
0
0
1
0
0
0
1
0
0
1
1
0
1
1
TB
JC
KC
0
1
0
0
1
0
1
1
0
0
0
1
0
0
1
1
0
1
0
1
0
1
1
1
1
0
0
1
1
0
1
1
1
1
0
1
1
1
1
DA
C
DA
C
TB
B
A
B A
X
X
C
JC
C
KC
B
B
A
A
X
Page8of16
X
CS2100
Thispageisforyourroughwork.