Three-address code(MCQs)

General Concepts What is Three-Address Code (TAC)? A) A type of assembly language code B) An intermediate code used in compilers C) A low-level machine code D) A high-level programming language Answer: B) An intermediate code used in compilers In TAC, what does each instruction typically contain? A) Two operands and a result B) Three operands and a result C) One operator and two operands D) An operator, two operands, and a result Answer: D) An operator, two operands, and a result Which of the following is an example of a TAC instruction? A) a = b + c B) MOV a, b C) ADD a, b, c D) ADD R1, R2 Answer: C) ADD a, b, c In TAC, what does the = operator signify? A) Assignment of a value to a variable B) Comparison of two values C) Addition of two values D) Logical negation Answer: A) Assignment of a value to a variable What is the main purpose of using TAC in a compiler? A) To perform lexical analysis B) To generate machine code directly C) To provide an intermediate representation for optimization and code generation D) To handle syntax errors Answer: C) To provide an intermediate representation for optimization and code generation Instructions and Operations Which of the following TAC instructions represents a conditional jump? A) IF x < y GOTO L1 B) JMP L1 C) CALL func D) RET Answer: A) IF x < y GOTO L1 What is the purpose of a GOTO instruction in TAC? A) To call a function B) To return from a function C) To jump to a specified label unconditionally D) To compare two values Answer: C) To jump to a specified label unconditionally In TAC, what does the CALL instruction do? A) Performs a conditional branch B) Jumps to a function or subroutine C) Returns from a function D) Assigns a value to a variable Answer: B) Jumps to a function or subroutine Which TAC instruction is used to return from a function? A) CALL B) RET C) GOTO D) JMP Answer: B) RET What is the purpose of temporary variables in TAC? A) To store intermediate results of computations B) To hold constants C) To represent memory locations D) To perform logical operations Answer: A) To store intermediate results of computations Addressing and Variables In TAC, which type of variable is used to hold the result of an operation? A) Local variable B) Global variable C) Temporary variable D) Static variable Answer: C) Temporary variable How does TAC handle variables and memory locations? A) Using direct memory addressing B) Using symbolic names and temporary variables C) Using immediate values D) Using register addresses Answer: B) Using symbolic names and temporary variables Which TAC instruction would you use to perform an arithmetic operation? A) MOV B) ADD C) JMP D) CALL Answer: B) ADD In TAC, how is the result of an arithmetic operation typically stored? A) In a register B) In a temporary variable C) In memory D) In a constant Answer: B) In a temporary variable What does the TAC instruction t1 = a + b represent? A) An addition operation with result stored in a B) An assignment of the sum of a and b to t1 C) An assignment of b to a D) A function call with a and b as parameters Answer: B) An assignment of the sum of a and b to t1 Optimization and Efficiency How can TAC be optimized during the compilation process? A) By eliminating redundant instructions B) By converting to high-level language constructs C) By using more temporary variables D) By increasing the number of instructions Answer: A) By eliminating redundant instructions What is common subexpression elimination in TAC? A) Replacing a variable with its constant value B) Removing redundant expressions that have already been computed C) Combining multiple GOTO instructions into a single instruction D) Adding new temporary variables to simplify expressions Answer: B) Removing redundant expressions that have already been computed Which of the following optimizations can be applied to TAC? A) Loop unrolling B) Function inlining C) Dead code elimination D) All of the above Answer: D) All of the above What is the purpose of loop optimization in TAC? A) To convert loops into function calls B) To reduce the number of iterations by optimizing loop conditions C) To remove loops entirely from the code D) To increase the number of loops Answer: B) To reduce the number of iterations by optimizing loop conditions What is the effect of eliminating dead code in TAC? A) Increases the size of the intermediate code B) Reduces the size of the intermediate code and improves performance C) Adds additional instructions to the intermediate code D) Does not affect the intermediate code Answer: B) Reduces the size of the intermediate code and improves performance Control Flow In TAC, which instruction is used to handle conditional execution? A) GOTO B) CALL C) IF D) RET Answer: C) IF How does a GOTO instruction affect the control flow in TAC? A) It skips to a specified line of code B) It calls a function C) It returns from a function D) It performs a conditional check Answer: A) It skips to a specified line of code What is the primary purpose of a conditional branch instruction in TAC? A) To unconditionally jump to a new location B) To call a function based on a condition C) To execute code based on a condition D) To return from a function Answer: C) To execute code based on a condition Which TAC instruction would you use to perform a loop? A) CALL B) IF C) GOTO D) RET **Answer: B) IF and C) GOTO (Typically used together for loop control) How can nested conditional branches be represented in TAC? A) By using multiple GOTO instructions B) By using nested IF statements C) By using a combination of IF and GOTO instructions D) By converting to high-level language constructs Answer: C) By using a combination of IF and GOTO instructions Addressing Modes and Expressions What addressing mode is commonly used in TAC? A) Immediate addressing B) Direct addressing C) Indirect addressing D) All of the above Answer: D) All of the above Which TAC instruction represents an arithmetic expression? A) MOV a, b B) ADD a, b, c C) JMP L1 D) CALL func Answer: B) ADD a, b, c In TAC, how are compound expressions typically handled? A) By using nested function calls B) By breaking them into simpler operations and storing intermediate results in temporary variables C) By using a single complex instruction D) By converting them directly to machine code Answer: B) By breaking them into simpler operations and storing intermediate results in temporary variables What is the role of temporary variables in complex TAC expressions? A) To store constants B) To hold intermediate results and simplify expressions C) To perform logical operations D) To handle function calls Answer: B) To hold intermediate results and simplify expressions Which TAC instruction would you use to perform a comparison? A) ADD B) MOV C) IF D) CALL Answer: C) IF Function Calls and Return In TAC, what does the CALL instruction typically include? A) The function name and arguments B) The address of the function C) The result of the function D) The return address Answer: A) The function name and arguments How is a function return value typically handled in TAC? A) By using a MOV instruction to assign the return value to a variable B) By storing the return value in a temporary variable C) By using a RETURN instruction D) By directly modifying the caller’s variable Answer: B) By storing the return value in a temporary variable What is the purpose of the RET instruction in TAC? A) To return a value from a function B) To call a function C) To jump to a different part of the code D) To store the result of a computation Answer: A) To return a value from a function Which TAC instruction might be used to handle function parameters? A) CALL B) MOV C) ADD D) IF Answer: B) MOV How are function parameters typically passed in TAC? A) Using global variables B) Through registers C) By copying them to temporary variables D) By directly passing them in the CALL instruction Answer: C) By copying them to temporary variables Miscellaneous Which TAC instruction is most likely to be used for variable initialization? A) CALL B) MOV C) ADD D) RET Answer: B) MOV What is the advantage of using TAC over high-level language code? A) TAC code is more readable B) TAC provides a lower-level abstraction, useful for optimization and translation to machine code C) TAC eliminates the need for intermediate representations D) TAC is easier for end-users to understand Answer: B) TAC provides a lower-level abstraction, useful for optimization and translation to machine code In TAC, what is the role of a LABEL instruction? A) To call a function B) To mark a point in the code for jumps and branches C) To return from a function D) To initialize variables Answer: B) To mark a point in the code for jumps and branches Which TAC instruction is used to handle unconditional jumps? A) IF B) GOTO C) CALL D) RET Answer: B) GOTO How does TAC support the handling of arrays and data structures? A) By directly manipulating memory addresses B) By using specific instructions for arrays C) By representing array accesses as expressions involving temporary variables D) By converting them to high-level constructs Answer: C) By representing array accesses as expressions involving temporary variables What does the TAC instruction t1 = a * b perform? A) Multiplication of a and b, storing the result in t1 B) Division of a by b, storing the result in t1 C) Addition of a and b, storing the result in t1 D) Subtraction of a from b, storing the result in t1 Answer: A) Multiplication of a and b, storing the result in `t1 How are relational operations represented in TAC? A) As part of arithmetic operations B) Using IF instructions with relational conditions C) Using separate relational operators D) Directly as machine code instructions Answer: B) Using IF instructions with relational conditions Which TAC instruction is used to implement function calls with arguments? A) MOV B) CALL C) RET D) GOTO Answer: B) CALL How does TAC facilitate the optimization of arithmetic operations? A) By converting arithmetic expressions to machine code directly B) By breaking down complex expressions into simpler steps C) By removing all temporary variables D) By using more efficient algorithms Answer: B) By breaking down complex expressions into simpler steps What is the effect of using a temporary variable t in TAC for an expression t = a + b? A) It stores the result of a + b in t to simplify further computations B) It initializes a with the value of b C) It performs a comparison between a and b D) It returns the result of a + b to the caller Answer: A) It stores the result of a + b in t to simplify further computations In TAC, which instruction is used for logical operations? A) IF B) CALL C) MOV D) ADD Answer: A) IF (Logical operations are typically handled by conditional checks) What is a common way to represent loop constructs in TAC? A) By using multiple CALL instructions B) By combining IF and GOTO instructions to manage loop entry and exit C) By using a single RET instruction D) By directly translating to machine code Answer: B) By combining IF and GOTO instructions to manage loop entry and exit How does TAC handle function return values? A) By using the RETURN instruction B) By copying the return value to a temporary variable C) By using the CALL instruction D) By directly modifying global variables Answer: B) By copying the return value to a temporary variable Which TAC instruction would be used to implement an assignment operation? A) ADD B) MOV C) IF D) CALL Answer: B) MOV What does the TAC instruction t1 = a < b typically represent? A) An arithmetic operation where t1 is assigned the result of a < b B) A comparison operation where t1 is assigned a boolean result of a < b C) An assignment of the value of a to t1 D) A function call with a and b as parameters Answer: B) A comparison operation where t1 is assigned a boolean result of a < b
All Copyrights Reserved 2025 Reserved by T4Tutorials