mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut

Similar documents
CSC231 C Tutorial Fall 2018 Introduction to C

by Pearson Education, Inc. All Rights Reserved.

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

Intermediate Programming, Spring 2017*

CSC209H Lecture 4. Dan Zingaro. January 28, 2015

C: Arrays, and strings. Department of Computer Science College of Engineering Boise State University. September 11, /16

C programming basics T3-1 -

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

mith College Computer Science CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut

C Programming Language Review and Dissection III

Iosif Ignat, Marius Joldoș Laboratory Guide 9. Character strings CHARACTER STRINGS

SYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University

Course organization. Course introduction ( Week 1)

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Create a Program in C (Last Class)

Chapter 8: Character & String. In this chapter, you ll learn about;

Computer Programming: Skills & Concepts (CP) Strings

Chapter 8 - Characters and Strings

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Reading Assignment. Strings. K.N. King Chapter 13. K.N. King Sections 23.4, Supplementary reading. Harbison & Steele Chapter 12, 13, 14

Introduction to string

8. Characters, Strings and Files

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb

mith College Computer Science CSC231 C Tutorials Fall 2017 Introduction to C Dominique Thiébaut

Computers Programming Course 11. Iulian Năstac

C: How to Program. Week /May/28

C-LANGUAGE CURRICULAM

BSM540 Basics of C Language

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

Chapter 8 C Characters and Strings

PRINCIPLES OF OPERATING SYSTEMS

PDS Class Test 2. Room Sections No of students

CS 222: Pointers and Manual Memory Management

C Characters and Strings

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

CS1100 Introduction to Programming

C mini reference. 5 Binary numbers 12

Chapter 9 Strings. With this array declaration: char s[10];

1 Pointer Concepts. 1.1 Pointer Examples

Lecture 10 Arrays (2) and Strings. UniMAP SEM II - 11/12 DKT121 1

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

CSC 2400: Computer Systems. Arrays and Strings in C

Structured programming

Chapter 8 Character Arrays and Strings

ONE DIMENSIONAL ARRAYS

Strings. Arrays of characters. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY

Characters and Strings

Arrays, Strings, & Pointers

CSC 2400: Computer Systems. Arrays and Strings in C

Dynamic memory allocation

Introduction to C/C++ Lecture 5 - String & its Manipulation

CS107 Spring 2019, Lecture 4 C Strings

Exercise 1.1 Hello world

Scientific Programming in C V. Strings

Dynamic Memory Allocation and Command-line Arguments

CS 61c: Great Ideas in Computer Architecture

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

Announcements. assign0 due tonight. Labs start this week. No late submissions. Very helpful for assign1

Object-Oriented Programming

Chapter 5. Section 5.4 The Common String Library Functions. CS 50 Hathairat Rattanasook

C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review

CS107, Lecture 4 C Strings

Multiple Choice Questions ( 1 mark)

Basic and Practice in Programming Lab7

C Programming Multiple. Choice

Computers Programming Course 10. Iulian Năstac

Chapter 21: Introduction to C Programming Language

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

CSCI 6610: Intermediate Programming / C Chapter 12 Strings

Intermediate Programming, Spring 2017*

A brief introduction to C programming for Java programmers

Overview. Concepts this lecture String constants Null-terminated array representation String library <strlib.h> String initializers Arrays of strings

Contents. A Review of C language. Visual C Visual C++ 6.0

Characters, Character Strings, and string-manipulation functions in C

1/31/2018. Overview. The C Programming Language Part 2. Basic I/O. Basic I/O. Basic I/O. Conversion Characters. Input/Output Structures and Arrays

Using Character Arrays. What is a String? Using Character Arrays. Using Strings Life is simpler with strings. #include <stdio.

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

mith College Computer Science CSC231 C Tutorials Fall 2017 Introduction to C Dominique Thiébaut

The C Programming Language Part 2. (with material from Dr. Bin Ren, William & Mary Computer Science)

today cs3157-fall2002-sklar-lect05 1

Lecture07: Strings, Variable Scope, Memory Model 4/8/2013

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

Fundamentals of Programming & Procedural Programming

UNIT 6. STRUCTURED DATA TYPES PART 1: ARRAYS

Built-in Functions for NTCAs.

C Libraries. Bart Childs Complementary to the text(s)

Fundamental of Programming (C)

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

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub

Lectures 5-6: Introduction to C

C Style Strings. Lecture 11 COP 3014 Spring March 19, 2018

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

ARRAYS(II Unit Part II)

Lecture 02 C FUNDAMENTALS

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Contents. Preface. Introduction. Introduction to C Programming

211: Computer Architecture Summer 2016

Approximately a Test II CPSC 206

Transcription:

mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut dthiebaut@smithedu

Outline A Few Words about HW 8 Finish the Input Port Lab!

Revisiting Homework 8

