CSE 12 Week Three Lecture One Tomorrow s discussion: Getting started on hw4

Similar documents
Result: original lp in main is. Goal was.

CSE 12 Spring 2018 Week One, Lecture Two

CSE 12 Spring 2016 Week One, Lecture Two

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

CSE 12 Week Eight, Lecture One

CSE 12 Week Eight, Lecture Two

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

SIGNED AND UNSIGNED SYSTEMS

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Variables and Data Representation

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

Final CSE 131B Spring 2004

CSE 351 Midterm - Winter 2017

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

CSE 582 Autumn 2002 Exam 11/26/02

CSE 374 Programming Concepts & Tools

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Intermediate Code Generation

Lecture 5 Tao Wang 1

Programming refresher and intro to C programming

CSE P 501 Exam 8/5/04

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CS133 C Programming. Instructor: Jialiang Lu Office: Information Center 703

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

Introduction to Programming (Java) 2/12

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Java Fall 2018 Margaret Reid-Miller

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

Programming with Java

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins)

CS 61c: Great Ideas in Computer Architecture

CS 241 Data Organization Binary

These are notes for the third lecture; if statements and loops.

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

UNIT- 3 Introduction to C++

Java Programming. Atul Prakash

Absolute C++ Walter Savitch

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Project Data: Manipulating Bits

Chapter 3: Operators, Expressions and Type Conversion

Project Compiler. CS031 TA Help Session November 28, 2011

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

Administration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP

Introduction to Computer Organization. Final Exam Summer 2017

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Fundamental of Programming (C)

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

printf( Please enter another number: ); scanf( %d, &num2);

LAB A Translating Data to Binary

EECE.2160: ECE Application Programming

Compiler, Assembler, and Linker

Introduction. Interpreters High-level language intermediate code which is interpreted. Translators. e.g.

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

CS33 Project Gear Up. Data

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output

Fundamentals of Programming Session 2

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Fundamentals of Programming

WARNING for Autumn 2004:

The Warhol Language Reference Manual

More Programming Constructs -- Introduction

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

DEPARTMENT OF MATHS, MJ COLLEGE

CSE 351 Midterm - Winter 2015 Solutions

Full file at

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

CS16 Exam #1 7/17/ Minutes 100 Points total

CSE 351 Midterm - Winter 2015

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Presented By : Gaurav Juneja

Inf2C - Computer Systems Lecture 2 Data Representation

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

