Compilation, Interpretation & Subroutines Flashcards

(76 cards)

1
Q

What are high-level programming languages?

A

Languages like Java, C/C++, C#, Fortran, Cobol, and Pascal that are easier for humans to use.

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

What is low-level programming?

A

Programming with machine code (opcodes), which is hard for humans to read and write.

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

What is assembly code?

A

A human-readable form of low-level code that uses mnemonics instead of binary opcodes.

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

Why must high-level code be converted to machine code?

A

Because computers can only execute machine code.

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

What tool translates assembly code into machine code?

A

An assembler.

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

What is the role of a linker?

A

It combines different assembled parts into a complete program.

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

What does a loader do?

A

It loads the machine code into memory at a specified location.

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

What are the two ways to run a high-level program?

A

By compiling it into machine code or by interpreting it with an interpreter.

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

What happens when a program is compiled?

A

It is translated into native machine language and then run directly on the target machine.

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

Which approach is generally more efficient: compiling or interpreting?

A

Compiling is usually more efficient (e.g., C/C++ is faster than Python/JavaScript).

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

What does a compiler do?

A

It converts source code into object code that performs the same tasks as the original program.

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

What is a key feature of object code produced by a compiler?

A

It is usually relocatable, meaning it can be linked and loaded into memory later.

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

What are the advantages of compilation?

A

Compilation is done once per program, and the compiler can optimise the code for fast execution by exploiting hardware features.

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

What are the disadvantages of compilation?

A

It is harder than interpreting and the resulting program is hardware-dependent.

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

Where does the compiler run in relation to the target code platform?

A

The compiler runs on the same platform X as the target code.

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

What is cross-compilation?

A

Cross-compilation is when the compiler runs on platform
X, but the target code runs on a different platform Y.

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

What is an interpreter?

A

A program that directly reads and follows the source code, performing actions as it goes.

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

What is an example of the interpretation principle in real life?

A

Humans following step-by-step instructions or a CPU interpreting machine code.

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

What are advantages of using an interpreter?

A

It supports interactive debugging, testing, modifying variables, and invoking procedures from the command line.

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

What is a major disadvantage of interpretation?

A

Execution is slower compared to compiled programs.

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

What does interpretation involve?

A

Running high-level code directly by an interpreter.

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

What is the idea behind combining compilation and interpretation?

A

