# Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

Size: px
Start display at page:

Download "Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion"

Transcription

1 CS 61C: Great Ideas in Computer Architecture Lecture 2: Numbers & C Language Krste Asanović & Randy Katz Numbers wrap-up This is not on the exam! Break C Primer Administrivia, Break C Type declarations And in Conclusion, 2 Recap: Binary Number Conversion Binary à Decimal two =?ten Binary Digit Decimal Value 0 0 x 2 0 = x 2 1 = x 2 2 = x 2 3 = x 2 4 = x 2 5 = x 2 6 = 64 S = 4ten Decimal à Binary 4ten Decimal =?two Binary (odd?) 4 0 /2 = 3 1 /2 = 18 0 /2 = 9 1 /2 = 4 0 /2 = 2 0 /2 = 1 1 Collect à two 3 Signed Integer Representation How to represent -5? Sign & magnitude (8-bit example): sign -bit magnitude (0 12) Rules for addition, a + b: If (a>0 and b>0): add b to a If (a>0 and b<0): subtract b from a +0, -0 à are they equal? If so, comparator must handle special case! (If not equal???) Cumbersome Complicated hardware: reduced speed / increased power Is there a better way? 4 Going backwards by going forwards How to add -1 to a four-bit number? 0111 two = ten???? two + = -1 ten 0110 two = 6 ten Going backwards by going forwards Add 10000two and throw away fifth bit, result unchanged Result wraps around to same value 0111 two = ten two + = 16 ten two = ten +16 ten 0111 two = ten 5 6 1

2 Going backwards by going forwards Add (10000 two 1 two = two ) and throw away fifth bit One less than original value 0111 two = ten two + = 16-1 ten two = ten 0110 two = 6 ten Decimal bit Example Binary Map negative à positive numbers Example for N=4-bit: -3 à = 13 Two s complement No special rules for adding positive and negative numbers Extra bit is ignored as doesn t fit in 4 bits = 16 8/29/1 8 Two s Complement (8-bit example) As Signed Decimal As Unsigned Decimal Binary Number Most-significant bit (MSB) equals sign when interpreted as a signed number Signed versus Unsigned Binary Numbers Both are stored as a collection of bits The same set of bits can be used to represent a signed number or an unsigned number (or a string, or a picture, or a.) It s up to the operation interpreting the bits 1101 two = +13 ten (as an unsigned number) 1101 two = -3 ten (as a signed number) 1101 two = orange (as a color) 1101 two = cat (as a type of animal) 1101 two = whatever you want it to mean 9 10 Unary Negation (Two s Complement) 4-bit Example (-8 ten + ten ) Brute Force & Tedious largest 4-bit number ten two - 3 ten two 13 ten 1101 two 16 ten two - 13 ten two Clever & Elegant 15 ten two - 3 ten two 12 ten 1100 two invert + 1 ten two 13 ten 1101 two Your Turn What is the decimal value of the following binary 8-bit 2 s complement number? two Answer RED ORANGE GREEN YELLOW Value 33 ten -31 ten 225 ten -33 ten

4 8/29/1 Your Turn Which range of decimals can be expressed with a 6-bit two s complement number? Answer Range RED GREEN ORANGE YELLOW Numbers wrap-up This is not on the exam! Break C Primer Administrivia, Break C Type declarations And in Conclusion, HotChips 201: Brains & Dinosaurs Top conference introducing new processor chips Z14, IBM Mainframe, 50+ years on

5 Break! 8/29/1 Fall Lecture #2 25 Numbers wrap-up This is not on the exam! Break C Primer Administrivia, Break C Type declarations And in Conclusion, 26 Levels of Representation High Level Language Program (e.g., C) Compiler Assembly Language Program (e.g., RISC-V) Assembler Machine Language Program (RISC-V) Machine Interpretation Hardware Architecture Description (e.g., block diagrams) Architecture Implementation Logic Circuit Description (Circuit Schematic Diagrams) temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; lw t0, 0(s2) lw t1, 4(s2) sw t1, 0(s2) sw t0, 4(s2) Current Focus Anything can be represented as a number, i.e., data or instructions Introduction to C The Universal Assembly Language Languages used in 61C: C Assembly Python used in two labs Prior programming experience helpful, e.g. Java C++ 28 Survey Hello World C Who has never written a program in Java or C, C++, Objective-C? Java