cast int( x float( x str( x hex( int string int oct( int string int bin( int string int chr( int int ord( ch

The Design of C: A Rational Reconstruction"

Expressions and Assignment

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

CS 61c: Great Ideas in Computer Architecture

Introduction to C Programming. What is a C program?

CSE 113 A. Announcements - Lab

Inheritance: Develop solutions by abstracting real-world object and their interaction into code to develop software solutions. Layering: Organization

Semantic Analysis. Lecture 9. February 7, 2018

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

A flow chart is a graphical or symbolic representation of a process.

Unit 3. Operators. School of Science and Technology INTRODUCTION

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

JAVA OPERATORS GENERAL

CS313D: ADVANCED PROGRAMMING LANGUAGE

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Transcription:

CSE 12 Week Three Lecture One Tomorrow s discussion: Getting started on hw4 Finishing content from last Tuesday Ex in 4 bits, signed addition: 1 bit of sign, 3 bits of magnitude 0101: 5 + 0110: +6 ------- -- Problem: Overflow a bit of magnitude or. 0100: flip + 1: add one ------- Observation: overflow occurred: o o o When a computer program produces overflow what happens? Ans: Ramifications:.

Bit manipulation: shifting and masking What: operations on ints/longs/chars that perform bit-by-bit comparisons, result based on the operation performed. Where: C, C++, Java Masking: bit-by-bit comparison, only a portion of the source shows through. NOT ~ ~0 => 1, ~1 => 0 Bits in action: src: 1010 1010 ~src: Example in code: dst = Intuition: Use: AND: & 1&1 => 1, else => 0 Bits in action: src: 1010 1010 &mask: 1111 0000 dst: Example in code: dst = ; Intuition: ANDing w/ 1s =>, ANDing w/0s => Use:, Practical Use: Extract one hexadecimal digit from a number in a hexout method: digit = number & 0x????????; // extracts last digit number: &mask: digit: 0x12345678 0x????????? => digit extracted

OR 0 0 => 0, else 1 Bits in action: scr: 1010 1010 mask: 1111 0000 dst: Intuition: ORing w/ 1s =>, ORing w/0s => Use: Practical Use: Convert a decimal digit to ASCII: code = digit 0 ; // 7 0x30 => 0x37 7 scr: 0000 0111 mask:?????????? dst: => ASCII code for 7 XOR ^ 0^1 => 1, 1^0=> 1, else 0 Bits in action: scr: 1010 1010 ^mask: 1111 0000 dst: Intuition: XORing w/ 1s =>, XORing w/0s => Practical Use: - - - puzzle: xxx ^= yyy; yyy^=xxx; xxx^=yyy;

Shifting: Source value shifting by an amount in bits >> right shift << left shift Ex: 3: 6: // 3 shifted by bit to the 12: // 3 shifted by to the 24: // 3 shifted by to the 48: // 3 shifted by to the Shifting left by powers of, Shifting right by powers of Ex: in decimal: 123 x 100 = 12,300 Ternary operator: if-then-else expression (condition)? true_value : false value Ex: aaa = (bbb == 10)? 20 : 30; // same as: if ( ) aaa = ; else aaa = ; Reversing stack1 onto stack2: while ( ) { ; ; ; }

How to declare and initialize an array: int array[] = {1,2,3,4,5,6,7}; Parallel arrays: What: Two (or more) arrays that share the same : For us:, Compiler Behavior - What is a compiler? - Ans: o o - What do we want a compiler to do for us? - Ans: o o Compiler errors: 1) Lexical errors: Input is not recognized as legal in terms of basic symbols. - First errors the compiler identifies a. b. c. d. English: 2) Parse errors or Syntax errors: Group of tokens is legal, but the order is unexpected. a. b. English:

3) Semantic error: Structure is legal, but your statement doesn t make sense. a. b. c. d. English: 4) Warning: The compiler will do as you ask, but not not necessarily as you want. - in CSE 12, we will compile without warnings a. b. c. d. e. English: 5) Advice: All errors beyond the first are based on the compiler making a guess at what your meant: a. Guess was good: Error message is. b. Guess was wrong: Error message is. c. Therefore correct the first few messages and compile again d. Therefore don t even look at 20 th message Run-Time Errors: What: Your program asked to do the impossible. Ex: if (10/0) - access memory that is out of range. - result: in C/C++, in Java - The core file: o A run-time image of your program in execution just before you asked to do the impossible. o Often very large files (consume entire quota) o What good is it? The can read it o gdb a.out core o where tell the line of problem.

Side note: Desire to remove core file, xxx.o: student types (note the extra unwanted space after the * before the.o: rm core *.o * is expanded by UNIX to match all files in current directory, and they will all be removed. make clean // safely remove core, exe,.class,.o make backup // copies source into a backup directory Logic Errors: The program does what you ask, not what you want. - Most of your time will be spent here. Ex: Output is wrong. Ex: infinite loop. Ex: extra output of display.

CSE 12 Week Three Discussion Two intopost example: 00 2 4 2 6 4 // priorities ((27 + 452) * 2 16 ^ 2) / 7 <ret> What: What: stack 1 stack 2 eval example: What: What: stack 1 stack 2 To represent a calculator word for an operator, you need all of the following all together in one long (word): 1. : to distinguish an operator from a number 2. : -> to display to the user

3. : -> used in intopost logic 4. : -> which function to execute Inside eval, you will use the functions array to evaluate each part of the expression. long eval (.) { long op1, op2, word;// for the operands and operator result = ; // word -> originated from a stack it s the operator } You are NOT going to have a switch/case statement switch (operator) { case + : NO!!! case - : NO!!! } ungetting characters: What: intopost and decin will need to put characters back into when they read a character not processed directly by the function. Why: So that the character can be processed by the processing function. For example, must read the entire number. When: - decin (provided) reads a for to process. - intopost (you do) reads a for to process.

Obtaining the priority from the index: index Symbol 0 ( 1 ) 2 + 3-4 * 5 / 6 ^ 7 blank 8!. The setupword function: What: Your constructor function to create the long to be used as the operator to be able to store on your stacks - the calculator word. How: + results in: binary:

hexadecimal: To get started with some code: long setupword (char character) { } Note: are magic numbers - grader takes off Better: #define #define Accessor methods on the calculator word: What:,, extract what creates. Example use of can be found in eval notes above. Please keep in mind: Only the following goes on the stacks in intopost : - return values from: o o

o NO EXCEPTIONS!!! If you forget, you will have errors!!!