cs33-7
58 Pages

cs33-7

Course Number: EL ENGR 2, Spring 2013

College/University: UCLA

Word Count: 2497

Rating:

Document Preview

Machine-Level Programming: Procedures Chapter3ofB&O SomenotesadoptedfromBryantandOHallaron IA32 Stack Regionofmemory managedwithstack discipline Growstowardlower addresses Register%esp indicates loweststackaddress addressoftopelement Stack Pointer %esp Stack Bottom Increasing Addresses Stack Grows Down Stack Top IA32 Stack Pushing Pushing Stack Bottom pushl Src FetchoperandatSrc Decrement%esp...

Unformatted Document Excerpt
Coursehero >> California >> UCLA >> EL ENGR 2

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Programming: Procedures Chapter3ofB&O SomenotesadoptedfromBryantandOHallaron IA32 Machine-Level Stack Regionofmemory managedwithstack discipline Growstowardlower addresses Register%esp indicates loweststackaddress addressoftopelement Stack Pointer %esp Stack Bottom Increasing Addresses Stack Grows Down Stack Top IA32 Stack Pushing Pushing Stack Bottom pushl Src FetchoperandatSrc Decrement%esp by4 Writeoperandat addressgivenby%esp Increasing Addresses Stack Pointer %esp Stack Grows Down -4 Stack Top IA32 Stack Popping Popping Stack Bottom popl Dest Readoperandat addressgivenby%esp Increment%esp by4 WritetoDest Increasing Addresses Stack Pointer %esp Stack Grows Down +4 Stack Top Procedure Control Flow Usestacktosupportprocedurecallandreturn Procedurecall: calllabel:Pushreturnaddressonstack;Jumptolabel Returnaddressvalue Addressofinstructionbeyondcall Examplefromdisassembly 804854e: e83d060000 call8048b90<main> 8048553: 50 pushl%eax Returnaddress=0x8048553 Procedurereturn: ret Popaddressfromstack;Jumptoaddress Procedure Call Example 804854e: 8048553: e8 3d 06 00 00 50 call 0x110 8048b90 0x110 0x10c call pushl 0x10c 0x108 123 0x108 123 0x104 0x8048553 %esp 0x108 %esp %eip 0x804854e 0x104 0x108 %eip 0x804854e 0x8048b90 %eip is program counter 8048b90 <main> %eax Procedure Return Example 8048591: c3 ret ret 0x110 0x110 0x10c 0x10c 0x108 123 0x108 0x104 0x8048553 %esp 0x104 %eip 0x8048591 %eip is program counter 123 0x8048553 %esp 0x108 0x104 %eip 0x8048591 0x8048553 Stack-Based Languages LanguagesthatSupportRecursion e.g.,C,Pascal,Java CodemustbeReentrant Multiplesimultaneousinstantiationsofsingleprocedure Needsomeplacetostorestateofeachinstantiation Arguments Localvariables Returnpointer StackDiscipline Stateforgivenprocedureneededforlimitedtime Fromwhencalledtowhenreturn Calleereturnsbeforecallerdoes StackAllocatedinFrames stateforsingleprocedureinstantiation Call Chain Example CodeStructure yoo() { who(); } Call Chain yoo who() { amI(); amI(); } ProcedureamI recursive who amI amI() { amI(); } amI amI amI Stack Frames Contents Localvariables Returninformation Temporaryspace yoo who amI Management Spaceallocatedwhenenter procedure Setupcode Previous Frame Deallocatedwhenreturn Finishcode Pointers Stackpointer %esp indicates stacktop Framepointer%ebp indicates startofcurrentframe Frame Pointer %ebp proc Stack Pointer %esp Stack Top yoo() { who(); } Call Chain yoo Frame Pointer %ebp yoo Stack Pointer %esp who() { amI(); amI(); } Call Chain yoo Frame Pointer %ebp yoo who who Stack Pointer %esp amI() { amI(); } Call Chain yoo yoo who amI Frame Pointer %ebp who amI Stack Pointer %esp amI() { amI(); } Call Chain yoo yoo who who amI amI Frame Pointer %ebp amI amI Stack Pointer %esp amI() { amI(); } Call Chain yoo yoo who who amI amI amI amI Frame Pointer %ebp amI amI Stack Pointer %esp amI() { amI(); } Call Chain yoo yoo who who amI amI Frame Pointer %ebp amI amI amI Stack Pointer %esp amI() { amI(); } Call Chain yoo yoo who amI amI amI Frame Pointer %ebp who amI Stack Pointer %esp who() { amI(); amI(); } Call Chain yoo Frame Pointer %ebp yoo who who amI amI amI Stack Pointer %esp amI() { } Call Chain yoo yoo Frame Pointer %ebp who amI amI amI amI who amI Stack Pointer %esp who() { amI(); amI(); } Call Chain Frame Pointer %ebp yoo yoo who who amI amI amI amI Stack Pointer %esp Call Chain yoo() { who(); } who amI amI yoo Stack Pointer %esp yoo amI Frame Pointer %ebp amI IA32/Linux Stack Frame CurrentStackFrame (ToptoBottom) Parametersforfunction abouttocall Argumentbuild Localvariables Caller Frame Arguments Frame Pointer (%ebp) Ifcantkeepinregisters Saved Registers + Local Variables Savedregistercontext Oldframepointer CallerStackFrame Returnaddress Pushedbycall instruction Argumentsforthiscall Return Addr Old %ebp Stack Pointer (%esp) Argument Build Revisiting swap Calling swap from call_swap int zip1 = 15213; int zip2 = 91125; void call_swap() { swap(&zip1, &zip2); } void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } call_swap: pushl $zip2 pushl $zip1 call swap # Global Var # Global Var Resulting Stack &zip2 &zip1 Rtn adr %esp Revisiting swap void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } swap: pushl %ebp movl %esp,%ebp pushl %ebx movl movl movl movl movl movl 12(%ebp),%ecx 8(%ebp),%edx (%ecx),%eax (%edx),%ebx %eax,(%edx) %ebx,(%ecx) movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret Set Up Body Finish swap Setup #1 Resulting Stack Entering Stack %ebp %ebp &zip2 yp &zip1 xp Rtn adr %esp Rtn adr Old %ebp swap: pushl %ebp movl %esp,%ebp pushl %ebx %esp swap Setup #2 Resulting Stack Entering Stack %ebp &zip2 yp &zip1 xp Rtn adr %esp Rtn adr Old %ebp %ebp %esp swap: pushl %ebp movl %esp,%ebp pushl %ebx swap Setup #3 Resulting Stack Entering Stack %ebp &zip2 yp &zip1 xp Rtn adr %esp Rtn adr Old %ebp Old %ebx swap: pushl %ebp movl %esp,%ebp pushl %ebx %ebp %esp Effect of swap Setup Entering Stack Resulting Stack %ebp Offset (relative to %ebp) &zip2 12 yp &zip1 8 xp 4 Rtn adr Rtn adr %esp 0 Old %ebp Old %ebx movl 12(%ebp),%ecx # get yp movl 8(%ebp),%edx # get xp ... %ebp %esp Body swap Finish #1 swaps Stack Offset Offset 12 yp 12 yp 8 xp 8 xp 4 Rtn adr 4 Rtn adr 0 Old %ebp %ebp 0 Old %ebp %ebp -4 Old %ebx %esp -4 Old %ebx %esp Observation Saved&restoredregister%ebx movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret swap Finish #2 swaps Stack Offset swaps Stack Offset 12 yp 12 yp 8 xp 8 xp 4 Rtn adr 4 Rtn adr 0 Old %ebp %ebp -4 Old %ebx %esp 0 Old %ebp %ebp %esp movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret swap Finish #3 swaps Stack Offset swaps Stack %ebp Offset 12 yp 12 yp 8 xp 8 xp 4 Rtn adr 4 Rtn adr 0 Old %ebp %esp %ebp %esp movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret swap Finish #4 swaps Stack %ebp %ebp 12 yp &zip2 8 xp &zip1 4 Rtn adr Offset Exiting Stack %esp %esp Observation movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret Saved&restoredregister%ebx Didntdosofor%eax,%ecx,or%edx Register Saving Conventions Whenprocedureyoo callswho: yoo isthecaller,who isthecallee CanRegistersbeUsedforTemporaryStorage? yoo: movl $15213, %edx call who addl %edx, %eax ret who: movl 8(%ebp), %edx addl $91125, %edx ret Contentsofregister%edx overwrittenbywho Register Saving Conventions Whenprocedureyoo callswho: yoo isthecaller,who isthecallee CanRegistersbeUsedforTemporaryStorage? Conventions CallerSave Callersavestemporaryinitsframebeforecalling Callee Save Callee savestemporaryinitsframebeforeusing IA32/Linux Register Usage IntegerRegisters Twohavespecialuses %ebp,%esp Threemanagedascallee save %ebx,%esi,%edi Oldvaluessavedonstack priortousing Threemanagedascaller save %eax,%edx,%ecx Dowhatyouplease,but expectanycalleetodoso, aswell Register%eax also storesreturnedvalue %eax Caller-Save Temporaries %edx %ecx %ebx Callee-Save Temporaries %esi %edi Special %esp %ebp Recursive Factorial int rfact(int x) { int rval; if (x <= 1) return 1; rval = rfact(x-1); return rval * x; } Registers %eax usedwithoutfirst saving %ebx used,butsaveat beginning&restoreat end .globl rfact .type rfact,@function rfact: pushl %ebp movl %esp,%ebp pushl %ebx movl 8(%ebp),%ebx cmpl $1,%ebx jle .L78 leal -1(%ebx),%eax pushl %eax call rfact imull %ebx,%eax jmp .L79 .align 4 .L78: movl $1,%eax .L79: movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret Rfact Stack Setup pre %ebp Caller %ebp pre Stack x Rtn %ebx Entering adr %esp rfact: rfact: pushl %ebp movl %esp,%ebp pushl %ebx pre %ebp Caller pre %ebx 8 4 Callee x Rtn adr 0 Old %ebp %ebp -4 Old %ebx %esp Rfact Body Recursion movl 8(%ebp),%ebx cmpl $1,%ebx jle .L78 leal -1(%ebx),%eax pushl %eax call rfact imull %ebx,%eax jmp .L79 .L78: # movl $1,%eax .L79: # int rfact(int x) { int rval; if (x <= 1) return 1; rval = rfact(x-1) ; return rval * x; } # ebx = x # Compare x : 1 # If <= goto Term # eax = x-1 # Push x-1 # rfact(x-1) # rval * x # Goto done Term: # return val = 1 Done: Registers %ebx %eax Storedvalueofx Temporaryvalueof x-1 Returnedvaluefrom rfact(x-1) Returnedvaluefromthiscall Rfact Recursion leal -1(%ebx),%eax pushl %eax x Rtn adr x Old %ebp %ebp Old %ebx %esp Rtn adr Old %ebp call rfact %ebp Old %ebx x-1 %eax x Rtn adr %esp Old %ebp %ebp Old %ebx x-1 %ebx x %eax %ebx x-1 x-1 Rtn adr x %eax x-1 %ebx x %esp Rfact Result Return from Call imull %ebx,%eax x x Rtn adr Rtn adr Old %ebp Old %ebp %ebp Old %ebx x-1 %ebp Old %ebx x-1 %esp %eax (x-1)! %eax (x-1)! x! %ebx x %ebx x Assume that rfact(x-1) returns (x-1)! in register %eax %esp Rfact Completion movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret pre %ebp pre %ebx 8 x 4 Rtn adr 0 Old %ebp pre %ebp x-1 pre %ebp 8 -4 Old %ebx -8 pre %ebx x pre %ebx 4 Rtn adr x %ebp %esp 0 Old %ebp %eax x! %ebx Old x ebx % %eax %ebp %esp Rtn adr x! %ebx Old %ebx %eax x! %ebx Old %ebx %ebp %esp Pointer Code Recursive Procedure void s_helper (int x, int *accum) { if (x <= 1) return; else { int z = *accum * x; *accum = z; s_helper (x-1,accum); } } Top-Level Call int sfact(int x) { int val = 1; s_helper(x, &val); return val; } Passpointertoupdatelocation Creating & Initializing Pointer Initial part of sfact _sfact: pushl %ebp movl %esp,%ebp subl $16,%esp movl movl 8(%ebp),%edx movl $1,-4(%ebp) # # # # # Save %ebp Set %ebp Add 16 bytes edx = x val = 1 UsingStackforLocalVariable Variableval mustbestored onstack Needtocreatepointertoit Computepointeras4(%ebp) Pushonstackassecond argument 8 x 4 Rtn adr 0 Old %ebp %ebp -4 val = 1 -8 -12 Temp. Space Unused -16 int sfact(int x) { int val = 1; s_helper(x, &val); return val; } %esp Passing Pointer Calling s_helper from sfact leal -4(%ebp),%eax pushl %eax pushl %edx call s_helper movl -4(%ebp),%eax # # # # # # Compute &val Push on stack Push x call Return val Finish Stack at time of call 8 x 4 Rtn adr 0 Old %ebp -4 val = 1 val =x! -8 -12 int sfact(int x) { int val = 1; s_helper(x, &val); return val; } %ebp Unused -16 &val x %esp Using Pointer void s_helper (int x, int *accum) { int z = *accum * x; *accum = z; } accum*x accum %eax accum*x x %ecx x movl %ecx,%eax #z=x imull (%edx),%eax # z *= *accum movl %eax,(%edx) # *accum = z Register%ecx holdsx Register%edx holdspointertoaccum Useaccess(%edx) toreferencememory %edx Summary TheStackMakesRecursionWork Privatestorageforeachinstance ofprocedurecall Instantiationsdontclobbereachother Addressingoflocals+argumentscanberelativetostackpositions Canbemanagedbystackdiscipline Proceduresreturnininverseorderofcalls IA32ProceduresCombinationofInstructions+ Conventions Call/Retinstructions Registerusageconventions Caller/Calleesave %ebp and%esp Stackframeorganizationconventions x86-64 Integer Registers %rax %eax %r8 %r8d %rbx %ebx %r9 %r9d %rcx %ecx %r10 %r10d %rdx %edx %r11 %r11d %rsi %esi %r12 %r12d %rdi %edi %r13 %r13d %rsp %esp %r14 %r14d %rbp %ebp %r15 %r15d Twicethenumberofregisters Accessibleas8,16,32,64bits x86-64 Integer Registers %rax Returnvalue %r8 Argument#5 %rbx Callee saved %r9 Argument#6 %rcx Argument#4 %r10 Callee saved %rdx Argument#3 %rsi Argument#2 %r12 C:Callee saved %rdi Argument#1 %r13 Callee saved %rsp Stackpointer %r14 Callee saved %rbp Callee saved %r15 Callee saved Usedforlinking %r11 x86-64 Registers Argumentspassedtofunctionsviaregisters Ifmorethan6integralparameters,thenpassreston stack Theseregisterscanbeusedascallersavedaswell Allreferencestostackframeviastackpointer Eliminatesneedtoupdate%ebp/%rbp OtherRegisters 6+1callee saved 2or3havespecialuses x86-64 Long Swap void swap(long *xp, long *yp) { long t0 = *xp; long t1 = *yp; *xp = t1; *yp = t0; } swap: movq movq movq movq ret (%rdi), %rdx (%rsi), %rax %rax, (%rdi) %rdx, (%rsi) Operandspassedinregisters First(xp)in%rdi,second(yp)in%rsi 64bitpointers Nostackoperationsrequired(exceptret) Avoidingstack Canholdalllocalinformationinregisters x86-64 Locals in the Red Zone /* Swap, using local array */ void swap_a(long *xp, long *yp) { volatile long loc[2]; loc[0] = *xp; loc[1] = *yp; *xp = loc[1]; *yp = loc[0]; } AvoidingStackPointer Change Canholdallinformation withinsmallwindow beyondstackpointer swap_a: movq movq movq movq movq movq movq movq ret (%rdi), %rax %rax, -24(%rsp) (%rsi), %rax %rax, -16(%rsp) -16(%rsp), %rax %rax, (%rdi) -24(%rsp), %rax %rax, (%rsi) rtn Ptr 8 unused 16 loc[1] 24 loc[0] %rsp x86-64 NonLeaf without Stack Frame long scount = 0; /* Swap a[i] & a[i+1] */ void swap_ele_se (long a[], int i) { swap(&a[i], &a[i+1]); scount++; } Novaluesheldwhileswap beinginvoked Nocallee saveregisters needed swap_ele_se: movslq %esi,%rsi # Sign extend i leaq (%rdi,%rsi,8), %rdi # &a[i] leaq 8(%rdi), %rsi # &a[i+1] call swap # swap() incq scount(%rip) # scount++; ret x86-64 Call using Jump long scount = 0; /* Swap a[i] & a[i+1] */ void swap_ele(long a[], int i) { swap(&a[i], &a[i+1]); } Whenswap executesret,it willreturnfromswap_ele Possiblesinceswap isa tailcall (noinstructionsafterwards) swap_ele: movslq %esi,%rsi # Sign extend i leaq (%rdi,%rsi,8), %rdi # &a[i] leaq 8(%rdi), %rsi # &a[i+1] jmp swap # swap() x86-64 Stack Frame Example long sum = 0; /* Swap a[i] & a[i+1] */ void swap_ele_su (long a[], int i) { swap(&a[i], &a[i+1]); sum += a[i]; } Keepsvaluesofa andi in callee saveregisters Mustsetupstackframeto savetheseregisters swap_ele_su: movq %rbx, -16(%rsp) movslq %esi,%rbx movq %r12, -8(%rsp) movq %rdi, %r12 leaq (%rdi,%rbx,8), %rdi subq $16, %rsp leaq 8(%rdi), %rsi call swap movq (%r12,%rbx,8), %rax addq %rax, sum(%rip) movq (%rsp), %rbx movq 8(%rsp), %r12 addq $16, %rsp ret Understanding x86-64 Stack Frame swap_ele_su: movq %rbx, -16(%rsp) movslq %esi,%rbx movq %r12, -8(%rsp) movq %rdi, %r12 leaq (%rdi,%rbx,8), %rdi subq $16, %rsp leaq 8(%rdi), %rsi call swap movq (%r12,%rbx,8), %rax addq %rax, sum(%rip) movq (%rsp), %rbx movq 8(%rsp), %r12 addq $16, %rsp ret # # # # # # # # # # # # # Save %rbx Extend & save i Save %r12 Save a &a[i] Allocate stack frame &a[i+1] swap() a[i] sum += a[i] Restore %rbx Restore %r12 Deallocate stack frame Understanding x86-64 Stack Frame swap_ele_su: movq %rbx, -16(%rsp) movslq %esi,%rbx movq %r12, -8(%rsp) movq %rdi, %r12 leaq (%rdi,%rbx,8), %rdi subq $16, %rsp leaq 8(%rdi), %rsi call swap movq (%r12,%rbx,8), %rax addq %rax, sum(%rip) movq (%rsp), %rbx movq 8(%rsp), %r12 addq $16, %rsp ret # # # # # # # # # # # # # Save %rbx %rsp rtn addr Extend & save i 8 %r12 Save %r12 %rbx 16 Save a &a[i] Allocate stack frame &a[i+1] rtn addr swap() +8 %r12 a[i] sum += a[i] %rsp %rbx Restore %rbx Restore %r12 Deallocate stack frame Interesting Features of Stack Frame Allocateentireframeatonce Allstackaccessescanberelativeto%rsp Dobydecrementingstackpointer Candelayallocation,sincesafetotemporarilyusered zone Simpledeallocation Incrementstackpointer Nobase/framepointerneeded x86-64 Procedure Summary Heavyuseofregisters Parameterpassing Moretemporariessincemoreregisters Minimaluseofstack Sometimesnone Allocate/deallocate entireblock Manytrickyoptimizations Whatkindofstackframetouse Callingwithjump Variousallocationtechniques

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Texas - GEO - 301
). The universe seems centered on us and so the reason for it existing must be us, top of the food chain, significant almost beyond measure. Guess who came up with that idea? The history of astronomy parallels one of the great stories of western civi
Institute of Technology - ELECTRICAL - 124
ne based). However, this is likely one of the cases where the pragmatic approach of cable manufacturers achieved faster results than research: reasonable cable reliability even in wet environment was obtained, in fact, using an outer metallic shield,
Binghamton - HWS - 332
no. 8 (1885): 228.5 &quot;Society Proceedings: New York State Medical Association,&quot; Medical News, 46, no. 10(1885): 269.4procedure to remove a tumor in the patient's thigh. He remarked, &quot;the operation was byno means a painless one.&quot;6 Large-scale m
Ithaca College - MATH - 185
ce that of 5. This idea of factoring applies to all triples. This rulealone proves that there are infinitely many Pythagorean Triples; there are infinitelymany numbers, thus factors, thus Triples.(3) When dealing with basictriples it is necessar
UCLA - EL ENGR - 2
Code Optimization I:Machine Independent OptimizationsChapter5ofB&amp;OSomenotesadoptedfromBryantandOHallaronGreat Reality #4Theresmoretoperformancethanasymptoticcomplexity Constantfactorsmattertoo! Easilysee10:1performancerangedependingonhowcodeiswrit
UCLA - EL ENGR - 2
Machine-Level Programming:Structured DataChapter3ofB&amp;OSomenotesadoptedfromBryantandOHallaronBasic Data Types Integral Stored&amp;operatedoningeneralregisters Signedvs.unsigneddependsoninstructionsusedIntelbyteworddoublewordquadwordGASbwlqByt
UCLA - EL ENGR - 2
Machine-Level Programming:Miscellaneous TopicsChapter3ofB&amp;OSomenotesadoptedfromBryantandOHallaronIA32 Linux Memory Layout StackFF Runtimestack(8MBlimit)notdrawntoscaleStack8MB Heap Dynamicallyallocatedstorage Whencallmalloc(), calloc(), new()
UCLA - EL ENGR - 2
Machine-Level Programming:IntroductionChapter3ofB&amp;OSomenotesadoptedfromBryantandOHallaronIA32 Processors EvolutionaryDesign Startingin1978with8086 Addedmorefeaturesastimegoeson Stillsupportoldfeatures,althoughobsolete ComplexInstructionSetCompute
UCLA - EL ENGR - 2
UNIVERSITY OF CALIFORNIA, LOS ANGELESBERKELEYDAVISIRVINELOS ANGELESRIVERSIDEUCLASAN DIEGOSAN FRANCISCOSANTA BARBARASANTA CRUZCS 33Midterm #2All answers must be written on the answer sheet (last page of the exam).All work should be written di
UCLA - EL ENGR - 2
CS33Spring2013Lab5:CUDAIntroductionInthislabassignment,youwillimprovetheperformanceoftheedgedetectioncodefromLab4bytranslatingpartsofittoCUDA.Thecodehasbeenmodifiedinafewplacestomakeitmorestraightforwardtotranslate.GradingYourgradeforthisassignmentw
UCLA - EL ENGR - 2
CUDA Quick ReferenceMore documentation can be found here:http:/developer.download.nvidia.com/compute/cuda/4_1/rel/toolkit/docs/online/group_CUDART_MEMORY.htmlhttp:/docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#c-language-extensionsCUDA Over
UCLA - EL ENGR - 2
CS33, Spring 2013Data LabAssigned: Apr. 2, Due: Fri., Apr. 12, 11:59PM1 IntroductionThe purpose of this assignment is to become more familiar with bit-level representations of integers. Youlldo this by solving a series of programming puzzles. Many of
UCLA - EL ENGR - 2
1. A Stack Walks into a Bar and Says Its Hard to Maintain Discipline While Getting Smashed (20points): Consider the following C datatype, intended to provide some protection against bufferoverflow:struct safe_buffer cfw_int size;char * buffer; mybuf
UCLA - EL ENGR - 2
Fan Zhang 904063433HW3=3.59int switch_prob(int x, int n)cfw_ int result = x; switch (n) cfw_ case 42: case 40: result = x &lt; 3; break; case 41: result += 17; break; case 43: result = x &gt; 3; break; case 45: result = x * x + 17; break; c
UCLA - EL ENGR - 2
Fan Zhang904063433CS33 HW5=1. exploit string:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C8 DB FF FF E8 85 04 08=2. A - wallabyB - platypusC - dingoD - koalaE - wombat
UCLA - EL ENGR - 2
A:B:.data.word.word.globl main510main:addu.globl outputAMsgoutputAMsg:.asciiz &quot;\n A = &quot;.globl outputBMsgoutputBMsg:.asciiz &quot;\n B = &quot;.globl blankMsgblankMsg:.asciiz &quot;&quot;.text.globlfoolwlwswswjr$t0,$t1,$t0,$t1,$ra$s7, $0, $ra
UCLA - EL ENGR - 2
UCLA - EL ENGR - 2
CS33Spring2013Lab4:OpenMPIntroductionInthislabassignment,youwillimprovetheperformanceofexistingcodeusingoptimizationtechniquesandparallelizationusingOpenMP.Thelabhandoutcontainsthefollowingfiles:hae.edrhegdtc.deeetcmi.ancMkflaeieigbpm.mcre
UCLA - EL ENGR - 2
OpenMP Quick ReferenceParallel Region#pragma omp parallelcfw_/ .The keyword &quot;parallel&quot; creates a team of threads.All threads execute the region.Parallel For#pragma omp parallel forfor ( _ ; _ ; _ )cfw_/ .i=0i=1i=2i=3i=4i=5i=6i=7The n
UCLA - EL ENGR - 2
Common Parallel ComputingScenariosMany parallel threads need to generate a single result ReduceMany parallel threads need to partition data SplitMany parallel threads produce variable output / thread Compact / ExpandPrimordial CUDA Pattern: Blocki
UCLA - EL ENGR - 2
CUDA BasicsCUDAA Parallel Computing Architecture for NVIDIA GPUsDevelopmentPlatform ofChoiceGPU Computing Applications Over 60,000 GPUComputingDevelopers (1/09) Windows, Linux andMacOS PlatformssupportedCtmOpenCLwith CUDA extensionsDirect
UCLA - EL ENGR - 2
5. Bit Off More Than You Can Chew? (10 points): Consider the code fragment below: &amp; $0%' :,0,What would be printed for each of the following statements: &quot;*8 * # &quot;*8* # &quot;*8 * # &quot;*8 8 8 8 * $/% $.% $-% $,%#How many bytes would occ
UCLA - EL ENGR - 2
1. Lost at C? (12 points): The following problem assumes the following declarations:int x = rand();float f= foo(); / f is not NaNunsigned ux = rand();For the following C expressions, circle either Y or N (but not both). If y
UCLA - EL ENGR - 2
CS33Setting up your environment for new Linux/Unix usersAuthor: Kanit Therdsteerasukdi (therdste@cs.ucla.edu)OverviewThere are two main types of environment for developing your code in this class. Theres actually more thantwo, but well just cover the
UCLA - EL ENGR - 2
UCLA - EL ENGR - 2
Modern Compiler DesignT10 MIPSMooly Sagiv and Greta YorshSchool of Computer ScienceTel-Aviv Universitygretay@post.tau.ac.ilhttp:/www.cs.tau.ac.il/~gretay1TodaytxtLexicalAnalysisSourceSyntaxAnalysisParsingASTSymbolTableetc.Inter.Rep.(
UCLA - EL ENGR - 2
Computer Systems: A Programmers PerspectiveInstructors Solution Manual 1Randal E. BryantDavid R. OHallaronOctober 18, 20021Copyright c 2003, R. E. Bryant, D. R. OHallaron. All rights reserved.2Chapter 1Solutions to Homework ProblemsThe text uses
UCLA - EL ENGR - 2
The Memory HierarchyChapter5ofB&amp;OSomenotesadoptedfromBryantandOHallaronThe CPU-Memory Gaphttp:/blogs.sun.com/toddjobson/entry/processors_and_performance_chips_mipsThe Energy Wall (SCiDAC)The Road to Exascale (SCiDac)Random-Access Memory (RAM) Keyf
UCLA - EL ENGR - 2
15213Recitation3:09/23/02OutlineRegisterconventionStacksandproceduresArraysStructsandlinkedlistReminder L2isduethisThursday!AnnieLuoemail:luluo@cs.cmu.eduOfficeHours:Thursday6:007:00Wean8402Registers%eax:Primaryaccumulator.containsreturnval
UCLA - EL ENGR - 2
Recitation2:Assembly&amp;gdbAndrewFaulring15213SectionA16September2002AndrewFaulring faulring@cs.cmu.edu Officehours: NSH2504(lab)/2507(conferenceroom) NormallyThursday56 THISWEEK:Wednesday56TodaysPlan PreparingforLab2 dueThursday,26Sep@11:59PM
UCLA - EL ENGR - 2
Problem 8.29 A plane wave in air withiE = (x 9 y 4 z 6)e j(2x+3z)(V/m)is incident upon the planar surface of a dielectric material, with r = 2.25, occupyingthe half-space z 0. Determine(a) The incidence angle i .(b) The frequency of the wave.r(c)
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 1 About EE161 Electromagnetic Waves James Clerk Maxwell and more Maxwells equations Boundary ConditionsEE161 Course InformationInstructor: Y. Etha
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 2 Complex Variable &amp; Phasor Time-harmonic Maxwells equations Wave Equations Plane WavesMaxwells Equations and BoundaryConditions in One GlanceInte
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 4 Waves in Lossy Medium Electromagnetic Power Density Current Conduction Surface ResistanceLossy Transmission Line d 2V ( z ) 2V ( z ) = 0 dz 22
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 3 General Plane Wave Solutions Field Direction and Wave PropagationDirection Polarization of the WaveGeneral Plane Wave SolutionsAs aforementioned,
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 6 Oblique Incidence Perpendicular Polarization Parallel Polarization Reflectivity and TransmissivityOblique IncidencexyzThe wave propagates in x
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 8 Introduction to Waveguide General Waveguide Solutions TEM Waves &amp; WaveguidesHistory of Waveguides1893 - Heaviside considered the possibility of wa
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 7 Incidence upon Lossy Medium Skin Effect Penetration into the Conductor Wave AbsorptionSpecial Angles - Brewster AngleBrewster Angle: A particular
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 11 Dispersion Relationship Phase Velocity and Group VelocityDispersion Relationship in WaveguidesFor each mode, is a function of the wave number k, t
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 10 Waveguide Examples Dominant Modes Mode TemplatesDominant Modes in Various WaveguidesCoaxial Line:TEM modeParallel Plate Waveguide:TEM modeRec
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 9 TE, TM Waves Rectangular Waveguides TM Modes TE ModesWaveguide SolutionsGeneral waveguide field solutions are propagating in z direction can be w
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 12 Waveguide Loss Transmission Line Resonator Rectangular Waveguide Cavity Waveguide ExcitationCurrent Flow in Good ConductorDC currentCurrent flo
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 14 Antennas Short Dipole Antennas Radiation Characteristics Antenna Pattern Antenna DirectivityAntenna -TransducerAntenna transducer between a gui
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 15 Antenna Gain Antenna Radiation Resistance Half Wave DipoleBeam DimensionsPattern Solid Angle is defined as: p = F ( , )d4For isotropic (omni-d
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 16 Dipole Antenna Large Aperture Antenna Rectangular Aperture with Uniform FieldDistribution Friss Transmission FormulaRadiation by Large Aperture
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 5 Wav Reflection &amp; Transmission at NormalIncidence Transmission Line Analogue Power Reflection &amp; TransmissionLoaded Transmission LineincidenceGene
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2007Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 18 Antenna Arrays Uniform Linear Array Arrays with Uniform Excitation Electronic Scanning Grating LobesAntenna ArrayAntenna arrays: a discrete ver
UCLA - EL ENGR - 2
EE161, HW5#1. For an air-filled rectangular waveguide with inner dimensions 0.9 in by 0.4in.,(1) assume f=9GHz, calculate ZTM and ZTE for each of the modes that arepropagating. (2) what is g, Vp and Vg for TE10 mode. (3) Do that again for thesame wave
UCLA - EL ENGR - 2
EE161Electromagnetic WavesSpring, 2013Midterm OneName:Student ID:Score:Problem 1. (30pts) The instantaneous electric field intensity vector of a wavetravelinginalossynonmagneticmediumisgivenbyy9E = e cos 6.28 10 t + 204 y x V / m . The
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2013Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 17 Antenna Arrays Arrays with Uniform Excitation Electronic ScanningAntenna ArrayAntenna arrays: a discrete version of aperture antennas.Aperture a
UCLA - EL ENGR - 2
EE161 Electromagnetic WavesSpring, 2007Prof. Y. Ethan WangElectrical Engineering Dept.UCLALesson 19 Radar Systems Radar Detection Doppler Radar Monopulse Radar Satellite Communication Satellite TV Free to Air receptionRadar SystemApplications
UCLA - EL ENGR - 2
UCLA - EL ENGR - 2
EE161 Final ExamSpring, 2009Name:Student ID:Grade:Problem 1 (20pts). The electric field of a plane wave propagating in air has thefollowing expression given byE(t ) = x1.8 cos(t 4 x 3z ) y 3 sin(t 4 x 3z ) + z 2.4 cos(t 4 x 3z ) .(1) (4pts) find t
UCLA - EL ENGR - 2
EE161 Final ExamSpring, 2010Name:Student ID:Grade:~Problem 1. (ABET) A plane wave in air with E i = ( x9 y 4 z6)e j ( 2 x +3 z ) (v/m) isincident upon the planar surface of a dielectric material, with r = 2.25 , occupyingthe half-space z 0 . Deter
UCLA - EL ENGR - 2
UCLA - MATH - 32A
EE M16 and CS M51A Spring 2012 Section 1Logic Design of Digital SystemsDr. Yutao HeVHDL Lab #1 - Orientation of VHDL and ISEDue: May 11, 2012Name:LastFirstStudent ID:Date:ResultCorrectnessCreativityReportTotal Score1VHDL Lab #1 Orientation
UCLA - MATH - 32A
UCLA - MATH - 32A
UCLA - MATH - 32A
UCLA - MATH - 32A
UCLA - MATH - 32A
S YLLABUS : P HYSICS 1B, L ECTURE 1, W INTER 2012I NSTRUCTOR :Prof. Troy Carter4-909 PAB(310) 825-4770tcarter@physics.ucla.eduO FFICE H OURS :M 10-11AM, T 1PM-2PM, F 1-2PM, other times by appointmentC OURSE A DMINISTRATOR :Elaine Dolalas (handles