Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UP Lecture 26

UP Lecture 26

Compilers
Intermediate Code III
(202605)

Transcript

  1. Dr. Javier Gonzalez-Sanchez | Compilers | 3 jgs jgs Translate

    Source to Object { int a; int b; int c; int d; if (a != 5) { b = c + d; } print (a); } a,int,global 0 b,int,global 0 c,int,global 0 d,int,global 0 #E1,int,label,9 #P,int,label,1 @ lod , 0 lit 5, 0 opr 14, 0 jmc #e1, false lod c, 0 lod d, 0 opr 2, 0 sto b, 0 lod a, 0 opr 21, 0 opr 1, 0
  2. Dr. Javier Gonzalez-Sanchez | Compilers | 5 jgs jgs Programming

    Assignment 4 Level 1 LIT, LOD, STO, OPR
  3. Dr. Javier Gonzalez-Sanchez | Compilers | 17 jgs jgs Code

    R if (twice) { OPR <operatorNumber>, 0 }
  4. Dr. Javier Gonzalez-Sanchez | Compilers | 18 jgs jgs Code

    E if (twice) { OPR <operatorNumber>, 0 }
  5. Dr. Javier Gonzalez-Sanchez | Compilers | 19 jgs jgs Parser

    A if (twice) { OPR <operatorNumber>, 0 }
  6. Dr. Javier Gonzalez-Sanchez | Compilers | 20 jgs jgs Code

    B if (operatorUsed) { OPR 3, 0 } LIT 0, 0
  7. Dr. Javier Gonzalez-Sanchez | Compilers | 22 jgs jgs Review

    Programming Assignment 4 Level 2 JMP, JMC
  8. Dr. Javier Gonzalez-Sanchez | Compilers | 23 jgs jgs Instructions

    ▪ JMP <line>, 0 Put the value <line> in the program counter; thus, the next line to be executed will be <line> Examples: JMP 1, 0 JMP 14, 0 JMP 75, 0
  9. Dr. Javier Gonzalez-Sanchez | Compilers | 24 jgs jgs Instructions

    ▪ JMC <line>, <condition> Read one value from the CPU register If the value is equal to <condition>, put the value <line> in the program counter; thus, the next line to be executed will be <line> Examples: JMC 1, true JMC 14, false JMC 75, true
  10. Dr. Javier Gonzalez-Sanchez | Compilers | 25 jgs jgs Example

    | if { int a; int b; a = 10; if (a>1) { print (a); } else { print (b); } return; } int a global 0 int b global 0 int #e1 global 10 int #e2 global 12 LIT 10, 0 STO a, 0 LOD a, 0 LIT 1, 0 OPR 11, 0 ; > JMC #e1, false LOD a, 0 OPR 20, 0 ;print JMP #e2, 0 LOD b, 0 OPR 20, 0 ;print OPR 1, 0 OPR 0, 0
  11. jgs jgs Compilers Javier Gonzalez-Sanchez, Ph.D. [email protected] Spring 2025 Copyright.

    These slides can only be used as study material for the Compilers course at Universidad Panamericana. They cannot be distributed or used for another purpose.