You are on page 1of 7

TheAmericanUniversityinCairo DepartmentofComputerScienceandEngineering EENGR352/CSCE231 ComputerOrganizationandAssemblyProgramming FirstMidtermFall2010

Name:_______________________________________________ ID:__________________________________
Tips/Instructions: Totalexamtimeis70minutes. Noexternalaidsareallowed;theseinclude:friends,notes,books,textmessages,orthe Internet. Someproblemscanbesolvedinmultipleways.Onlyoneisrequired. Unclearanswersorunclearhandwritingwillreduceyourchances. Doyourbest!Youwillbegradedforyourunderstandingandthewayyouthinkofaproblem. BestofLuck!

October13,2010 CSCE231/EENGR352FirstMidterm

Question1(5Points)
JustlikewedefinedMIPSrating,wecanalsodefinesomethingcalledtheMFLOPSratingwhichstands forMillionsofFloatingPointoperationsperSecond.IfMachineAhasahigherMIPSratingthanthatof MachineB,thendoesMachineAnecessarilyhaveahigherMFLOPSratingincomparisontoMachineB? ANSWER AhigherMIPSratingformachineAcomparedtomachineBneednotimplyahigherMFLOPSratingfor thatmachineA.Onereasonforthiscanbethefollowing:Itispossiblethatthefloatingpoint instructionsformafairlylowproportionofthealltheinstructionsinagivenprogram.Soifthefloating pointoperationsofmachineBarefarmoreefficientthanthefloatingpointoperationsofmachineA whiletheother(integer,memoryetc)instructionsaremoreefficientonB,thenmachineBgetsahigher MFLOPSratingthanAwhileAhasahigherMIPSrating.

Page2of7

October13,2010 CSCE231/EENGR352FirstMidterm

Question2(15Points)
Considertwodifferentimplementations,M1andM2,ofthesameinstructionset.Therearethree classesofinstructions(A,B,andC)intheinstructionset.M1hasaclockrateof80MHzandM2hasa clockrateof100MHz.Theaveragenumberofcyclesforeachinstructionclassandtheirfrequencies(for atypicalprogram)areasfollows:
Instruction Class Machine M1 Instruction Class Machine M1 Cycles/Instruction Class A 1 B 2 C 4 Machine M2 Machine M2 Cycles/Instruction Class 2 3 4 Frequency 60% 30% 10%

(a) CalculatetheaverageCPIforeachmachine,M1,andM2. ANSWER

ForMachineM1:ClocksperInstruction=(60/100)*1+(30/100)*2+(10/100)*4=1.6 ForMachineM2:ClocksperInstruction=(60/100)*2+(30/100)*3+(10/100)*4=2.5
(b) CalculatetheaverageMIPSratingsforeachmachine,M1andM2. ANSWER

ForMachineM1:AverageMIPSrating=ClockRate/(CPI*106)=(80*106)/(1.6*106)=50.0 ForMachineM2:AverageMIPSrating=ClockRate/(CPI*106)=(100*106)/(2.5*106)=40.0
(c) WhichmachinehasasmallerMIPSrating?WhichindividualinstructionclassCPIdoyouneedto change,andbyhowmuch,tohavethismachinehavethesameorbetterperformanceasthe machinewiththehigherMIPSrating(youcanonlychangetheCPIforoneoftheinstructionclasses ontheslowermachine)? ANSWER

MachineM2hasasmallerMIPSrating.IfwechangetheCPIofinstructionclassAforMachineM2to1, wecanhaveabetterMIPSratingthanM1asfollows: ClocksperInstruction=(60/100)*1+(30/100)*3+(10/100)*4=1.9 AverageMIPSrating=ClockRate/(CPI*106)=(100*106)/(1.9*106)=52.6

Page3of7

October13,2010 CSCE231/EENGR352FirstMidterm

Question3(10Points)
(Amdahlslawquestion)Supposeyouhaveamachinewhichexecutesaprogramconsistingof50% floatingpointmultiply,20%floatingpointdivide,andtheremaining30%arefromotherinstructions.
(a) Managementwantsthemachinetorun4timesfaster.Youcanmakethedividerunatmost3times fasterandthemultiplyrunatmost8timesfaster.Canyoumeetmanagementsgoalbymakingonly oneimprovement,andwhichone? ANSWER

AmdahlsLawstates:Executiontimeafterimprovement=(Executiontimeaffectedby improvement)/(AmountofImprovement)+Executiontimeunaffected Assuminginitiallythatthefloatingpointmultiply,floatingpointdivideandtheotherinstructionshad thesameCPI,ExecutiontimeafterImprovementwithDivide=(20)/3+(50+30)=86.67 ExecutiontimeafterImprovementwithMultiply=(50)/8+(20+30)=66.67 ThemanagementsgoalcannotbemetbymakingtheimprovementwithMultiplyalone.