6 Compilation & Running \$ gcc HelloWorld.c \$./a.out Hello World! \$ 31 C Compilation Simplified Overview (more later in course) foo.c Compiler foo.o Linker a.out bar.c Compiler bar.o C source files (text) Machine code object files lib.o Pre-built object file libraries Machine code executable file Compiler/assembler combined here 32 Compilation versus Interpretation C (compiled) Compiler (& linker) translates source into machine language Machine language program is loaded by OS and directly executed by the hardware Python (interpreted) Interpreter is written in some high-level language (e.g. C) and translated into machine language Loaded by OS and directly executed by processor Interpreter reads source code (e.g. Python) and interprets it 33 Java Byte Code Java compiler (javac) translates source to byte code Byte code is a particular assembly language - Just like i86, RISC-V, ARM, - Can be directly executed by appropriate machine implementations exist(ed), not commercially successful - More typically, byte code is interpreted on target machine (e.g. i86) by java program compiled to target machine code (e.g. by JIT) - Program runs on any computer with a byte code interpreter (more or less) 34 Compilation Excellent run-time performance: - Much faster than interpreted code (e.g. Python) - Usually faster than Java (even with JIT) Note: Computers only run machine code - Compiled application program, or - Interpreter (that interprets source code) Compilation: Disadvantages Compiled files, including the executable, are - architecture-specific, depending on processor type e.g., RISC-V vs. ARM - and the operating system e.g., Windows vs. Linux Executable must be rebuilt on each new system - I.e., porting your code to a new architecture Change Compile Run [repeat] iteration cycle can be slow during development - Recompile only parts of program that have changed - Tools (e.g. make) automate this

7 8/29/1 C Dialects C Pre-Processor (CPP) \$ gcc x.c foo.c \$ gcc ansi Wpedantic x.c 3 38 Administratrivia Numbers wrap-up This is not on the exam! Break C Primer Administrivia, Break C Type declarations And in Conclusion, Compiler C source files pass through macro processor, CPP, before compilation CPP replaces comments with a single space CPP commands begin with # #include file.h /* Inserts file.h */ #include <stdio.h> /* Loads from standard loc */ #define M_PI ( ) /* Define constant */ #if/#endif /* Conditional inclusion of text */ Use save-temps option to gcc to see result of preprocessing Full documentation at: foo.i CPP Notify us of all known variances - DSP special accommodations: head TA (Steven Ho) - Exam conflicts: Fill out the form on Piazza (special accommodations can be made only in exceptional cases) - If you cannot get an instructional account, head TA Notify head TA by Tuesday, 9/5/201 - see 39 Break! 40 Numbers wrap-up This is not on the exam! Break C Primer Administrivia, Break C Type declarations And in Conclusion, 8/29/1 Fall Lecture #

8 int a = 4; float f = 1.38e; char c = x ; Typed Variables in C Declare before use Type cannot change Like Java Type Description Examples int integers, positive or negative 0, 82, -, 0xAB8 unsigned int ditto, no negatives 0, 8, 3 float (single precision) floating point 3.2, -.9e-10 char text character or symbol x, F,? double high precision/range float 1.3e100 long integer with more bits Constants and Enummerations in C Constants - Assigned in typed declaration, cannot change - E.g. const float pi = ; const unsigned long addr = 0xaf460; Enumerations Integers: Python vs. Java vs. C Language sizeof(int) Python >=32 bits (plain ints), infinite (long ints) Java 32 bits C Depends on computer; 16 or 32 or 64 C: int - integer type that target processor works with most efficiently Only guarantee: - sizeof(long long) sizeof(long) sizeof(int) sizeof(short) - Also, short >= 16 bits, long >= 32 bits - All could be 64 bits Impacts portability between architectures 45 Variable Sizes: Machine Dependent! sizeof... (bytes) char: 1 short: 2 int: 4 unsigned int: 4 long: 8 long long: 8 float: 4 double: 8 46 Boolean No boolean datatype in C - Declare if you wish: typedef int boolean; const boolean false = 0; const boolean true = 1; What evaluates to FALSE in C? - 0 (integer) - NULL (a special kind of pointer: more on this later) What evaluates to TRUE in C? - Anything that isn t false is true - Similar to Python: only 0 s or empty sequences are false, everything else is true! 4 int number_of_people() { } return 3; void news() { } printf( no news ); int sum(int x, int y) { } return x + y; Functions in C Like Java Declare return & argument types void for no value returned Functions MUST be declared before they are used 48 8

