Recitation 1 Session 5 + handout Ishani Chakraborty.

Slides:



Advertisements
Similar presentations
Switch code for Lab 4.2 switch (input) { /* input is a variable that we will test. */ case 'M': printf("The prefix is equal to 1E6.\n"); break; case 'k':
Advertisements

Numerical Recipes The Art of Scientific Computing (with some applications in computational physics)
Control Statements. Define the way of flow in which the program statements should take place. Control Statements Implement decisions and repetitions.
Decisions If statements in C.
CENG 311 Decisions in C/Assembly Language
MIPS assembly. Review  Lat lecture, we learnt  addi,  and, andi, or, ori, xor, xori, nor,  beq, j, bne  An array is stored sequentially in the memory.
CS/COE0447 Computer Organization & Assembly Language
The University of Adelaide, School of Computer Science
Intermediate Code Generation. 2 Intermediate languages Declarations Expressions Statements.
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Comp Sci Control structures 1 Ch. 5 Control Structures.
Generation of Intermediate Code Compiler Design Lecture (03/30//98) Computer Science Rensselaer Polytechnic.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
Chapter 7Louden, Programming Languages1 Chapter 7 - Control I: Expressions and Statements "Control" is the general study of the semantics of execution.
Homework Any Questions?. Statements / Blocks, Section 3.1 An expression becomes a statement when it is followed by a semicolon x = 0; Braces are used.
Control Flow C and Data Structures Baojian Hua
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
1 CS 201 Compiler Construction Lecture 1 Introduction.
true (any other value but zero) false (zero) expression Statement 2
Toward a general purpose computer II Example: Game of Life.
Conditionals, Loops, and Other Statements CS-2301, B-Term Conditionals, Loops, and Other Kinds of Statements CS-2301, System Programming for Non-Majors.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
CPS120: Introduction to Computer Science Decision Making in Programs.
1 Homework / Exam Turn in HW3 today Exam 1 next class –Open Book / Open Notes –Recommended Use of Book / Notes in Exam: Avoids reliance on “rote memorization”
Lecture 15: 10/24/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
CIS 3301 C# Lesson 3 Control Statements - Selection.
CISC105 – General Computer Science Class 8 – 06/28/2006.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
CPS120: Introduction to Computer Science Decision Making in Programs.
תרגול 5 תכנות באסמבלי, המשך
CDA 3101 Spring 2016 Introduction to Computer Organization
Computer Organization Instructions Language of The Computer (MIPS) 2.
CPS120: Introduction to Computer Science Decision Making in Programs.
The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Engineering Computing I Chapter 3 Control Flow. Chapter 3 - Control Flow The control-flow of a language specify the order in which computations are performed.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic3: Instructions, The Language of the Machine José Nelson Amaral.
Program Control: Selection Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
CS 108 Computing Fundamentals Notes for Thursday, February 18, 2016.
Programming Techniques
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Program Control: Selection Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
Instruction Set Architectures Continued. Expanding Opcodes & Instructions.
Standard 14 Solve by completing the square. Example One. Instructions: Factor Perfect Square.
Lesson #4 Logical Operators and Selection Statements.
Lesson #4 Logical Operators and Selection Statements.
Switch Statement Pre-requisites: 1D array addressing Updated 7/11/2013.
Chapter 5 The if Statement
16.317: Microprocessor System Design I
Compound Condition Break , Continue Switch Statements in Java
Unit-1 Introduction to Java
Microprocessor Systems Design I
Computer Architecture & Operations I
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Control Structures.
Lecture 3 CPU - Data Path for Branches
Week 6 The darkness, the loop of negative thoughts on repeat, clamours and interferes with the music I hear in my head. Lady Gaga.
الكلية الجامعية للعلوم التطبيقية
Three Address Code Generations for Boolean Functions
Machine-Level Programming: Control Flow
Introduction to Programming
Homework Any Questions?.
Systems Architecture I
MIPS Assembly.
Structured Programming
MIPS assembly.
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Presentation transcript:

Recitation 1 Session 5 + handout Ishani Chakraborty

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.

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

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) }

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) }