COMPSYS Flashcards

(34 cards)

1
Q

What is the key difference between compilation and interpretation?

A

Compilation translates high-level code into machine code before execution; interpretation executes code line-by-line during runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are two advantages of compilation?

A

Optimized machine code for faster execution and ability to run multiple times without recompiling.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are two advantages of interpretation?

A

Easier debugging and platform independence — no machine-specific compilation required.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is combined compilation and interpretation? Give an example.

A

First compile to an intermediate form (e.g., Java Bytecode), then interpret or JIT-compile it at runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a virtual machine (VM) in this context?

A

A software simulation of a CPU that runs programs independently of hardware; e.g., Java Virtual Machine (JVM).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the JVM use to execute Java programs?

A

It uses compiled bytecode (.class files), interpreted or JIT-compiled during runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Just-In-Time (JIT) compilation?

A

JIT compiles bytecode into machine code during runtime to improve performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the role of a stack in a stack machine?

A

Stack holds operands for computation and return addresses for subroutines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why do stack machines use stacks instead of registers?

A

Simpler instruction set, smaller code, flexible operand management.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Reverse Polish Notation (RPN) and why is it used?

A

Postfix notation where operators follow operands; eliminates parentheses, ideal for stack evaluation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How are subroutines implemented using stacks?

A

Push return address and local variables onto the stack at call; pop return address on return.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between unconditional and conditional jumps?

A

Unconditional jump always branches; conditional jump branches only if a condition is met.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does the Program Counter (PC) behave in stack machines like JVM?

A

PC points to the current instruction and steps through sequentially.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why is Java compiled to bytecode instead of directly to machine code?

A

Portability, security, and runtime optimization flexibility.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

List 3 key properties of the JVM architecture.

A
  1. Stack-based 2. Typed instructions 3. Variable-length instructions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Would you choose compilation, interpretation, or a hybrid for multi-device systems? Why?

A

Hybrid — compile to intermediate bytecode, interpret/JIT it; ensures portability and runtime optimization.

17
Q

For rapid bug fixing and testing, choose compilation or interpretation?

A

Interpretation — allows immediate testing without recompilation.

18
Q

How do pure interpreters and JIT compilers differ at runtime?

A

Pure interpreter executes line-by-line; JIT compiles chunks into machine code during execution.

19
Q

In a stack machine, why might evaluating a + (b * c) be faster than in a register machine?

A

Stack machines avoid register allocation overhead and have simpler decoding.

20
Q

When is a stack machine preferable despite being slower?

A

For simplicity, smaller hardware, easier implementation — common in embedded systems or VMs.

21
Q

Convert this RPN to Infix: 5 6 + 7 2 - ×

A

(5 + 6) × (7 - 2)

22
Q

Convert this RPN to Infix: a b + c d + ×

A

(a + b) × (c + d)

23
Q

Convert this RPN to Infix: 4 5 × 6 7 × +

A

(4 × 5) + (6 × 7)

24
Q

In RPN 2 3 + 5 *, what is the final stack result?

25
In RPN 8 2 / 3 +, what is the final stack result?
7
26
Given RPN: 3 4 5 × + 6 -, what is the Infix expression?
(3 + (4 × 5)) - 6
27
Given Infix: (x + y) × (a - b), what is the equivalent RPN?
x y + a b - ×
28
During evaluation of a b + c d + ×, what is on the stack after the first addition?
[a+b, c, d]
29
True or False: In RPN, parentheses are necessary to indicate order of operations.
False — the order is inherently clear.
30
Why are stack machines like JVM naturally suited to RPN?
Because operands are pushed and operations work directly on stack values, no precedence management needed.
31
Imagine a new language today: compiled, interpreted, or JIT compiled?
JIT compiled — balances performance and portability for modern multicore/cloud environments.
32
Why is the program counter simpler to manage in stack machines?
Instructions are executed sequentially with implied operand order, no dynamic dependency tracking.
33
Design for minimal embedded device: stack or register architecture?
Stack-based architecture — simpler, cheaper, more compact code.
34
Critique: 'Interpretation is always worse than compilation.'
False — interpretation is faster for initial testing, dynamic environments, and adaptable execution.