9 Code Uninitialized Variables Output \$ gcc test.c \$./a.out x = 0 x = 1680 x = -4 x = x = -16 Struct s in C Struct s are structured groups of variables A bit like Java classes, but no methods E.g More C And In Conclusion, Lecture does not cover C completely - You ll still need your C reference for this course - K&R, The C Programming Language - & other references on the course website Next few lectures focus: - Pointers & Arrays - Memory management Signed integers represented in 2 s complement C Programming Language - Popular (still!) - Similar to Java, but no classes explicit pointers (next lecture) - Beware variables not initialized variable size (# of bits) is machine & compiler dependent C is compiled to machine code - Unlike Python or Java, which are interpreted - Compilation is faster than interpretation

### CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

CS 61C: Great Ideas in Computer Architecture Lecture 2: Numbers & C Language Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Numbers wrap-up This is not on the exam! Break C Primer Administrivia,

### CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

CS 110 Computer Architecture Lecture 2: Introduction to C, Part I Instructor: Sören Schwertfeger http://shtech.org/courses/ca/ School of Information Science and Technology SIST ShanghaiTech University

### CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

CS 110 Computer Architecture Lecture 2: Introduction to C, Part I Instructor: Sören Schwertfeger http://shtech.org/courses/ca/ School of Information Science and Technology SIST ShanghaiTech University

### CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I

CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda Everything is a Number

### Number Representation & I See The C

Number Representation & I See The C 1 Signed Integers and Two s-complement Representation Signed integers in C; want ½ numbers 0, and want one 0 Two s complement treats 0 as positive,

### CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I

CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I Instructors: Vladimir Stojanovic & John Wawrzynek http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda Compile vs. Interpret

### CS 61C: Great Ideas in Computer Architecture Introduction to C

CS 61C: Great Ideas in Computer Architecture Introduction to C Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda C vs. Java vs. Python Quick Start Introduction

### CS 102 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

CS 102 Computer Architecture Lecture 2: Introduction to C, Part I Instructor: Sören Schwertfeger http://shtech.org/courses/ca/ School of Information Science and Technology SIST ShanghaiTech University

### Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011

Two s Complement Review CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part I) Instructor: Michael Greenbaum http://inst.eecs.berkeley.edu/~cs61c/su11 Suppose we had

### CS 61c: Great Ideas in Computer Architecture

Introduction to C, Pointers June 24, 2014 Review of Last Lecture Six Great Ideas in Computer Architecture Number Representation Bits can represent anything! n bits can represent up to 2 n things Unsigned,

### CS 61C: Great Ideas in Computer Architecture Introduc=on to C, Part I. We are here!

Agenda CS 61C: Great Ideas in Computer Architecture Introduc=on to C, Part I Instructors: Krste Asanovic Randy H. Katz hgp://inst.eecs.berkeley.edu/~cs61c/f12 Review Compile vs. Interpret Python vs. Java

### CS 61c: Great Ideas in Computer Architecture

Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address

### CS Programming In C

CS 24000 - Programming In C Week Two: Basic C Program Organization and Data Types Zhiyuan Li Department of Computer Science Purdue University, USA 2 int main() { } return 0; The Simplest C Program C programs

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

CS61C L2 Number Representation & Introduction to C (1) insteecsberkeleyedu/~cs61c CS61C : Machine Structures Lecture #2 Number Rep & Intro to C Scott Beamer Instructor 2007-06-26 Review Continued rapid

### Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture

### C: Introduction, Pointers Instructors: Steven Ho, Nick Riasanovsky

C: Introduction, Pointers Instructors: Steven Ho, Nick Riasanovsky Overflow Overflow is when the result of an arithmetic operation can t be represented by the (FINITE) hardware bits i.e. the result is

### CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/sp16 1 Machine Interpretation

### CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and RISC-V Instruction Set Architecture

CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and RISC-V Instruction Set Architecture Instructors: Krste Asanović & Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c 9/7/17

### Agenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture

CS 61C: Great Ideas in Computer Architecture Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c And in Conclusion, 2 Processor Control Datapath Components of a Computer PC Registers Arithmetic

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

CS61C Machine Structures Lecture 3 Introduction to the C Programming Language 1/23/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L03 Introduction to C (1) Administrivia

### CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz

CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic

### Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer

CS 61C: Great Ideas in Computer Architecture Everything is a Number Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13 9/19/13 Fall 2013 - - Lecture #7 1 New- School Machine Structures

### CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro 1 Levels of Representation/Interpretation Machine Interpretation High Level Language Program (e.g., C) Compiler Assembly

### C - Basics, Bitwise Operator. Zhaoguo Wang

C - Basics, Bitwise Operator Zhaoguo Wang Java is the best language!!! NO! C is the best!!!! Languages C Java Python 1972 1995 2000 (2.0) Procedure Object oriented Procedure & object oriented Compiled

### Inf2C - Computer Systems Lecture 2 Data Representation

Inf2C - Computer Systems Lecture 2 Data Representation Boris Grot School of Informatics University of Edinburgh Last lecture Moore s law Types of computer systems Computer components Computer system stack

### P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

### Number review... Lecture 3 Introduction to the C Programming Language (pt 1) Has there been an update to ANSI C?

CS61C L03 Introduction to C (pt 1) (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 3 Introduction to the C Programming Language (pt 1) 2008-01-28 Lecturer SOE Dan Garcia Hello to Dev

### Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

### Declaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.

Declaration Fundamental Data Types All variables must be declared before being used. Tells compiler to set aside an appropriate amount of space in memory to hold a value. Enables the compiler to perform

### But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

Integer Representation Representation of integers: unsigned and signed Sign extension Arithmetic and shifting Casting But first, encode deck of cards. cards in suits How do we encode suits, face cards?

### Operations, Operands, and Instructions

Operations, Operands, and Instructions Tom Kelliher, CS 220 Sept. 12, 2011 1 Administrivia Announcements Assignment Read 2.6 2.7. From Last Time Macro-architectural trends; IC fab. Outline 1. Introduction.

### CS61C : Machine Structures

Get your clickers ready...! inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 3 Introduction to the C Programming Language (pt 1) 2013-01-28! Hello to Nishant Varma watching from India!!!Senior

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 3 Introduction to the C Programming Language (pt 1)!!Lecturer SOE Dan Garcia!!!www.cs.berkeley.edu/~ddgarcia CS61C L03 Introduction to C

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 2 Introduction to the C Programming Language (pt 1) 2010-06-22!!!Instructor Paul Pearce! There is a handout at the front of the room! Please

### PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

### CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers

CS 61C: Great Ideas in Computer Architecture C Arrays, Strings, More Pointers Instructor: Justin Hsia 6/20/2012 Summer 2012 Lecture #3 1 Review of Last Lecture C Basics Variables, Functions, Flow Control,

### 6.096 Introduction to C++ January (IAP) 2009

MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

### CS 261 Fall Mike Lam, Professor Integer Encodings

CS 261 Fall 2018 Mike Lam, Professor https://xkcd.com/571/ Integer Encodings Integers Topics C integer data types Unsigned encoding Signed encodings Conversions Integer data types in C99 1 byte 2 bytes

### CS 61C: Great Ideas in Computer Architecture More RISC-V Instructions and How to Implement Functions

CS 61C: Great Ideas in Computer Architecture More RISC-V Instructions and How to Implement Functions Instructors: Krste Asanović and Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa17 9/14/17 Fall

### CS 61C: Great Ideas in Computer Architecture RISC-V Instruction Formats

CS 61C: Great Ideas in Computer Architecture RISC-V Instruction Formats Instructors: Krste Asanović and Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa17 9/14/17 Fall 2017 - Lecture #7 1 Levels of

### 9/14/17. Levels of Representation/Interpretation. Big Idea: Stored-Program Computer

CS 61C: Great Ideas in Computer Architecture RISC-V Instruction Formats Instructors: Krste Asanović and Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa17 Fall 2017 - Lecture #7 1 Levels of Representation/Interpretation

### A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

### Topics Introduction to Microprocessors

Topics 22440 Introduction to Microprocessors C-Language Review (I) Important: : You will not learn how to code in C in this one lecture! You ll still need some sort of C reference. C Syntax Important Tidits

### CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduc)on to C (Part I) We are here!

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduc)on to C (Part I) Instructors: Randy H. Katz David A. PaGerson hgp://inst.eecs.berkeley.edu/~cs61c/sp11 Summary Spring 2011 - -

