CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Some Basics.

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Lecture 7  Fundamental data types in C  Data type conversion:  Automatic  Casting  Character processing  getchar()  putchar()  Macros on ctype.h.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Structure of a C program
1 Integral Data Types in C. 2 First lecture response sent out Lots of good questions Some questions will be punted to reading when appropriate 3 statements.
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Data types and variables
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
Chapter 2 Data Types, Declarations, and Displays
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Professor Jennifer Rexford COS 217
1 Integral Data Types in C Professor Jennifer Rexford
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Chapter Introduction to Computers and Programming 1.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Computers Organization & Assembly Language
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Structured Programming Approach Module III - Expressing Algorithm Sequence Module IV - Concept of scalar Data Types Prof: Muhammed Salman Shamsi.
Introduction to Computer Systems and the Java Programming Language.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
1 C++ Syntax and Semantics, and the Program Development Process.
Week 1 Algorithmization and Programming Languages.
Lecture12. Outline Binary representation of integer numbers Operations on bits –The Bitwise AND Operator –The Bitwise Inclusive-OR Operator –The Bitwise.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Bitwise Operators Fall 2008 Dr. David A. Gaitros
These notes were originally developed for CpSc 210 (C version) by Dr. Mike Westall in the Department of Computer Science at Clemson.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
Data Types and Operations On Data Objective To understand what data types are The need to study data types To differentiate between primitive types and.
 2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
CS115 FALL Senem KUMOVA-METİN1 The Fundamental Data Types CHAPTER 3.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
CSE 351 Number Representation & Operators Section 2 October 8, 2015.
Module B - Computation1/61 Module-B-Computation Variables Basic Memory Operations Expressions.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
C Part 1 Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens A History Lesson Development of language by Dennis Ritchie at Bell.
C is a high level language (HLL)
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.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
CompSci From bits to bytes to ints  At some level everything is stored as either a zero or a one  A bit is a binary digit a byte is a binary.
From bits to bytes to ints
Lec 3: Data Representation
The Machine Model Memory
Variables Mr. Crone.
Documentation Need to have documentation in all programs
C Structures, Unions, Bit Manipulations and Enumerations
Computer Organization & Compilation Process
Introduction to Programming
How Computers Work Part 1 6 February 2008.
Primitive Types and Expressions
Computer Organization & Compilation Process
C Language B. DHIVYA 17PCA140 II MCA.
Lecture 2: Bits, Bytes, Ints
Getting Started With Coding
Presentation transcript:

CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Some Basics

CS1372: HELPING TO PUT THE COMPUTING IN ECE Computer Numbers Binary Two's complement Hexadecimal

CS1372: HELPING TO PUT THE COMPUTING IN ECE What are the components? Processor -- Does math, logic, testing (=0) Memory -- Stores data AND program –Also is where program interfaces with I/O devices Input -- Gameboy has 10 pushbuttons Output –Video screen –Sound

CS1372: HELPING TO PUT THE COMPUTING IN ECE Machine Model Processor Memory Video Controller Display Sound Controller Speakers/ Jacks Button Controller Buttons

CS1372: HELPING TO PUT THE COMPUTING IN ECE Light Up a Pixel

CS1372: HELPING TO PUT THE COMPUTING IN ECE REG_DISPCNT F0E0D0C0B0A Mode BG0BG1BG2BG3 Bits 0-2 Mode (at 0X ) –0,1,2 Tile Modes –3, 4, 5 Bitmap Modes For bitmapped graphics use BG2

CS1372: HELPING TO PUT THE COMPUTING IN ECE REG_DISPCNT F0E0D0C0B0A Mode BG0BG1BG2BG3 Bits 0-2 Mode –0,1,2 Tile Modes –3, 4, 5 Bitmap Modes For bitmapped graphics use BG = = = 1027

CS1372: HELPING TO PUT THE COMPUTING IN ECE Video Memory (in Mode 3) Located at 0x Consists of 240 x bit shorts

CS1372: HELPING TO PUT THE COMPUTING IN ECE Let's Light Up a Pixel int main(void) { *(unsigned short *)0x = 1027; *(unsigned short *)0x = 32767; while(1) { } return 0; }

