SlideShare a Scribd company logo
1 of 21
CSE340 - Principles of
Programming Languages
Lecture 20:
Intermediate Code I
Javier Gonzalez-Sanchez
BYENG M1-38
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2
A Compiler in Action
Lexer	
Parser	
Semantic  
Analyzer	
Code  
Generation	
Words
Tokens
Sentences
Symbol table
Uniqueness
Type matching
Translation
Source Code è Intermediate Code
Intermediate Code è Machine or Binary Code
Analysis
Compilation
Assembly
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3
Source Code
{
int a;
int b;
int c;
int d;
if (a != 5) {
b = c + d;
}
print (a);
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4
Intermediate (Object) Code
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 a, 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
Symbol table
Instructions
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5
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
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6
High-Level Languages
X,E,G,O,O
#e1,I,I,0,7
@
OPR 19, AX
STO x, AX
LIT 5, AX
OPR 21, AX
LOD #e1,AX
CAL 1, AX
OPR 0, AX
5
Virtual Machine
(interpreter)
// sorce code
int x;
int foo () {
read (x);
print (5);
}
main () {
foo ();
}
Lexer
Parser
Semantic Analyzer
Code Generation
01001010101000010
01010100101010010
10100100000011011
11010010110101111
00010010101010010
10101001010101011
Assembler
compilation execution
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7
High-Level Languages
X,E,G,O,O
#e1,I,I,0,7
@
OPR 19, AX
STO x, AX
LIT 5, AX
OPR 21, AX
LOD #e1,AX
CAL 1, AX
OPR 0, AX
5
Virtual Machine
(interpreter)
// sorce code
int x;
int foo () {
read (x);
print (5);
}
main () {
foo ();
}
Lexer
Parser
Semantic Analyzer
Code Generation
01001010101000010
01010100101010010
10100100000011011
11010010110101111
00010010101010010
10101001010101011
Assembler
compilation execution
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8
A Simple Virtual Machine
	
CPU	
	
	
	
	
	
	
	
ALU	
	
	
	
	
	
	
	
	
	
	
Register	
	
	
	
	
	
Memory
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9
	
Memory	
	
	
	
	
	
	
	
        program	
	
	
	
	
	
	
	
A Simple Virtual Machine
	
CPU	
	
	
	
	
	
	
	
ALU	
	
	
	
	
	
	
	
	
	
	
Register	
	
	
	
	
	
	
	
	
Code
sto 0, s
sto 0, d
sto 0, c
sto 0, d
lod s, 0
lit “s”, 0
opr 14, 0
jmc #a1, false
lod b, 0	
	
	
	
	
	
	
	
	
	
	
	
	
Symbol  
Table
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10
A Simple Virtual Machine
	
CPU	
	
	
	
	
	
	
	
ALU	
	
	
	
	
	
	
	
	
	
	
Register	
	
	
	
	
	
	
PC	
	
	
	
	
Memory	
	
	
	
	
	
	
	
        program	
	
	
	
	
	
	
	
	
	
	
	
Code
sto 0, s
sto 0, d
sto 0, c
sto 0, d
lod s, 0
lit “s”, 0
opr 14, 0
jmc #a1, false
lod b, 0	
	
	
	
	
	
	
	
	
	
	
	
	
Symbol  
Table
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11
Instructions
	
	
	
instruction first second
parameter parameter
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12
Instructions
•  LIT <value>, <register_id>
Put a constant value in a CPU register
Examples:
LIT 5, 0
LIT 5.5, 0
LIT 'a', 0
LIT ”hello”, 0
LIT true, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13
Instructions
•  LOD <variable>, <register_id>
Search for <variable> in the symbol table
Read its value
Put the value of <variable> in the CPU register
Examples:
LOD a, 0
LOD hello, 0
LOD cse340, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14
Instructions
•  STO <variable>, <register_id>
Read a value from the CPU register
Search for <variable> in the symbol table
Store the value into the variable
Examples:
STO a, 0
STO hello, 0
STO cse340, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15
Example
Source Code:	
{
int a; int b;
a = 10;
b = a;
Symbol Table:
Type Name Scope Value
int a global 0
int b global 0
Intermediate (Object) Code:
LIT 10,0
STO a,0
LOD a,0
STO b,0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16
Instructions
•  OPR <operation>, <register_id>
Read one or two values from the CPU register
Do the operation <operation>
Put the result into the CPU register
Examples:
OPR 1, 0 ; return
OPR 2, 0 ; add
OPR 3, 0 ; subtract
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17
Operations
Number Action
0 Exit program
1 Return
2 ADD: POP A, POP B, PUSH B+A
3 SUBTRACT: POP A, POP B, PUSH B-A
4 MULTIPLY: POP A, POP B, PUSH B*A
5 DIVIDE: POP A, POP B, PUSH B/A
6 MOD: POP A, POP B, PUSH (B mod A)
7 POW: POP A, POP B, PUSH (A to the power B)
8 OR: POP A, POP B, PUSH (B or A)
9 AND: POP A, POP B, PUSH (B and A)
10 NOT: POP A, PUSH (not A)
11 TEST GREATER THAN: POP A, POP B, PUSH (B>A)
12 TEST LESS THAN: POP A, POP B, PUSH (B<A)
13 TEST GREATER THAN OR EQUAL: POP A, POP B, PUSH (B>=A)
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18
Operations
Number Action
14 TEST LESS THAN OR EQUAL: POP A, POP B, PUSH (B<=A)
15 TEST EQUAL: POP A, POP B, PUSH (B=A)
16 TEST NOT EQUAL: POP A, POP B, PUSH (B<>A)
17
18 clear screen
19 read a value from the standard input
20 print a value to the standard output
21 print a value to the standard output and a newline character
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 19
Example
{
int a;
int b;
a = 10;
b = a;
a = a * 10;
b = 2 + 3 + 4;
}
Type Name Scope Value
int a global 0
int b global 0
LIT 10, 0
STO a, 0
LOD a, 0
STO b, 0
LOD a, 0
LIT 10, 0
OPR 4, 0 ; multiply
STO a, 0
LIT 2, 0
LIT 3, 0
OPR 2, 0 ; add
LIT 4, 0
OPR 2, 0 ; add
STO b, 0
OPR 1,0
OPR 0,0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 20
to be continued...
CSE340 - Principles of Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Summer 2015
Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.

More Related Content

What's hot

Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Ahmed Khateeb
 
Project on digital vlsi design
Project on digital vlsi designProject on digital vlsi design
Project on digital vlsi designDINESH DEVIREDDY
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in cVikas Dongre
 
Arithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded CArithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded CVikas Dongre
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluationJeeSa Sultana
 
Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4emailharmeet
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]ecko_disasterz
 
Code quailty metrics demystified
Code quailty metrics demystifiedCode quailty metrics demystified
Code quailty metrics demystifiedJeroen Resoort
 
Lecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorsLecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorseShikshak
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramidnayakq
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsAfaq Mansoor Khan
 
Machine language
Machine languageMachine language
Machine languagetrekalover
 

What's hot (20)

201506 CSE340 Lecture 15
201506 CSE340 Lecture 15201506 CSE340 Lecture 15
201506 CSE340 Lecture 15
 
Booth algorithm
Booth algorithmBooth algorithm
Booth algorithm
 
Prefix Postfix
Prefix PostfixPrefix Postfix
Prefix Postfix
 
201505 CSE340 Lecture 06
201505 CSE340 Lecture 06201505 CSE340 Lecture 06
201505 CSE340 Lecture 06
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)
 