### World Inside a Computer is Binary

C Programming 1 Representation of int data World Inside a Computer is Binary C Programming 2 Decimal Number System Basic symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Radix-10 positional number system. The radix

### Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Appendix F Number Systems Binary Numbers Decimal notation represents numbers as powers of 10, for example 1729 1 103 7 102 2 101 9 100 decimal = + + + There is no particular reason for the choice of 10,

### CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static

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

CS61C L2 Number Representation & Introduction to C (1) insteecsberkeleyedu/~cs61c CS61C : Machine Structures Lecture #2 Number Rep & Intro to C 2005-08-31 There is one handout today at the front and back

### CS61C Machine Structures. Lecture 8 - Introduction to the MIPS Processor and Assembly Language. 9/14/2007 John Wawrzynek

CS61C Machine Structures Lecture 8 - Introduction to the MIPS Processor and Assembly Language 9/14/2007 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L08 C Introduction

### CS61C : Machine Structures

Get your clickers ready...! inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 3 Introduction to the C Programming Language (pt 1)!!Senior Lecturer SOE Dan Garcia!!!www.cs.berkeley.edu/~ddgarcia

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #2 Number Rep & Intro to C 2005-08-31 There is one handout today at the front and back of the room! Lecturer PSOE, new dad Dan Garcia www.cs.berkeley.edu/~ddgarcia

### Introduction to C. Systems Programming Concepts

Introduction to C Systems Programming Concepts Introduction to C A simple C Program Variable Declarations printf ( ) Compiling and Running a C Program Sizeof Program #include What is True in C? if example

### ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

ECE 250 / CS 250 Computer Architecture C to Binary: Memory & Data Representations Benjamin Lee Slides based on those from Alvin Lebeck, Daniel Sorin, Andrew Hilton, Amir Roth, Gershon Kedem Administrivia

### CS107, Lecture 3 Bits and Bytes; Bitwise Operators

CS107, Lecture 3 Bits and Bytes; Bitwise Operators reading: Bryant & O Hallaron, Ch. 2.1 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons Attribution

### CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

### C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

### Data III & Integers I

Data III & Integers I CSE 351 Autumn 2018 Instructor: Justin Hsia Teaching Assistants: Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie

### Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

### Lecture 3. More About C

Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

### Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

### Chapter 3. Fundamental Data Types

Chapter 3. Fundamental Data Types Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr Variable Declaration

### Lecture 3: Instruction Set Architecture

Lecture 3: Instruction Set Architecture CSE 30: Computer Organization and Systems Programming Summer 2014 Diba Mirza Dept. of Computer Science and Engineering University of California, San Diego 1. Steps

### CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

### Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics

### C Introduction. Comparison w/ Java, Memory Model, and Pointers

CS 261 Fall 2018 Mike Lam, Professor C Introduction Comparison w/ Java, Memory Model, and Pointers Please go to socrative.com on your phone or laptop, choose student login and join room LAMJMU The C Language

### Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C

Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison

### CS 31: Intro to Systems Binary Arithmetic. Martin Gagné Swarthmore College January 24, 2016

CS 31: Intro to Systems Binary Arithmetic Martin Gagné Swarthmore College January 24, 2016 Unsigned Integers Suppose we had one byte Can represent 2 8 (256) values If unsigned (strictly non-negative):

### Data Type Fall 2014 Jinkyu Jeong

Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants

### Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

### Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

CS 150 Introduction to Computer Science I Data Types Today Last we covered o main function o cout object o How data that is used by a program can be declared and stored Today we will o Investigate the

### Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

