COMPSYS Flashcards
(34 cards)
What is the key difference between compilation and interpretation?
Compilation translates high-level code into machine code before execution; interpretation executes code line-by-line during runtime.
What are two advantages of compilation?
Optimized machine code for faster execution and ability to run multiple times without recompiling.
What are two advantages of interpretation?
Easier debugging and platform independence — no machine-specific compilation required.
What is combined compilation and interpretation? Give an example.
First compile to an intermediate form (e.g., Java Bytecode), then interpret or JIT-compile it at runtime.
What is a virtual machine (VM) in this context?
A software simulation of a CPU that runs programs independently of hardware; e.g., Java Virtual Machine (JVM).
What does the JVM use to execute Java programs?
It uses compiled bytecode (.class files), interpreted or JIT-compiled during runtime.
What is Just-In-Time (JIT) compilation?
JIT compiles bytecode into machine code during runtime to improve performance.
What is the role of a stack in a stack machine?
Stack holds operands for computation and return addresses for subroutines.
Why do stack machines use stacks instead of registers?
Simpler instruction set, smaller code, flexible operand management.
What is Reverse Polish Notation (RPN) and why is it used?
Postfix notation where operators follow operands; eliminates parentheses, ideal for stack evaluation.
How are subroutines implemented using stacks?
Push return address and local variables onto the stack at call; pop return address on return.
What is the difference between unconditional and conditional jumps?
Unconditional jump always branches; conditional jump branches only if a condition is met.
How does the Program Counter (PC) behave in stack machines like JVM?
PC points to the current instruction and steps through sequentially.
Why is Java compiled to bytecode instead of directly to machine code?
Portability, security, and runtime optimization flexibility.
List 3 key properties of the JVM architecture.
- Stack-based 2. Typed instructions 3. Variable-length instructions
Would you choose compilation, interpretation, or a hybrid for multi-device systems? Why?
Hybrid — compile to intermediate bytecode, interpret/JIT it; ensures portability and runtime optimization.
For rapid bug fixing and testing, choose compilation or interpretation?
Interpretation — allows immediate testing without recompilation.
How do pure interpreters and JIT compilers differ at runtime?
Pure interpreter executes line-by-line; JIT compiles chunks into machine code during execution.
In a stack machine, why might evaluating a + (b * c) be faster than in a register machine?
Stack machines avoid register allocation overhead and have simpler decoding.
When is a stack machine preferable despite being slower?
For simplicity, smaller hardware, easier implementation — common in embedded systems or VMs.
Convert this RPN to Infix: 5 6 + 7 2 - ×
(5 + 6) × (7 - 2)
Convert this RPN to Infix: a b + c d + ×
(a + b) × (c + d)
Convert this RPN to Infix: 4 5 × 6 7 × +
(4 × 5) + (6 × 7)
In RPN 2 3 + 5 *, what is the final stack result?
25