Project on digital vlsi design
Project on digital vlsi designProject on digital vlsi design
Project on digital vlsi design
 
Lab 1
Lab 1Lab 1
Lab 1
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
 
201506 CSE340 Lecture 10
201506 CSE340 Lecture 10201506 CSE340 Lecture 10
201506 CSE340 Lecture 10
 
Arithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded CArithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded C
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
 
Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]
 
Code quailty metrics demystified
Code quailty metrics demystifiedCode quailty metrics demystified
Code quailty metrics demystified
 
Lecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorsLecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operators
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramid
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Machine language
Machine languageMachine language
Machine language
 

Viewers also liked

Viewers also liked (20)

Slides boekpresentatie 'Sociale Media en Journalistiek'
Slides boekpresentatie 'Sociale Media en Journalistiek'Slides boekpresentatie 'Sociale Media en Journalistiek'
Slides boekpresentatie 'Sociale Media en Journalistiek'
 
Thehub Milan Startup Weekend
Thehub   Milan Startup WeekendThehub   Milan Startup Weekend
Thehub Milan Startup Weekend
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和java
 
LiveOffice Email Archiving & Compliance 101
LiveOffice Email Archiving & Compliance 101LiveOffice Email Archiving & Compliance 101
LiveOffice Email Archiving & Compliance 101
 
