Code Generation MCQs January 8, 2026December 14, 2024 by u930973931_answers 20 min Score: 0 Attempted: 0/20 Subscribe 1. What is the primary purpose of code generation in a compiler? (A) To detect and correct errors in the program (B) To optimize the source code (C) To translate high-level language code into machine language (D) To generate intermediate representations of the code 2. In the context of code generation, what does the term “target machine” refer to? (A) The programming language being used for generation (B) The hardware architecture for which the code is being generated (C) The system software used to execute the program (D) The intermediate representation of the program 3. Which of the following is a key step in the code generation process? (A) Lexical analysis (B) Optimization of loops (C) Syntax checking (D) Mapping intermediate code to target machine instructions 4. What does “register allocation” refer to in code generation? (A) The process of assigning variable names to memory locations (B) The process of optimizing loops in the code (C) The process of assigning variables to machine registers (D) The process of handling function calls in the code 5. Which of the following is NOT typically involved in code generation? (A) Register allocation (B) Instruction selection (C) Intermediate code optimization (D) Memory management 6. What is the purpose of instruction selection in code generation? (A) To select the appropriate programming language for code generation (B) To select the most efficient machine instructions for the target machine (C) To detect syntax errors in the code (D) To optimize loops in the code 7. In code generation, which of the following would be considered an “addressing mode”? (A) Register (B) All of the above (C) Direct memory access (D) Stack 8. Which type of code generation targets a specific machine architecture? (A) Machine-dependent code generation (B) Source code generation (C) Assembly code generation (D) Intermediate code generation 9. Which of the following is a common target of code generation? (A) Java bytecode (B) Intermediate code (C) High-level language code (D) Assembly language 10. Which phase of the compiler is directly responsible for generating the executable code? (A) Lexical analysis (B) Syntax analysis (C) Code generation (D) Optimization 11. In code generation, what is the role of the “instruction scheduler”? (A) To reorder instructions to improve execution efficiency (B) To select the correct machine instructions (C) To detect syntax errors (D) To handle function calls 12. What does the term “instruction scheduling” in code generation refer to? (A) Determining the order in which machine instructions should be executed (B) Determining which instructions are redundant (C) Converting high-level code to assembly code (D) Removing unnecessary code 13. Which of the following is an example of a target machine in code generation? (A) High-level programming language (B) ARM architecture (C) Intermediate representation (D) Abstract syntax tree 14. In code generation, what is the purpose of “peephole optimization”? (A) To generate machine code for a specific architecture (B) To optimize the overall logic of the program (C) To replace small instruction sequences with more efficient alternatives (D) To detect and handle runtime errors 15. Which of the following is a major challenge in code generation? (A) Handling syntax errors (B) Performing lexical analysis (C) Mapping high-level language constructs to target machine instructions (D) Parsing intermediate code 16. What is “register spilling” in the context of code generation? (A) Storing variables in memory instead of using machine registers when the registers are full (B) Moving variables between registers to optimize performance (C) Clearing unnecessary data from registers (D) Assigning registers to variables in the code 17. Which of the following is a technique used during code generation to minimize the number of instructions? (A) Register allocation (B) Dead code elimination (C) Instruction selection (D) Instruction scheduling 18. In which phase of code generation is the target machine code actually produced? (A) Register allocation (B) Code emission (C) Instruction selection (D) Code optimization 19. Which of the following is a key challenge of machine-dependent code generation? (A) Translating abstract syntax into machine-specific instructions (B) Ensuring that the code runs on multiple platforms (C) Generating high-level programming language code (D) Handling syntax errors in the code 20. What does the term “target code” refer to in code generation? (A) The code generated by a compiler for a specific machine architecture (B) The intermediate code generated by the compiler (C) The source code before compilation (D) The high-level code that is being optimized