6811 E A15 A14 A13 A2 A1 A0 Part 1 3-to-8 E' A2 A1 A0 Y0' Y1' Y2' Y3' Y4' Y5' Y6' Y7' D D Sd Cd Sd Q Q Q D7 D6 D0 Cd Q R/W D Sd Q Turn the Green LED On without changing the state of the others Cd Q

6811 E A15 A14 A13 Part 1 A2 A1 A0 D7 D6 D0 3-to-8 E' A2 A1 A0 Y0' Y1' Y2' Y3' Y4' Y5' Y6' Y7' 3-to-8 E' A2 A1 A0 Y0' Y1' Y2' Y3' Y4' Y5' Y6' Y7' D D Sd Cd Sd Cd Sd Q Q Q Q R/W D Q Turn the Green LED On without changing the state of the others Cd Q

6811 E A15 A14 A13 A2 A1 A0 Part 2 3-to-8 E' A2 A1 A0 Y0' Y1' Y2' Y3' Y4' Y5' Y6' Y7' D7 D6 D0 D Sd Cd Q Q R/W Send 50 0-1 pulses as fast as possible

6811 E A15 A14 A13 A2 A1 A0 Part 2 Puzzle! 3-to-8 E' A2 A1 A0 Y0' Y1' Y2' Y3' Y4' Y5' Y6' Y7' Assume E's frequency is 1MHz Figure out a way to send 50 0-1 pulses in 100 usec! D7 D6 D0 D Sd Cd Q Q R/W

6811 E A15 A14 A13 A2 A1 A0 Part 2 Puzzle! 3-to-8 E' A2 A1 A0 Y0' Y1' Y2' Y3' Y4' Y5' Y6' Y7' Figure out a way to send 50 0-1 pulses in 100 cycles! D7 D6 D0 D Sd Cd Q Q R/W

Let s Stop HERE! Start the Lab!

Outline A Few Words about HW 8 Finish the Input Port Lab! Flexibility General Purpose IO Learning C The Arduino < download the IDE http://wwwarduinocc/en/main/software

6811 E A15 A14 A13 A2 A1 A0 Part 2 Puzzle! 3-to-8 E' A2 A1 A0 Y0' Y1' Y2' Y3' Y4' Y5' Y6' Y7' Assume E's frequency is 1MHz Figure out a way to send 50 0-1 pulses in 100 usec! D7 D6 D0 D Sd Cd Q Q R/W

Sd D Q Q Cd Logic LDAA #1 STAA 8000 JMP START

General Purpose I/O

E' A2 A1 A0 D Sd Q Q Cd Sd D Q Q Cd R/W' D0

E' A2 A1 A0 D Sd Q Q Cd Sd D Q Q Cd R/W' D0

E' A2 A1 A0 D Sd Q Q Cd Sd D Q Q Cd R/W' D0

E' A2 A1 A0 D Sd Q Q Cd Sd D Q Q Cd R/W' D0

http://wwwtutorialspointcom/compile_c_onlinephp C Tutorial

References Online C Compiler wwwtutorialspointcom/ compile_c_onlinephp https://ideonecom/ Web Tutorial http://wwwphysicsdrexeledu/courses/ Comp_Phys/General/C_basics/ c_tutorialhtml http://wwwprogramizcom/cprogramming Kernighan & Ritchie http://wwwimeuspbr/~pf/kernighan-ritchie/ C-Programming-Ebookpdf

Hello World!

Comments // this is a one-line comment /* this is a comment too */ /* this is a multi-line comment */

Variables & Types int -> integer variable short -> short integer (short int) long -> long integer (long int) float -> single precision real (floating point) variable double -> double precision real (floating point) variable char -> character variable (single byte) qualifiers: unsigned -> applies to ints const -> variable cannot be modified

Variables & Types int -> integer variable short -> short integer (short int) long -> long integer (long int) float -> single precision real (floating point) variable double -> double precision real (floating point) variable char -> character variable (single byte) qualifiers: unsigned -> applies to ints const -> variable cannot be modified No Booleans!

Output #include <sdtioh> printf( format, [variables], [literals] ); %nd > integer (optional n = number of columns) %mnf > float or double (optional m = number of columns, n = number of decimal places) %ns > string (optional n = number of columns) %c > character \n \t > new line, tab

(Chars are ints too!)

Input #include <sdtioh> scanf( format, [variables] ); %d > integer (optional n = number of columns) %f > float or double (optional m = number of columns, n = number of decimal places) %s > string (optional n = number of columns) %c > character (won't work with tutorials point's online IDE but will on https://ideonecom/)

Using IDEOne

Input #include <sdtioh> char c; c = getchar(); (won't work with tutorials point's online IDE but will on https://ideonecom/)

Loops while ( boolean expression ) { } for ( expr1; expr2; expr3 ) { } break; // break out of inner loop continue; // return to beginning of // inner loop