### Programming. Data Structure

Programming & Data Structure For Computer Science & Information Technology By www.thegateacademy.com Syllabus Syllabus for Programming and Data Structures Programming in C, Arrays, Stacks, Queues, Linked

### Jin-Soo Kim Systems Software & Architecture Lab. Seoul National University. Integers. Spring 2019

Jin-Soo Kim (jinsoo.kim@snu.ac.kr) Systems Software & Architecture Lab. Seoul National University Integers Spring 2019 4190.308: Computer Architecture Spring 2019 Jin-Soo Kim (jinsoo.kim@snu.ac.kr) 2 A

### AGENDA Binary Operations CS 3330 Samira Khan

AGENDA Binary Operations CS 3330 Logistics Review from last Lecture Samira Khan University of Virginia Jan 31, 2017 Binary Operations Logical Operations Bitwise Operations Examples 2 Feedbacks Quizzes

### Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine

### CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

CS 220: Introduction to Parallel Computing Beginning C Lecture 2 Today s Schedule More C Background Differences: C vs Java/Python The C Compiler HW0 8/25/17 CS 220: Parallel Computing 2 Today s Schedule

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

Outline of Introduction Administrivia What is computer architecture? What do computers do? Representing high level things in binary Data objects: integers, decimals, characters, etc. Memory locations (We

### Lecture 7: Examples, MARS, Arithmetic

Lecture 7: Examples, MARS, Arithmetic Today s topics: More examples MARS intro Numerical representations 1 Dealing with Characters Instructions are also provided to deal with byte-sized and half-word quantities:

### Programming refresher and intro to C programming

Applied mechatronics Programming refresher and intro to C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2018 Outline 1 C programming intro 2

### advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation

### Bits, Bytes, and Integers Part 2

Bits, Bytes, and Integers Part 2 15-213: Introduction to Computer Systems 3 rd Lecture, Jan. 23, 2018 Instructors: Franz Franchetti, Seth Copen Goldstein, Brian Railing 1 First Assignment: Data Lab Due:

### Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with

### C-string format with scanf/printf

CSI333 Lecture 4 C-string format with scanf/printf char mycstring[4]; int intvar; scanf("%3s", &intvar ); /*reads up to 3 chars and stores them PLUS \0 in the 4-byte var. intvar*/ scanf("%3s", mycstring);

### DEPARTMENT OF MATHS, MJ COLLEGE

T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

### Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

### Computer Organization & Systems Exam I Example Questions

Computer Organization & Systems Exam I Example Questions 1. Pointer Question. Write a function char *circle(char *str) that receives a character pointer (which points to an array that is in standard C

CS 33 Data Representation, Part 1 CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Number Representation Hindu-Arabic numerals developed by Hindus starting in

### THE FUNDAMENTAL DATA TYPES

THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include

### Integers II. CSE 351 Autumn Instructor: Justin Hsia

Integers II CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/571/

### Data III & Integers I

Data III & Integers I CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Everyone has VM

### CSCI 171 Chapter Outlines

Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

### M1 Computers and Data

M1 Computers and Data Module Outline Architecture vs. Organization. Computer system and its submodules. Concept of frequency. Processor performance equation. Representation of information characters, signed

### Survey. Motivation 29.5 / 40 class is required

Survey Motivation 29.5 / 40 class is required Concerns 6 / 40 not good at examination That s why we have 3 examinations 6 / 40 this class sounds difficult 8 / 40 understand the instructor Want class to

### CS 253. January 14, 2017

CS 253 Department of Computer Science College of Engineering Boise State University January 14, 2017 1/30 Motivation Most programming tasks can be implemented using abstractions (e.g. representing data

### Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Carnegie Mellon 1 Bits, Bytes and Integers Part 1 15-213/18-213/15-513: Introduction to Computer Systems 2 nd Lecture, Aug. 31, 2017 Today s Instructor: Randy Bryant 2 Announcements Recitations are on

### BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

### The C Programming Language Guide for the Robot Course work Module

The C Programming Language Guide for the Robot Course work Module Eric Peasley 2018 v6.4 1 2 Table of Contents Variables...5 Assignments...6 Entering Numbers...6 Operators...7 Arithmetic Operators...7