I. Review for the final exam A. itegrative question ------------------------------------------ INTEGRATIVE QUESTION How would you organize the code for an assembler? ------------------------------------------ B. Terminology 1. Compilers a. Semantic analysis and symbol tables ------------------------------------------ COMPILER CONCEPTS What is a scope? What syntactic features start scopes in C? What starts a scope in PL/0? How is a symbol table used? Is there just one symbol table? ------------------------------------------ b. Code generation ------------------------------------------ CODE GENERATION What did we use for an IR in HW4? What information from a name's use is needed to generate code in PL/0? In PL/0, why not have the parser determine the lexical address of each variable? ------------------------------------------ i. code generation for statements ------------------------------------------ CODE GENERATION FOR STATEMENTS How is the code generator written in C? What does the C code look like for generating code for PL/0 statements? What does the C code look like for generating code for a PL/0 while statement? ------------------------------------------ ------------------------------------------ GENERATING CODE FOR IF STATEMENTS In C there are 2 kinds of if-statements with syntax if (Exp) Stmt and if (Exp) Stmt1 else Stmt2 How would these be compiled? What would the generated code look like for a C switch statement? ------------------------------------------ ------------------------------------------ LABELS Would labels (as in HW4) be useful if the VM's ISA required absolute addresses for jumps? How would that work? ------------------------------------------ ii. code generation for nested scopes ------------------------------------------ ACTIVATION RECORDS What are ARs used for on the runtime stack? Why not have all calls of a procedure share the same storage? In C, how many levels of static scopes can there be in a program? In C, what causes that nesting of scopes? ------------------------------------------ ------------------------------------------ PROCEDURE CALLS What does the CAL instruction do? Does the code for a procedure body need to reserve space for the links? In C, when the function main returns, what is it returning to? ------------------------------------------ ------------------------------------------ PROCEDURE CALLS AND RETURNS How is the starting address of a procedure obtained (for use in a CAL instruction)? Why does the stack need to be trimmed before a procedure returns? With static scoping, what does the BP register point to on the stack? ------------------------------------------ ------------------------------------------ SCOPING AND ADDRESSING If some variables were dynamically scoped, how would they be addressed? ------------------------------------------ iii. generating code for declarations ------------------------------------------ GENERATING CODE FOR DECLARATIONS How would the C declaration const double e = 2.718281828459; be compiled for a stack machine? How would the C declaration int i; be compiled for a stack machine? How would the C declaration void incI() { i += 1; } be compiled? ------------------------------------------ iv. generating code for expressions ------------------------------------------ CODE GENERATION FOR EXPRESSIONS Where does the compiled code put the result of an expression (in a stack machine)? Why are identifier uses important? ------------------------------------------ ------------------------------------------ CODE GENERATION FOR EXPRESSIONS 2 How is a constant's lexical address used to load the constant's value? How is a variable's lexical address used in an assignment statement? ------------------------------------------ C. Assembly Language ------------------------------------------ ASSEMBLY LANGUAGE What is an assembly language? What features does assembly language provide to help programmers? How does assembly language differ from C? ------------------------------------------ ------------------------------------------ ASSEMBLERS How does an assembler translate forward jumps to a label? How would you organize an assembler as a program? ------------------------------------------ ------------------------------------------ ASSEMBLER OUTPUT FORMAT What would be the output format for an assembler on Unix? What are the main sections of an object file? What addresses would need to be relocated and would need to be marked as such? ------------------------------------------ D. Linkers ------------------------------------------ LINKERS What does a linker do? How many passes would a linker need? Does a linker treat user program code differently than library code? ------------------------------------------ E. Loaders ------------------------------------------ LOADERS What does a loader do? What is a boot loader? How is the boot loader loaded? Does a boot loader do relocation? ------------------------------------------ F. Operating Systems ------------------------------------------ OS What are the goals of an OS? What is the basic technique for running programs efficiently used by an OS? Would it be better if an OS were just a collection of libraries that worked with the hardware? ------------------------------------------ 1. processes ------------------------------------------ PROCESSES What is a process? How is a process different from a program? How does a program become a process? Why is the process concept useful for programmers? ------------------------------------------ ------------------------------------------ PROCESS TRANSITIONS What states can a process be in? What causes transitions between states? ------------------------------------------ 2. resource sharing ------------------------------------------ RESOURCE SHARING How does an OS facilitate sharing of resources? Why are interrupts needed? What are the different kinds of interrupts? ------------------------------------------ ------------------------------------------ INTERRUPT PROCESSING What is an interrupt handler? What mode does an interrupt execute in? What does an interrupt handler do to save the state of the running process? ------------------------------------------ ------------------------------------------ TRAP TABLES (INTERRUPT VECTORS) What is a trap table? What software controls the trap table? ------------------------------------------ 3. limited direct execution ------------------------------------------ LIMITED DIRECT EXECUTION What is limited direct execution? How does it work? What mode does your program run in? What kinds of instructions are privileged? ------------------------------------------ a. system calls ------------------------------------------ SYSTEM CALLS What is a system call? Why are system calls needed? ------------------------------------------ G. threads ------------------------------------------ THREADS What is a thread? Does each thread have its own stack? Why are threads useful? ------------------------------------------ 1. synchronization ------------------------------------------ SYNCHRONIZATION What is a race condition? Why are race conditions a problem? What is a critical section? ------------------------------------------ ------------------------------------------ CORRECTNESS FOR THREADS When is an execution serializable? When is execution atomic? ------------------------------------------ H. skills Would you be able to write code for traversing an AST and checking declarations (given some helping functions)? Would you be able to write code to traverse an enhanced AST and generate stack machine code (given some helping functions)?