Compile high-level code into an intermediate language that can be efficiently interpreted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How does the speed of combined compilation and interpretation compare to pure methods?
It is slower than pure compilation but faster than pure interpretation.
26
What is an advantage of compiling to an intermediate language?
A single compiler can be used, independent of the CPU.
27
What is the CPU’s role in the combined model?
Each CPU interprets the intermediate language separately.
28
What does a virtual machine (VM) do?
It executes an instruction stream in software instead of hardware.
29
Which languages use virtual machines?
Pascal, Java, Smalltalk-80, C#, and some functional, logic, and scripting languages.
30
What is P-code in Pascal?
Intermediate code generated by Pascal compilers that can be interpreted or compiled into object code.
31
How does the Java Virtual Machine (JVM) execute programs?
It interprets Java bytecode and may use Just-In-Time (JIT) compilation to translate it into machine code.
32
What does a compiler do when using a virtual machine?
It generates an intermediate program (language).
33
How does the virtual machine execute the program?
It interprets the intermediate program.
34
What is required for the virtual machine to work on different platforms?
A virtual machine must be available on each platform.
35
What were the primary languages used before Java for systems programming?
C and C++ (object-oriented C) were used for systems programming.
36
What challenges arose with the rapid evolution of the World Wide Web?
Issues like different target machines, word lengths, instruction sets, and security.
37
How does Java overcome the issue of portability on different platforms?
Java uses a virtual machine, which makes it portable and allows programs to be executed remotely (e.g., applets) over the WWW.
38
Why isn't Java compiled directly to machine code?
Because it would require generating code for each target machine, making it impossible to exchange executable code.
39
What solution did Sun Microsystems design for Java's portability?
They designed the Java Virtual Machine (JVM) to specifically run Java bytecode.
40
How is Java source code translated?
Java source code is compiled into JVM bytecode, which is platform-independent.
41
How does the JVM enable portability and remote execution of Java programs?
The JVM can be written as a software interpreter in C (widely available), allowing bytecode to be exchanged and executed remotely.
42
What type of machine architecture is used by the JVM?
The JVM uses a stack machine, which is closer to modern high-level languages than the von Neumann register machines.
43
What is the memory size used by the JVM?
The JVM uses 32-bit words (4 bytes) for memory.
44
How many instructions does the JVM have, and what are their characteristics?
The JVM has 226 instructions, which are of variable length (1-5 bytes).
45
What does the Program Counter (PC) in the JVM contain?
The Program Counter (PC) contains byte addresses.
46
What is the Integer JVM (IJVM)?
IJVM is a simplified version of the JVM that lacks floating-point arithmetic and is focused on integer operations, making it a more basic form of the full JVM. It has fewer features, making it easier to understand and study.
47
What is a stack in the context of a stack machine?
A stack is an area of memory that extends upwards or shrinks downwards, with Local Variables (LV) at the base and the Stack Pointer (SP) at the top.
48
What does the Stack Pointer (SP) represent in a stack machine?
The Stack Pointer (SP) represents the top of the stack.
49
What happens when you perform a "push" operation on the stack?
A "push" operation increments the Stack Pointer (SP) and adds an item to the top of the stack.
50
What happens during a "pop" operation in a stack machine?
A "pop" operation decrements the Stack Pointer (SP) and removes the item from the top of the stack.
51
What happens during an "add" operation in a stack machine?
An "add" top two arguments on the stack replacing with result
52
What are stacks useful for in expression evaluation?
They handle bracketed expressions and allow evaluation like (a1 + a2) * a3 without using temporary variables by using PUSH and operations.
53
How would you evaluate (a1 + a2) * a3 using a stack?
PUSH a1, PUSH a2, ADD, PUSH a3, MULT (Related to RPN - Reverse Polish Notation).
54
How do stacks support local variables in methods?
Local variables are stored at the base of the stack and are deleted when the method exits.
55
How do stacks assist with method calls?
Stacks store the return address during (recursive) method calls.
56
What are the main stack operations in IJVM?
PUSH/POP (push or pop word), BIPUSH (push byte), ILOAD/ISTORE (load/store local variable onto/from stack).
57
What IJVM instructions handle integer arithmetic?
IADD (add) and ISUB (subtract) the two top words on the stack.
58
What branching instruction exists in IJVM?
IFEQ — pops the top word from the stack and branches if the value is zero.
59
Which IJVM instructions manage method calls and returns?
INVOKEVIRTUAL (invoke a method) and RETURN (return from a method).
60
What group is in one byte?
byte, const, varnum
61
What group is in two bytes?
disp,index, offset
62
Compiling Java to IJVM
63
How are JVM instructions different from most CPU instructions?
They are closer to high-level programming languages and not based on von Neumann architecture.
64
What is a major difference between JVM and typical CPU architecture regarding data storage?
JVM uses only the stack — no accumulators or registers.
65
What are two important features of JVM instructions?
Variable length instructions and typed instructions (different LOAD instructions for integers vs pointers).
66
Variable length instructions and typed instructions (different LOAD instructions for integers vs pointers).
To help verify security constraints.
67
How was the original JVM implemented by Sun Microsystems?
As a software interpreter in C with memory for the constant pool, method area, and stack.
68
What does a software JVM interpreter do?
It fetches, decodes, and executes JVM instructions using a procedure for each instruction.
69
What is a micro-programmed interpreter in the context of JVM?
A specialized version of the JVM interpreter optimized at the microcode level
70
What was the purpose of the picoJava II chip?
To manufacture hardware supporting JVM instructions for embedded Java applications.
71
Why not compile JVM bytecode directly to the target architecture?
Because it's more expensive and difficult due to many different architectures.
72
What is another disadvantage of compiling JVM bytecode to native code?
It would take more time to compile each instruction.
73
What is a major downside of using a software interpreter for JVM?
Execution is slower and instructions may need to be parsed repeatedly.
74
What does Just In Time (JIT) compilation do in Java?
It compiles Java instructions on the target machine (e.g., within a browser) and reuses the compiled code.
75
What is a downside of JIT compilation?
There is a longer wait time before executable code becomes available.
76