Download presentation

Presentation is loading. Please wait.

Published byLisbeth Artley Modified over 2 years ago

1
Recitation 1 Session 5 + handout Ishani Chakraborty

2
Switch statement Multi-way branching. Implemented through data structure called Jump Table. A Jump Table is an array where entry i is the address of the code implemented if switch index = i.

3
Preferred over if-else if Number of cases > 4. Range of values is small.

4
switch(n) { case 0: P1printf("You typed zero\n"); break; case 1: case 9: P2printf("n is a perfect square\n"); break; case 2: P3printf("n is an even number\n"); default: P4printf("Only single-digit numbers are allowed\n"); break; } Addr of instruction P1 Addr of instruction P2 Addr of ……… instruction P3 Addr of instruction P2 Addr of instruction P4 Jump Table: Resides somewhere in memory, address obtained from dissembled code 019Def2 switch_logical(n) { if (n>9) goto instruction for default goto jt[n]); …… } jt[10] = { Addr(P1), Addr(P2), Addr(P3), Addr(default), Addr(default), Addr(P4) }

5
switch(n) { case 100: P1printf("You typed zero\n"); break; case 101: case 109: P2printf("n is a perfect square\n"); break; case 102: P3printf("n is an even number\n"); default: P4printf("Only single-digit numbers are allowed\n"); break; } Addr of instruction P1 Addr of instruction P2 Addr of ……… instruction P3 Addr of instruction P2 Addr of instruction P4 Jump Table: Resides somewhere in memory, address obtained from dissembled code 019Def2 switch_logical(n) { n_i = n-100; if (n_i>9) goto instruction for default goto jt[n_i]); …… } jt[10] = { Addr(P1), Addr(P2), Addr(P3), Addr(default), Addr(default), Addr(P4) }

Similar presentations

Presentation is loading. Please wait....

OK

1 CS 201 Compiler Construction Lecture 1 Introduction.

1 CS 201 Compiler Construction Lecture 1 Introduction.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on particle size distribution curve Ppt on quality education data Ppt on landscape photography Ppt on tata trucks new Ppt on antimicrobial activity of ginger Ppt on carbon and its compounds ppt Ppt on pivot table in excel 2007 Ppt on project tiger for class 10 Ppt on first conditional grammar Ppt on natural resources conservation