CS 354 Final Exam 2023 with verified questions and answers
-Wall Show all errors -m32 32-bit code -std=gnu99 java syntex -o output file little endian least sign. digit is in lowest address big endian most sign. digit is in lowest address (*(m+i))[j] sub for i *(m[i]+j) sub for j ((m+i)+j) sub for both i and j pointer arithmetic requires continues memory 2-d array types continuous vs array of arrays dangling pointer pointer to address that is no longer vaild local variables don't return local varable Statically allocated arrays all but first dim. must be specified Array's can't be return types TRUE argc argument count includes program name argv argument values is an array to char pointers (program name included) remember string literals? In read only area so can't modify char *strcpy char strcpy(char dest, char *scr) char *strcat char strcat(char dest, char *scr) Remember new lines will cause intermittent error if not in place Initialized DATA Segment Static variables and global variables with initial variables Uninitialized DATA Segment static variables and global variables with uninitialized or initialized to zero HEAP dynamic alloc'd stack local variables, parms, temps, statically alloc'd virtual address space illusion by os that each process has whole range of memory virtual address simulated address generated by a process physical address addrs. used by hardward page table maps virtual to physical address brk changes program space in mem. (use malloc instead) Requirements of Heap Allocator 1. Provide an immediate response 2. Allocate uses heap 3. Cannot move or change allocated block 4. Follow alignment requirements 5. Must handle arbitrary sequences of request External Fragmentation enough free space but divided into small blocks First Fit alloc first block big enough Next Fit first fit from block just alloced Footers only on free blocks 2d array do end dim first and first dim 2nd B bytes per block b log2(B) bits for byte offset within block to word, last two bits give you byte in the word m size of address space S number of sets line can store one block size of cache given S and B SxB (Note: does not include V or Tag bits) Cache Process to Select Correct Word in Cache 1. Select Set from S bits 1.5 Get right line from E bits 2. Select/Verify Line from T bits 3. Word extraction from B bits Bytes per word 4 bytes per word 5 value cache summary C=(S, E, B, m) write through update immediately writing to lower level write back update lower only when victim No Write Alloc bypass cache with miss and write to level below write allocate loads in block and writes to it Stride Misses % misses = min(1, wordsize*k / B) Top of Stack Register %esp Base of Stack Register %edx Return Register %eax CF Carry Flag ZF Zero Flag SF Sign Flag OF Overflow Flag cmp (s2, s1) - s1 - s2 test s1 & s2 True 0 False anything but zero String Caveats only string pointer can be assigned a string literal Page Table OS part that maps virtual address to physical one First Fit - Benefits and Negatives +Splits large blocks at front leaving more room -slow throughput Next Fit - Benefits and Negatives +throughput high -poorer mem. until then FF Best Fit +good mem. util -slow throughout What happens if no free block is large enough? 1. Coalesce adj. free blocks 2. Ask kernel for more space Preprocessor -edits source by removing comments -expands preprocess directives #include, #define Complier -Translates HL to assembly Assembler -translates assembly to machine code -produces relocatable object file Linker -merges the relocatable object files into single executable -at this point .bss and .data laid out leal for simple math - See examples L24 Compiler Needs To Do 1. Allocate/Free Activation Records 2. Allocate/Initialize Local Vars 3. Handle Return Values 4. Pass Parms. 5. Transfer execution to/from called func. 6. Preserve regs. used by caller 7. Store temp. vars. 8. Remember return addr. A callees args. Are located in stack frame above it +8 bytes to first arg (4 for return address, 4 to arg), %ebp used to access Flow of Control For Function Calls 1. Push return addr. to stack 2. Jump to the called func. (%eip gets the function addr) ret 1. pop return value off stack 2. Jump back to caller function %eip program pointer leave free callee's stack prior to ret 1. Sets stack pointer to base of callee's frame 2. restores %ebp to caller's frame base and %esp to top of caller's frame %ebp - value set up locals caller-saved regs %eax, %ecx, %edi callee-saved regs %edx, %esi, %edi Array In Assembly Practice L29 Alignment of ints, floats, doubles, pointers 4 byte aligned Alignment of short 2 byte align Total size of a struct Mult. of largest member (practice L31) Buffer Overflow Attack When more data is inputted than what was intended, causing data in lower stack frames to get overwritten. Can lead to malicious code being inserted. worm runs by itself and propagate itself virus cannot run itself must attach to other code Protection Against Stackoverflow 1. "canary values" 2. limit executable pages with executable bit 3. Address space randomization control transfer transition from one instruction to another control flow sequence of control transfer Exception Event that sidesteps the normal stack flow of execution Asynchronous an event that is external to the process and can happen anytime synchronous an event that's a result of the current instruction Control Flow of Exception Normal flow 1. Exceptional Event Occurs 2. Call Appropriate handler 3. Exception handler runs 4a. return control to instr. current 4b. return control to instr. next 4c. abort Exception table OS table determined at boot time; jump table of exception handlers Exception number unique non-negative integer associated with exception type Indirect Function Call for Exception 1. Push return addr. 2. Push process state (context switch) 3. run exception handler Interrupts enables devices to notify they need attention current instruction completes TRAP allows process to interact w/ OS returns to next instruction Fault problem w/ current instruction returns to current instr and re-tries it Abort cleanly ends a process Process Instance of a program Switching to Kernel Mode Only can be done with exception Cache Pollution In context switch new process cannot used cached info Group multiple process together xx/xx pgid/pid Signal Small message sent to a process to notify it that some event has occurred How to send signal? kill(signal#) ROF module containing code stored on disk that is in a format that can easily be recombine by linker with other ROF ELF (Executable and Linkable Formate) is layout used by linux w/ for ROF's and EOF's ELF Header Gen Info: ELF size, object file type, byte offset to SHT, size of SHT and # of entires in SHT SHT (Section Header Table) section locations and sizes .symtab linker symbol table .line maps machine code to code for debugger static linking combines ROF's into a fully linked EOF contains library code larger dynamic linker library code is linked in during load time or run time Issues from combining ROFs 1. Symbols needs to be check that this is one definition - Resolution 2. Symbols need address need to be updated as the ROFs are combine What kinds of variables need symbols? static locals global vars static globals externs What kinds of functions needs symbols? Extern. function declared in one file defined in another Non-static functions in this ROF that can be referenced in other ROFs Symbol Table build by assembler using symbols that are exported by the compiler Ndx 1. text 2. redata 3. data 4. bss Symbol Resolution ensuring each symbol has exactly one def. This is divided between compiler and linker Compiler: check symbols in each file, locals, static locals Linker: checks symbols in multiple modules, static locals must relocate them, globals check and relocate weak symbol uninitialized global vars strong symbol initialed global vars or funcs Linker Rules for Resolving Globals 1. Multiple strong symbols not allowed 2. Given one strong and one or more weak, choose strong 3. Given only weak definitions choose only one (linker dependent)
Written for
- Institution
- CS 354
- Course
- CS 354
Document information
- Uploaded on
- May 5, 2023
- Number of pages
- 8
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
- wall show all errors
- m32 32 bit code
- o output file
-
cs 354 final exam 2023 with verified questions and answers
-
stdgnu99 java syntex