mips assembly: practice questions for midterm 1 saving to ... · practice questions for midterm 1...
Post on 27-Jan-2020
12 Views
Preview:
TRANSCRIPT
MIPSAssembly:PracticeQuestionsforMidterm1
SavingtoandLoadingfromMemory
CS64:ComputerOrganizationandDesignLogicLecture#6
ZiadMatni
Dept.ofComputerScience,UCSB
• Tuesday,4/24inthisclassroom• Startsat11:00AM**SHARP**
– Pleasestartarriving5-10minutesbeforeclass
• Imayaskyoutochangeseats• PleasebringyourUCSBIDswithyou
• Closedbook:nocalculators,nophones,nocomputers• OnlytheMIPSReferenceCardisallowed• Youwillwriteyouranswersontheexamsheetitself.
4/19/18 Matni,CS64,Wi18 2
What’sontheMidterm??1/2• DataRepresentation
– Convertbinßàhexßàdecimalßàbin– Signedandunsignedbinaries
• LogicandArithmetic– Binaryaddition,subtraction
• CarryandOverflow– BitwiseAND,OR,NOT,XOR– GeneralrulesofAND,OR,XOR,usingNORasNOT
• Alldemosdoneinclass• Labassignments1and2
4/19/18 Matni,CS64,Wi18 3
What’sontheMidterm??2/2Assembly• CorecomponentsofaCPU
– Howinstructionswork• Registers($t,$s,$a,$v)• Arithmeticinassembly(add,subtract,multiply,divide)
– What’sthedifferencebetweenadd,addi,addu,addui,etc…• Conditionalsandloopsinassembly• ConversiontoandfromAssemblyandC/C++• syscallanditsvarioususes(printingoutput,takinginput,ending
program)• .dataand.textdeclarations• MemoryinMIPS• BigEndianvsLittleEndian4/19/18 Matni,CS64,Wi18 4
ReviewQuestions
• IwillputupreviewquestionsforMidterm#1upontheclasswebsite– Laterontoday…
4/19/18 Matni,CS64,Sp18 5
AbouttheMidtermExam• MadeupofMultipleChoice&ShortAnswers/Coding.EXAMPLES:
4/19/18 Matni,CS64,Sp18 6
CompletethefollowingMIPSassemblycodethatissupposedtoaddthenumberinregister$t0to15:
li$t0,12_____________
A. add$t2,$t1,$t2B. addu$t2,$t1,$t2C. addi$t2,$t0,FD. addi$t2,$t0,0xFE. addui$t2,$t0,0xF
Whatisthe2’scomplementof0x5EC?
A. 1x5ECB. 0x5ECC. 0xA13D. 0xA14E. 0xA15
SampleQuestions
TranslatethisC-stylecodeinto4linesofMIPSassemblycode:intt1=10,t2=3;intt3=t1+2*t2
Whatistheresultoftheseoperations?0xF2&~(0x55)0x102A99D8^0xABA11CAB
4/19/18 Matni,CS64,Sp18 7
li$t1,10li$t2,3sll$t2,$t2,1add$t3,$t2,$t1
0xA2
00010000001010101001100111011000^10101011101000010001110010101011=10111011100010111000010101110011=0xBB8B8573
SampleQuestionsTranslatethisMIPSassemblycodeintopseudo-code(CorC++accepted):li$s0,2li$s1,6li$t0,2add$s2,$s1,$s0sll$s2,$s2,3mult$s2,$t0mflo$s34/19/18 Matni,CS64,Sp18 8
ints0=2,s1=6,t0=2;ints2=s1+s0;s2*=8;ints3=s2*t0;
SampleQuestions
4/19/18 Matni,CS64,Sp18 9
.textmain:li$t0,3li$t2,7slt$t3,$t0,$t2beq$t3,$zero,elseadd$t1,t0,$t2;jend
else:add$t1,$t0,$t0
end:li$v0,10syscall
TranslatethisC++codeintoMIPS(justthe.textpart)intt0=3;if(t0<7)t1=7+t0;
elset1=t0+t0;
LargerDataStructures
• Recall:registersvs.memory– Wherewoulddatastructures,arrays,etc.go?– Whichisfastertoaccess?Why?
• Somedatastructureshavetobestoredinmemory– Soweneedinstructionsthat“shuttle”datato/fromtheCPUandcomputermemory(RAM)
4/19/18 Matni,CS64,Sp18 11
AccessingMemory• Twobaseinstructions:– load-word(lw)frommemorytoregisters– store-word(sw)fromregisterstomemory
• MIPSlacksinstructionsthatdomorewithmemorythanaccessit(e.g.,retrievesomethingfrommemoryandthenadd)– Operationsaredonestep-by-step– MarkofRISCarchitecture
4/19/18 Matni,CS64,Sp18 12
MemoryRs
lw
sw
4/19/18 Matni,CS64,Sp18 13
.datanum1:.word42num2:.word7num3:.space1.textmain:
lw$t0,num1lw$t1,num2add$t2,$t0,$t1sw$t2,num3li$v0,1lw$a0,num3syscall
li$v0,10syscall
Example4Whatdoesthisdo?
MemoryRs
lw
sw
AddressingMemory• Ifyou’renotusingthe.datadeclarations,thenyouneedstarting
addressesofthedatainmemorywithlwandswinstructionsExample: lw$t0,0x0000400A (ßnotarealaddress)Example: lw$t0,0x0000400A($s0)(ßnotarealaddress)
• 1word=32bits(inMIPS)– So,ina32-bitunitofmemory,that’s4bytes– Representedwith8hexadecimals 8x4bits=32bits…checksout…
• MIPSaddressessequentialmemoryaddresses,butnotin“words”– AddressesareinBytesinstead– MIPSwordsmuststartataddressesthataremultiplesof4– Calledanalignmentrestriction
4/19/18 Matni,CS64,Sp18 14
4/19/18 Matni,CS64,Sp18 15
ThisisfoundonyourMIPSReferenceCard
NOTE:Notallmemoryaddressescanbeaccessedbytheprogrammer.Althoughtheaddressspaceis32bits,thetopaddressesfrom0x80000000to0xFFFFFFFFarenotavailabletouserprograms.TheyareusedmostlybytheOS.
Howmuchmemorydoesaprogrammergettodirectly
useinMIPS?
MemoryAllocationMap
MappingMIPSMemory(saythat10timesfast!)
• Imaginecomputermemorylikeabigarrayofwords• Sizeofcomputermemoryis:
232=4Gbits,or512MBytes(MB)– Weonlygettouse2Gbits,or256MB– That’s(256MB/groupsof4B)=64millionwords
4/19/18 Matni,CS64,Sp18 16
8bits 8bits 8bits 8bitsword
MIPSComputerMemoryAddressingConventions
4/19/18 Matni,CS64,Sp18 17
1A 80 C5 29
52 00 37 EE
B1 11 1A A5
0x00000x00010x00020x00030x00040x00050x00060x00070x00080x00090x000A0x000B
Aàà
MIPSComputerMemoryAddressingConventions
4/19/18 Matni,CS64,Sp18 18
1A 80 C5 29
52 00 37 EE
B1 11 1A A5
0x00030x00020x00010x00000x00070x00060x00050x00040x000B0x000A0x00090x0008
Bßß
or...
ATaleof2Conventions…
4/19/18 Matni,CS64,Sp18 19
BIGEND(MSByte)getsaddressedfirst
LITTLEEND(LSByte)getsaddressedfirst
TheUseofBigEndianvs.LittleEndian
Origin:JonathanSwift(author)in“Gulliver'sTravels”.Somepeoplepreferredtoeattheirhardboiledeggsfromthe“little
end”first(thus,littleendians),whileothersprefertoeatfromthe“bigend”(i.e.bigendians).
• MIPSuserstypicallygowithBigEndianconvention– MIPSallowsyoutoprogram“endian-ness”
• MostIntelprocessorsgowithLittleEndian…
• It’sjustaconvention–itmakesnodifferencetoaCPU!
4/19/18 Matni,CS64,Sp18 20
YOURTO-DOs
• Finishassignment/Lab#2– AssignmentdueonFRIDAY
• Studyforyourmidterm!!J
• Relaxalittle
4/19/18 Matni,CS64,Sp18 21
top related