Code Generator
similar to Intermediate Code GeneratorIntermediate Code GeneratorExpressed as quadruples: Opr Arg1, Arg2, Store/result If there is a while or if, add jmpf right away only do while uses jmpt only jmpf always come first Intermediate Code Generator Operators Example Alvina Aulia Intermediate Code Generator (while) x := 1; y := x + 10; while (x Final Exam](../compilation-techniques.md#final-exam) References
Expressed as:
Opr Arg1, Store/result
No arg2
Use # for numbers
If there is a
while
orif
, addjmpf
right away only
do while
usesjmpt
only
jmpf
always come first
ex: a = a * a
mov a, R0
mul a, R0
mov R0, a
Intermediate Code Generator OperatorsIntermediate Code Generator OperatorsPasted image 20241214144120.png
Example Kenny Jingga Responsi 2024 (for)
- mov #0, a
(int a = 0)
- mov #0 i
(i = 0)
- move i, R0
(prep for operation, beginning of for loop) [R0 = i = 0]
- lt #10, R0
(i < 10) [R0 = R0 < 10 = T/F]
- jmpf R0, [17]
(for loop condition is fale)
- mov i, R0
(prep for operation, beginning of if statement) [R0 = i]
- mod #2, R0
(i % 2) [R0 = R0 % 2]
- eq #0, R0
(... == 0) [R0 = R0 == 0 = T/F]
- jmpf R0, [13]
if condition is false, go to increment in loop
- mov a, R0
(prep for operation) [R0 = a]
- add i, R0
(a + i) [R0 = a + i]
- mov R0, a
(a = a + i)
- mov i, R0
(prep for operation) [R0 = a]
- add #1, R0
(i + 1) [R0 = i + 1]
- mov R0, i
(i = i + 1)
- jmp , [3]
(looping)
- ...
Status: #idea
Tags: compilation-techniques > Final ExamCompilation Techniques NotesMid Exam
RE to DFA
RE to E-NFA to DFA
Context Free Grammar
Top down parsing
Final Exam
Bottom Up Parsing
Directed Acyclic Graph
TAC, Triples, Quadriples
Intermediate Code Generator
Code Generator
Annotated Parse Tree
Three Address Statement
resources:
https://www.youtube.com/watch?v=6yRB6dszSUo&ab_channel=HIMTIBINUS
* [x] watch all alvina aulia vids
* [x] watch responsi
(after OS)
* [ ] try example questions from kenny
* [ ] try example questions from others
* [ ] practice weak