Fun at the Sculpture Gardens with Ally and Lauren
Fun at the Sculpture Gardens with Ally and LaurenFun at the Sculpture Gardens with Ally and Lauren
Fun at the Sculpture Gardens with Ally and Lauren
 
Jay Cross
Jay CrossJay Cross
Jay Cross
 
Diego Ernesto Leal
Diego Ernesto LealDiego Ernesto Leal
Diego Ernesto Leal
 
201010 SPLASH Tutorial
201010 SPLASH Tutorial201010 SPLASH Tutorial
201010 SPLASH Tutorial
 
Week7
Week7Week7
Week7
 
Chapter 3 presentation
Chapter 3 presentationChapter 3 presentation
Chapter 3 presentation
 
Valvuloplastie
ValvuloplastieValvuloplastie
Valvuloplastie
 
Presentation
PresentationPresentation
Presentation
 
007 014 belcaro corrige
007 014 belcaro corrige007 014 belcaro corrige
007 014 belcaro corrige
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Angeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumesAngeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumes
 
Sanghamitra Iyengar - Índia
Sanghamitra  Iyengar - ÍndiaSanghamitra  Iyengar - Índia
Sanghamitra Iyengar - Índia
 
open office
open officeopen office
open office
 
Terofox v port catalogue (rev.01)
Terofox v port catalogue (rev.01)Terofox v port catalogue (rev.01)
Terofox v port catalogue (rev.01)
 
Gr trav f. risk cv s.metabolique
Gr trav f. risk cv s.metaboliqueGr trav f. risk cv s.metabolique
Gr trav f. risk cv s.metabolique
 
Corporate taxation introduction
Corporate taxation introductionCorporate taxation introduction
Corporate taxation introduction
 

Similar to 201506 CSE340 Lecture 20

Seminar on Digital Multiplier(Booth Multiplier) Using VHDL
Seminar on Digital Multiplier(Booth Multiplier) Using VHDLSeminar on Digital Multiplier(Booth Multiplier) Using VHDL
Seminar on Digital Multiplier(Booth Multiplier) Using VHDLNaseer LoneRider
 
Computer archi&mp
Computer archi&mpComputer archi&mp
Computer archi&mpMSc CST
 
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...ammarqazi53
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECERamesh Naik Bhukya
 
Microprocessor Part 3
Microprocessor    Part  3Microprocessor    Part  3
Microprocessor Part 3Sajan Agrawal
 
Lecture 03 Arithmetic Group of Instructions
Lecture 03 Arithmetic Group of InstructionsLecture 03 Arithmetic Group of Instructions
Lecture 03 Arithmetic Group of InstructionsZeeshan Ahmed
 
Patstat indicators step by step
Patstat indicators step by stepPatstat indicators step by step
Patstat indicators step by stepGianluca Tarasconi
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2HarshitParkar6677
 
Debugging para el no iniciado
Debugging para el no iniciadoDebugging para el no iniciado
Debugging para el no iniciadoLeonardo Jimenez
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsnoahjamessss
 