CS1372: HELPING TO PUT THE COMPUTING IN ECE Structure of C Program C programs consist of one or more files Each file may contain 0 or more functions Executable code must appear in functions Other items such as definitions, variable declarations, typedefs, etc may appear outside of functions. Where a variable is declared will affect where it is in memory, its scope and lifetime. C is compiled with a somewhat odd preprocessing step.

CS1372: HELPING TO PUT THE COMPUTING IN ECE C Datatypes integers –int –short –long –unsigned floating point –float –double characters –char

CS1372: HELPING TO PUT THE COMPUTING IN ECE “Build your Own Language” C is such a primitive language that we frequently need to expand its vocabulary in order to make code more understandable: typedef creates new data types (affects the compiler) #define is a preprocessor directive – modifies your source code before compilation

CS1372: HELPING TO PUT THE COMPUTING IN ECE typedef Allows you to define your own aliases for types Syntax: typedef Example –unsigned short is a valid c-type –So we can create out own alias using typedef unsigned short u16;

CS1372: HELPING TO PUT THE COMPUTING IN ECE C Logical Operators && || !

CS1372: HELPING TO PUT THE COMPUTING IN ECE Bitwise Operators & | ~ ^ >> <<

CS1372: HELPING TO PUT THE COMPUTING IN ECE While we're at it...

CS1372: HELPING TO PUT THE COMPUTING IN ECE Memory: Bits, Bytes, Words Memory consists of individual bits which may have a value of 0 or 1 but The smallest quantity of bits we can access is 8. This is known as a byte Bytes have address that increment by 1 Other data items which consist of groups of bytes have addresses which increment depending on the number of bytes –e.g. Shorts are 2 bytes long so their addresses are multiples of 2

CS1372: HELPING TO PUT THE COMPUTING IN ECE Addresses Addresses are usually expressed as hexadecimal numbers There are gaps in the address space Some areas of memory may be accessed as bytes, shorts and ints while others may only be accessed as shorts and ints –8, 16, 32 –16, 32

CS1372: HELPING TO PUT THE COMPUTING IN ECE Bit Vectors Storing multiple values (as individual bits or groups of bits) is known as a bit vector Bit vectors are used to save space Bit vectors are used extensively in GBA programming especially with I/O The key to bit vectors is the bitwise operations

CS1372: HELPING TO PUT THE COMPUTING IN ECE How would we set a bit? Assume bits are numbered like this: – To set bit 3 of x where x is an 8 bit quantity x = x | (1 << 3) To set bit n of x where x is an 8 bit quantity x = x | (1 << n) Note: Use | and not +

CS1372: HELPING TO PUT THE COMPUTING IN ECE How would we clear a bit? Assume bits are numbered like this: – To clear bit 3 of x where x is an 8 bit quantity x = x & ~(1 << 3) To clear bit n of x where x is an 8 bit quantity x = x & ~(1 << n) Note: Use & and not -

CS1372: HELPING TO PUT THE COMPUTING IN ECE How would we test a bit? Assume bits are numbered like this: – To test bit 3 of x where x is an 8 bit quantity if( x & (1 << 3) ) To set bit n of x where x is an 8 bit quantity if( x & (1 << n) ) If the desired bit is set, the expression will evaluate to true (i.e. In C, not zero)

CS1372: HELPING TO PUT THE COMPUTING IN ECE How can we put two values in one variable???? Assume we have a 16 bit short int called x and an unsigned char called y. We wish to replace the left half of x (8 high order bits) with y leaving the right half (8 low order bits) intact x = (x & 0xFF) | (y<<8);

CS1372: HELPING TO PUT THE COMPUTING IN ECE How can we put two values in one variable???? Assume we have a 16 bit short int called x and an unsigned char called y. We wish to replace the right half of x (8 low order bits) with y leaving the left half (8 high order bits) intact x = (x & 0xFF00) | y;

CS1372: HELPING TO PUT THE COMPUTING IN ECE How can we put three values in one variable? Color values are often stored in the GBA as 3 (Red, Green and Blue) five bit values packed into one unsigned short. xBBBBBGGGGGRRRRR We can code: R | G<<5 | B<<10 OR B<<10 | G<<5 | R Or as a macro #define COLOR(R, G, B) (R)|(G)<<5|(B)<<10

CS1372: HELPING TO PUT THE COMPUTING IN ECE Questions?