(b) Dogberthasnowtakenoverthecompanyremovingallthepreviousmanagers.Ifyoumakeboththe multiplyanddivideimprovements,whatisthespeedoftheimprovedmachinerelativetothe originalmachine? ANSWER Ifwemakeboththeimprovements, ExecutiontimeafterImprovement=(50)/8+(20)/3+(30)=53.33 Thespeeduprelativetotheoriginalmachine=(100)/(53.33)=1.88

Page4of7

October13,2010 CSCE231/EENGR352FirstMidterm

Question4(10Points)
InMIPSassembly,writeanassemblylanguageversionofthefollowingCcodesegment:
int A[100], B[100]; for (i=1; i < 100; i++) { A[i] = A[i-1] + B[i]; }

Atthebeginningofthiscodesegment,theonlyvaluesinregistersarethebaseaddressofarraysA andB inregisters$a0 and$a1.Avoidtheuseofmultiplicationinstructionstheyareunnecessary. ANSWER TheMIPSassemblysequenceisasfollows: li $t0, 1 # Starting index of i li $t5, 100 # Loop bound loop: lw $t1, 0($a1) # Load A[i-1] lw $t2, 4($a2) # Load B[i] add $t3, $t1, $t2 # A[i-1] + B[i] sw $t3, 4($a1) # A[i] = A[i-1] + B[i] addi $a1, 4 # Go to i+1 addi $a2, 4 # Go to i+1 addi $t0, 1 # Increment index variable bne $t0, $t5, loop # Compare with Loop Bound halt:

Page5of7

October13,2010 CSCE231/EENGR352FirstMidterm

Question5(15Points)
SupposethatanewMIPSinstruction,calledbcp,wasdesignedtocopyablockofwordsfromone addresstoanother.Assumethatthisinstructionrequiresthatthestartingaddressofthesourceblock beinregister$t1 andthatthedestinationaddressbein$t2.Theinstructionalsorequiresthatthe numberofwordstocopybein$t3 (whichis>0).Furthermore,assumethatthevaluesoftheseregisters aswellasregister$t4 canbedestroyedinexecutingthisinstruction(sothattheregisterscanbeusedas temporariestoexecutetheinstruction). Dothefollowing:WritetheMIPSassemblycodetoimplementablockcopywithoutthisinstruction. WritetheMIPSassemblycodetoimplementablockcopywiththisinstruction.Estimatethetotalcycles necessaryforeachrealizationtocopy100wordsonthemulticyclemachine(assumingthatany instructionwilltakeonlyonecycletoexecute). ANSWER TheMIPScodetoimplementblockcopywithoutthebcpinstructionisasfollows: loop: lw $t4, 0($t1) sw $t4, 0($t2) addi $t1, $t1, 4 addi $t2, $t2, 4 subi $t3, $t3, 1 bne $t3, $zero, loop Toimplementblockcopywiththisinstruction: li $t1, src li $t2, dst li $t3, count bcp AssumingeachinstructionintheMIPScodeoflooptakes1cycle,fordoinga100wordcopythetotal numberofcyclestakenis6*100=600cycles.

Page6of7

October13,2010 CSCE231/EENGR352FirstMidterm

Question6(BONUS7Points)
InMIPSassembly,writeanassemblylanguageversionofthefollowingCcodesegment:
for (i = 0; i < 98; i ++) { C[i] = A[i + 1] - A[i] * B[i + 2] }

ArraysA,BandCstartatmemorylocationA000hex,B000hex andC000hex respectively.Trytoreduce thetotalnumberofinstructionsandthenumberofexpensiveinstructionssuchasmultiplies. ANSWER TheMIPSassemblysequenceisasfollows: li $s0, 0xA000 # Load Address of A li $s1, 0xB000 # Load Address of B li $s2, 0xC000 # Load Address of C li $t0, 0 # Starting index of i li $t5, 98 # Loop bound loop: lw $t1, 0($s1) # Load A[i] lw $t2, 8($s2) # Load B[i+2] mul $t3, $t1, $t2 # A[i] * B[i+2] lw $t1, 4($s1) # Load A[i+1] add $t2, $t1, $t3 # A[i+1] + A[i]*B[i+2] sw $t2, 4($s3) # C[i] = A[i+1] + A[i]*B[i+2] addi $s1, 4 # Go to A[i+1] addi $s2, 4 # Go to B[i+1] addi $s3, 4 # Go to C[i+1] addi $t0, 1 # Increment index variable bne $t0, $t5, loop # Compare with Loop Bound halt:

Page7of7

You might also like