Similar to 201506 CSE340 Lecture 20 (20)

201506 CSE340 Lecture 14
201506 CSE340 Lecture 14201506 CSE340 Lecture 14
201506 CSE340 Lecture 14
 
Lab06
Lab06Lab06
Lab06
 
Seminar on Digital Multiplier(Booth Multiplier) Using VHDL
Seminar on Digital Multiplier(Booth Multiplier) Using VHDLSeminar on Digital Multiplier(Booth Multiplier) Using VHDL
Seminar on Digital Multiplier(Booth Multiplier) Using VHDL
 
201505 CSE340 Lecture 03
201505 CSE340 Lecture 03201505 CSE340 Lecture 03
201505 CSE340 Lecture 03
 
201801 CSE240 Lecture 07
201801 CSE240 Lecture 07201801 CSE240 Lecture 07
201801 CSE240 Lecture 07
 
201505 - CSE340 Lecture 01
201505 - CSE340 Lecture 01201505 - CSE340 Lecture 01
201505 - CSE340 Lecture 01
 
201506 - CSE340 Lecture 08
201506 - CSE340 Lecture 08201506 - CSE340 Lecture 08
201506 - CSE340 Lecture 08
 
Computer archi&mp
Computer archi&mpComputer archi&mp
Computer archi&mp
 
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECE
 
Microprocessor Part 3
Microprocessor    Part  3Microprocessor    Part  3
Microprocessor Part 3
 
Mcs 012 soved assignment 2015-16
Mcs 012 soved assignment 2015-16Mcs 012 soved assignment 2015-16
Mcs 012 soved assignment 2015-16
 
Sasin nisar
Sasin nisarSasin nisar
Sasin nisar
 
pic-prog-assembly.pdf
pic-prog-assembly.pdfpic-prog-assembly.pdf
pic-prog-assembly.pdf
 
Lecture 03 Arithmetic Group of Instructions
Lecture 03 Arithmetic Group of InstructionsLecture 03 Arithmetic Group of Instructions
Lecture 03 Arithmetic Group of Instructions
 
Patstat indicators step by step
Patstat indicators step by stepPatstat indicators step by step
Patstat indicators step by step
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2
 
Debugging para el no iniciado
Debugging para el no iniciadoDebugging para el no iniciado
Debugging para el no iniciado
 
Microcontroller- An overview
Microcontroller- An overviewMicrocontroller- An overview
Microcontroller- An overview
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
 

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 