We stopped here last time That's the end of the Lab report

Exercise Use a loop to print all the letters of the alphabet

Use a loop to print the first 10 Fibonaccis 1, 1, 2, Exercise

Pointers! int a = 3; int* p = 0;

Pointers! int a = 3; int* p = 0; p 0 a 3

Pointers! int a = 3; int* p = 0; p 10FCB23 p = &a; a 3

Pointers! int a = 3; int* p = 0; p 10FCB23 p = &a; a = a + 1; a 3 4

Pointers! int a = 3; int* p = 0; p 10FCB23 p = &a; a = a + 1; *p = 5; a 3 4 5

Arrays int arr[4]; arr[0] = 1; arr[1] = 10; arr[2] = 3; 100 3 arr[3] = 100; 3 2 10 1 arr 1 0

Arrays int arr[4]; arr[0] = 1; arr[1] = 10; arr[2] = 3; 100 3 arr[3] = 100; 3 2 10 1 arr 1 0 An array variable is a pointer to the first cell of the array

Arrays int arr[4]; int *p; arr[0] = 1; arr[1] = 10; arr[2] = 3; arr[3] = 100; p = arr; *p = 99; *(p+2) = 65; arr 100 3 10 1 3 2 1 0 An array variable is a pointer to the first cell of the array

Exercise Store the 10 first Fibonaccis in an array using indexes

Exercise Store the 10 first Fibonaccis in an array using pointers

// prototypes void hello(); int main(); Functions void hello() { } printf( "Hello World!\n" ); int main() { hello(); return 0; }

// prototypes void printnice(int); int main(); Functions Passing Parameters void printnice( int a ) { } printf( $%d00\n, a ); int main() { int dollars = 100; printnice( dollars ); return 0; }

// prototypes void increment( ); int main(); Functions Passing Parameters void increment( ) { a = a + 1; } int main() { int amount = 100; increment( amount ); return 0; }

Exercise Let's code Hanoi in C!!! http://ecximages-amazoncom/images/i/31c89fseu9ljpg

If-Statements if ( boolean expression ) { } else { }

If-Statements if ( boolean expression ) { } else { Operators } < > <= >=!= ==! &&

Create a function called swap() that swaps the two ints it gets as arguments Exercise

Dynamic int* arr; Memory Alloc arr = (int *) malloc( 10 * sizeof(int) ); if ( arr == NULL ) { // stop } arr[0] = 1; arr[9] = 100;

Dynamic int* arr; Memory Alloc arr = (int *) malloc( 10 * sizeof(int) ); if ( arr == NULL ) { // stop } arr[0] = 1; arr[9] = 100; // do some more work

Dynamic int* arr; Memory Alloc arr = (int *) malloc( 10 * sizeof(int) ); if ( arr == NULL ) { // stop } arr[0] = 1; arr[9] = 100; // perform some operations on arr free( arr );

STRINGS

Strings char name[] = "Sophia Smith"; printf( "name = %s\n", name );

Strings char name[] = "Sophia Smith"; char *place = "Smith College"; printf( "name = %s\n", name ); printf( "place = %s\n", place );

Strings char name[] = "Sophia Smith"; char *place = "Smith College"; char *st = (char *) malloc( 100*sizeof(char ) ); // initialize st printf( "name = %s\n", name ); printf( "place = %s\n", place ); printf( "st = %s\", st );

C Strings end with \0 char name[] = "Smith"; S m i t h \0?

C Strings Are Mutable char name[] = "Smith"; S m i t h \0 name[4] = 't'; S m i t t \0

Replace all the characters of "Smith College" by 'A' Do it with indexes, and with pointers Exercise

#include <stringh> Strings Functions char name[] = "Sophia Smith"; char *place = "Smith College"; char *st = (char *) malloc( 100*sizeof(char ) ); strcpy( st, name ); strcpy( st, " " ); strcpy( st, place );

The nine most common functions in <stringh>: strcat - concatenate two strings strchr - string scanning operation strcmp - compare two strings strcpy - copy a string strlen - get string length strncat - concatenate one string with part of another strncmp - compare parts of two strings strncpy - copy part of a string strrchr - string scanning operation https://enwikibooksorg/wiki/c_programming/strings See http://wwwtutorialspointcom/c_standard_library/string_hhtm for more info

Write a C program that declares a string variable containing "Smith College" and replaces all the characters by the first letters of the alphabet Your program must use a loop! Exercise

Let s Stop HERE!

The Arduino

Why? Natural progression: transistor > gate > comb & seq circuits > microprocessor > I/O ports > microcontroller + C

References LYNDA: http://wwwlyndacom/search?q=arduino Good for installation of software on Windows and Mac Arduino's Site: https://wwwarduinocc/ LadyAda: http://wwwladyadanet/