SlideShare a Scribd company logo
1 of 34
CSE340 - Principles of
Programming Languages
Lecture 22:
Intermediate Code III
Javier Gonzalez-Sanchez
BYENG M1-38
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3
Review
Programming Assignment 4
Level 1
LIT, LOD, STO, OPR
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4
Code
PROGRAM
OPR 0, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5
Code
BODY
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6
Code
PRINT
OPR 21, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7
Code
ASSIGNMENT
STO identifier, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8
Code
VARIABLE
identifier, <type>
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9
Code
RETURN
OPR 1, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10
Parser
EXPRESSION
if (twice) {
OPR 8, 0
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11
Parser
X
if (twice) {
OPR 9, 0
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12
Parser
Y
if (operatorUsed) {
OPR 10, 0
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13
Parser
R
if (twice) {
OPR <operatorNumber>, 0
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14
Parser
E
if (twice) {
OPR <operatorNumber>, 0
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15
Parser
A
if (twice) {
OPR <operatorNumber>, 0
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16
Parser
B
if (operatorUsed) {
OPR 3, 0
}
LIT 0, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17
Assignment 2 | Code
C
LIT <value>, 0
LOD identifier, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18
Review
Programming Assignment 4
Level 2
JMP, JMC
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 19
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
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 20
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
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 21
Example
{
int a; int b;
a = 10;
while (a>1){
print (a);
}
return;
}
int a global 0
int b global 0
@
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
OPR 1, 0
OPR 0, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 22
Labels
•  Compiler creates variables and adds them to the
symbol table to remember positions in the code.
•  This is useful for loops and conditions.
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 23
Labels | how while works
while (a < b) {
//code
}
label#1
if (a < b) {
//code
} else
goto label#2
}
goto label#1
label #2
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 24
Labels | how if works
if (a < b) {
//code1
} else {
// code2
}
if (a < b) {
if (a>b) goto label #1
//code1
} else
goto label#2
label #1
// code2
}
label #2
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 25
Example | while
{
int a; int b;
a = 10;
while (a>1){
print (a);
}
return;
}
int a global 0
int b global 0
int #e1 global 10
int #e2 global 3
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
OPR 1, 0
OPR 0, 0
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 26
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
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 27
Exercise
{
int a; int b;
a = 10;
while (a>1) {
if (a != 0) {
print (a);
} else {
print (b);
}
a = a -1;
}
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 28
Handwritten notes
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 29
Code
WHILE
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 30
Code
IF
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 31
What about a switch-case
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 32
Handwritten notes
Add the symbol table here…
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 33
Homework
Translate this source code to intermediate code:
int a, b;
switch (a) {
case 1: { b = 11; break;}
case 2: { b = 22; break;}
case 3: { b = 33; break;}
default:{ b = 99; break;}
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 34
Homework
Assignment #4
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 (10)

201505 CSE340 Lecture 06
201505 CSE340 Lecture 06201505 CSE340 Lecture 06
201505 CSE340 Lecture 06
 
201506 CSE340 Lecture 14
201506 CSE340 Lecture 14201506 CSE340 Lecture 14
201506 CSE340 Lecture 14
 
201506 CSE340 Lecture 10
201506 CSE340 Lecture 10201506 CSE340 Lecture 10
201506 CSE340 Lecture 10
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
 
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
 
201506 CSE340 Lecture 15
201506 CSE340 Lecture 15201506 CSE340 Lecture 15
201506 CSE340 Lecture 15
 
Pi Controller
Pi ControllerPi Controller
Pi Controller
 
201506 CSE340 Lecture 11
201506 CSE340 Lecture 11201506 CSE340 Lecture 11
201506 CSE340 Lecture 11
 
201506 CSE340 Lecture 09
201506 CSE340 Lecture 09201506 CSE340 Lecture 09
201506 CSE340 Lecture 09
 
C++ questions
C++ questionsC++ questions
C++ questions
 

Viewers also liked

Twitter voor journalisten
Twitter voor journalistenTwitter voor journalisten
Twitter voor journalistenBart Van Belle
 
Thehub Milan Startup Weekend
Thehub   Milan Startup WeekendThehub   Milan Startup Weekend
Thehub Milan Startup WeekendThe Hub Milan
 
Elalamy DiabèTe Et Aap Sfa 2009
Elalamy DiabèTe Et Aap Sfa 2009Elalamy DiabèTe Et Aap Sfa 2009
Elalamy DiabèTe Et Aap Sfa 2009sfa_angeiologie
 
200801 Generating OpenMP and Pthreads code
200801 Generating OpenMP and Pthreads code200801 Generating OpenMP and Pthreads code
200801 Generating OpenMP and Pthreads codeJavier Gonzalez-Sanchez
 
RCMSL Phenomenal July 2, 2009
RCMSL Phenomenal July 2, 2009RCMSL Phenomenal July 2, 2009
RCMSL Phenomenal July 2, 2009etalcomendras
 
Tax planning introduction fall 2012
Tax planning introduction fall 2012Tax planning introduction fall 2012
Tax planning introduction fall 2012dphil002
 
Itf ipp ch08_2012_final
Itf ipp ch08_2012_finalItf ipp ch08_2012_final
Itf ipp ch08_2012_finaldphil002
 
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 resumessfa_angeiologie
 
Livre resumes 2007 angeio
Livre resumes 2007 angeioLivre resumes 2007 angeio
Livre resumes 2007 angeiosfa_angeiologie
 
Paul Harris Fellow Clubs En
Paul Harris Fellow Clubs EnPaul Harris Fellow Clubs En
Paul Harris Fellow Clubs Enetalcomendras
 
Technologische trends voor journalistiek
Technologische trends voor journalistiekTechnologische trends voor journalistiek
Technologische trends voor journalistiekBart Van Belle
 
Urban Cottage + IceMilk Aprons
Urban Cottage + IceMilk ApronsUrban Cottage + IceMilk Aprons
Urban Cottage + IceMilk ApronsIceMilk Aprons
 

Viewers also liked (20)

Jay Cross Vivo Versao Final Corrigida
Jay Cross Vivo Versao Final CorrigidaJay Cross Vivo Versao Final Corrigida
Jay Cross Vivo Versao Final Corrigida
 
201505 CSE340 Lecture 02
201505 CSE340 Lecture 02201505 CSE340 Lecture 02
201505 CSE340 Lecture 02
 
Week7
Week7Week7
Week7
 
Twitter voor journalisten
Twitter voor journalistenTwitter voor journalisten
Twitter voor journalisten
 
Thehub Milan Startup Weekend
Thehub   Milan Startup WeekendThehub   Milan Startup Weekend
Thehub Milan Startup Weekend
 
Elalamy DiabèTe Et Aap Sfa 2009
Elalamy DiabèTe Et Aap Sfa 2009Elalamy DiabèTe Et Aap Sfa 2009
Elalamy DiabèTe Et Aap Sfa 2009
 
200801 Generating OpenMP and Pthreads code
200801 Generating OpenMP and Pthreads code200801 Generating OpenMP and Pthreads code
200801 Generating OpenMP and Pthreads code
 
RCMSL Phenomenal July 2, 2009
RCMSL Phenomenal July 2, 2009RCMSL Phenomenal July 2, 2009
RCMSL Phenomenal July 2, 2009
 
Tax planning introduction fall 2012
Tax planning introduction fall 2012Tax planning introduction fall 2012
Tax planning introduction fall 2012
 
Diapositivas
DiapositivasDiapositivas
Diapositivas
 
201204 AME High Five
201204 AME High Five201204 AME High Five
201204 AME High Five
 
Itf ipp ch08_2012_final
Itf ipp ch08_2012_finalItf ipp ch08_2012_final
Itf ipp ch08_2012_final
 
199912 outsight
199912 outsight199912 outsight
199912 outsight
 
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
 
Livre resumes 2007 angeio
Livre resumes 2007 angeioLivre resumes 2007 angeio
Livre resumes 2007 angeio
 
Paul Harris Fellow Clubs En
Paul Harris Fellow Clubs EnPaul Harris Fellow Clubs En
Paul Harris Fellow Clubs En
 
Technologische trends voor journalistiek
Technologische trends voor journalistiekTechnologische trends voor journalistiek
Technologische trends voor journalistiek
 
Urban Cottage + IceMilk Aprons
Urban Cottage + IceMilk ApronsUrban Cottage + IceMilk Aprons
Urban Cottage + IceMilk Aprons
 
007 014 belcaro corrige
007 014 belcaro corrige007 014 belcaro corrige
007 014 belcaro corrige
 
201107 ICALT
201107 ICALT201107 ICALT
201107 ICALT
 

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

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2
 

Recently uploaded (20)

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 

201506 CSE340 Lecture 22

  • 1. CSE340 - Principles of Programming Languages Lecture 22: Intermediate Code III Javier Gonzalez-Sanchez BYENG M1-38 Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3 Review Programming Assignment 4 Level 1 LIT, LOD, STO, OPR
  • 3. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4 Code PROGRAM OPR 0, 0
  • 4. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5 Code BODY
  • 5. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6 Code PRINT OPR 21, 0
  • 6. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7 Code ASSIGNMENT STO identifier, 0
  • 7. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8 Code VARIABLE identifier, <type>
  • 8. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9 Code RETURN OPR 1, 0
  • 9. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10 Parser EXPRESSION if (twice) { OPR 8, 0 }
  • 10. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11 Parser X if (twice) { OPR 9, 0 }
  • 11. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12 Parser Y if (operatorUsed) { OPR 10, 0 }
  • 12. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13 Parser R if (twice) { OPR <operatorNumber>, 0 }
  • 13. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14 Parser E if (twice) { OPR <operatorNumber>, 0 }
  • 14. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15 Parser A if (twice) { OPR <operatorNumber>, 0 }
  • 15. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16 Parser B if (operatorUsed) { OPR 3, 0 } LIT 0, 0
  • 16. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17 Assignment 2 | Code C LIT <value>, 0 LOD identifier, 0
  • 17. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18 Review Programming Assignment 4 Level 2 JMP, JMC
  • 18. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 19 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
  • 19. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 20 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
  • 20. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 21 Example { int a; int b; a = 10; while (a>1){ print (a); } return; } int a global 0 int b global 0 @ 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 OPR 1, 0 OPR 0, 0
  • 21. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 22 Labels •  Compiler creates variables and adds them to the symbol table to remember positions in the code. •  This is useful for loops and conditions.
  • 22. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 23 Labels | how while works while (a < b) { //code } label#1 if (a < b) { //code } else goto label#2 } goto label#1 label #2
  • 23. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 24 Labels | how if works if (a < b) { //code1 } else { // code2 } if (a < b) { if (a>b) goto label #1 //code1 } else goto label#2 label #1 // code2 } label #2
  • 24. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 25 Example | while { int a; int b; a = 10; while (a>1){ print (a); } return; } int a global 0 int b global 0 int #e1 global 10 int #e2 global 3 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 OPR 1, 0 OPR 0, 0
  • 25. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 26 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
  • 26. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 27 Exercise { int a; int b; a = 10; while (a>1) { if (a != 0) { print (a); } else { print (b); } a = a -1; } }
  • 27. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 28 Handwritten notes
  • 28. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 29 Code WHILE
  • 29. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 30 Code IF
  • 30. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 31 What about a switch-case
  • 31. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 32 Handwritten notes Add the symbol table here…
  • 32. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 33 Homework Translate this source code to intermediate code: int a, b; switch (a) { case 1: { b = 11; break;} case 2: { b = 22; break;} case 3: { b = 33; break;} default:{ b = 99; break;} }
  • 33. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 34 Homework Assignment #4
  • 34. 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.