201506 CSE340 Lecture 20

  • 1. CSE340 - Principles of Programming Languages Lecture 20: Intermediate Code I Javier Gonzalez-Sanchez BYENG M1-38 Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2 A Compiler in Action Lexer Parser Semantic   Analyzer Code   Generation Words Tokens Sentences Symbol table Uniqueness Type matching Translation Source Code è Intermediate Code Intermediate Code è Machine or Binary Code Analysis Compilation Assembly
  • 3. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3 Source Code { int a; int b; int c; int d; if (a != 5) { b = c + d; } print (a); }
  • 4. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4 Intermediate (Object) Code 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 a, 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 Symbol table Instructions
  • 5. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5 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
  • 6. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6 High-Level Languages X,E,G,O,O #e1,I,I,0,7 @ OPR 19, AX STO x, AX LIT 5, AX OPR 21, AX LOD #e1,AX CAL 1, AX OPR 0, AX 5 Virtual Machine (interpreter) // sorce code int x; int foo () { read (x); print (5); } main () { foo (); } Lexer Parser Semantic Analyzer Code Generation 01001010101000010 01010100101010010 10100100000011011 11010010110101111 00010010101010010 10101001010101011 Assembler compilation execution
  • 7. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7 High-Level Languages X,E,G,O,O #e1,I,I,0,7 @ OPR 19, AX STO x, AX LIT 5, AX OPR 21, AX LOD #e1,AX CAL 1, AX OPR 0, AX 5 Virtual Machine (interpreter) // sorce code int x; int foo () { read (x); print (5); } main () { foo (); } Lexer Parser Semantic Analyzer Code Generation 01001010101000010 01010100101010010 10100100000011011 11010010110101111 00010010101010010 10101001010101011 Assembler compilation execution
  • 8. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8 A Simple Virtual Machine CPU ALU Register Memory
  • 9. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9 Memory        program A Simple Virtual Machine CPU ALU Register Code sto 0, s sto 0, d sto 0, c sto 0, d lod s, 0 lit “s”, 0 opr 14, 0 jmc #a1, false lod b, 0 Symbol   Table
  • 10. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10 A Simple Virtual Machine CPU ALU Register PC Memory        program Code sto 0, s sto 0, d sto 0, c sto 0, d lod s, 0 lit “s”, 0 opr 14, 0 jmc #a1, false lod b, 0 Symbol   Table
  • 11. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11 Instructions instruction first second parameter parameter
  • 12. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12 Instructions •  LIT <value>, <register_id> Put a constant value in a CPU register Examples: LIT 5, 0 LIT 5.5, 0 LIT 'a', 0 LIT ”hello”, 0 LIT true, 0
  • 13. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13 Instructions •  LOD <variable>, <register_id> Search for <variable> in the symbol table Read its value Put the value of <variable> in the CPU register Examples: LOD a, 0 LOD hello, 0 LOD cse340, 0
  • 14. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14 Instructions •  STO <variable>, <register_id> Read a value from the CPU register Search for <variable> in the symbol table Store the value into the variable Examples: STO a, 0 STO hello, 0 STO cse340, 0
  • 15. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15 Example Source Code: { int a; int b; a = 10; b = a; Symbol Table: Type Name Scope Value int a global 0 int b global 0 Intermediate (Object) Code: LIT 10,0 STO a,0 LOD a,0 STO b,0
  • 16. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16 Instructions •  OPR <operation>, <register_id> Read one or two values from the CPU register Do the operation <operation> Put the result into the CPU register Examples: OPR 1, 0 ; return OPR 2, 0 ; add OPR 3, 0 ; subtract
  • 17. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17 Operations Number Action 0 Exit program 1 Return 2 ADD: POP A, POP B, PUSH B+A 3 SUBTRACT: POP A, POP B, PUSH B-A 4 MULTIPLY: POP A, POP B, PUSH B*A 5 DIVIDE: POP A, POP B, PUSH B/A 6 MOD: POP A, POP B, PUSH (B mod A) 7 POW: POP A, POP B, PUSH (A to the power B) 8 OR: POP A, POP B, PUSH (B or A) 9 AND: POP A, POP B, PUSH (B and A) 10 NOT: POP A, PUSH (not A) 11 TEST GREATER THAN: POP A, POP B, PUSH (B>A) 12 TEST LESS THAN: POP A, POP B, PUSH (B<A) 13 TEST GREATER THAN OR EQUAL: POP A, POP B, PUSH (B>=A)
  • 18. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18 Operations Number Action 14 TEST LESS THAN OR EQUAL: POP A, POP B, PUSH (B<=A) 15 TEST EQUAL: POP A, POP B, PUSH (B=A) 16 TEST NOT EQUAL: POP A, POP B, PUSH (B<>A) 17 18 clear screen 19 read a value from the standard input 20 print a value to the standard output 21 print a value to the standard output and a newline character
  • 19. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 19 Example { int a; int b; a = 10; b = a; a = a * 10; b = 2 + 3 + 4; } Type Name Scope Value int a global 0 int b global 0 LIT 10, 0 STO a, 0 LOD a, 0 STO b, 0 LOD a, 0 LIT 10, 0 OPR 4, 0 ; multiply STO a, 0 LIT 2, 0 LIT 3, 0 OPR 2, 0 ; add LIT 4, 0 OPR 2, 0 ; add STO b, 0 OPR 1,0 OPR 0,0
  • 20. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 20 to be continued...
  • 21. CSE340 - Principles of Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Summer 2015 Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.