This topic belongs to the Code Generation phase of a compiler. It explains what the final output language is and how memory locations (addresses) are represented in generated code.
The target language is the language into which a compiler translates the source program.
👉 It is the final output language of the compiler.
MOV, ADD, MULx = a + b;
MOV R1, a
ADD R1, b
MOV x, R1
✔ Target language is final output of compiler ✔ Can be machine code or assembly code ✔ Must be efficient and executable ✔ Depends on target machine architecture
Addresses in target code refer to the locations where data is stored or accessed during execution.
👉 These may represent:
Fixed memory location in physical memory.
MOV R1, 5000
👉 5000 = fixed memory address
Address relative to a base register or current instruction.
LOAD R1, 8(R2)
👉 Means: R2 + 8
Uses labels instead of actual memory locations.
L1: ADD R1, R2
JMP L1
Uses CPU registers instead of memory.
MOV R1, R2
Addressing modes define how operands are accessed.
Operand is given directly.
MOV R1, #5
Memory address is given.
MOV R1, A
Address stored in a pointer/register.
MOV R1, (R2)
Base + offset form.
MOV R1, 4(R2)
During code generation, compiler assigns:
a → 1000
b → 1004
c → 1008
Created during intermediate code:
t1 = a + b
t1 → register or stack memory
L1, L2, L3
Used in:
if (a < b)
x = a + b;
if a < b goto L1
goto L2
L1: t1 = a + b
x = t1
L2:
MOV R1, a
CMP R1, b
JGE L2
MOV R2, a
ADD R2, b
MOV x, R2
L2:
✔ Helps map variables to memory ✔ Enables correct execution flow ✔ Required for jumps and loops ✔ Used for register allocation ✔ Improves efficiency of target code
Relocation means adjusting addresses when program is loaded into memory.
| Concept | Meaning |
|---|---|
| Target language | Final output (assembly/machine code) |
| Absolute address | Fixed memory location |
| Relative address | Base + offset |
| Symbolic address | Label-based reference |
| Register address | CPU register usage |
✔ Target language is final compiler output ✔ Usually assembly or machine code ✔ Addresses define memory locations of data ✔ Types: absolute, relative, symbolic, register ✔ Addressing modes control how operands are accessed ✔ Labels are used for control flow
Target language is the final language produced by a compiler, usually assembly or machine code. Addresses in target code refer to the memory locations, registers, or labels used to access data and control program execution. These addresses may be absolute, relative, symbolic, or register-based depending on the addressing mode used.
| Concept | Description | Example |
|---|---|---|
| Target language | Final output code | Assembly code |
| Absolute address | Fixed memory | 5000 |
| Relative address | Base + offset | 8(R2) |
| Symbolic address | Labels | L1, L2 |
| Register address | CPU registers | R1, R2 |
| Immediate mode | Constant value | #5 |
Open this section to load past papers