Chapter 10. Programming in C

Similar documents
Computer Systems Lecture 9

Table of Figures Figure 1. High resolution PWM based DAC...2 Figure 2. Connecting the high resolution buck converter...8

Pragma intrinsic and more

Short Notes of CS201

A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE

CS201 - Introduction to Programming Glossary By

EC 413 Computer Organization

A Fast Review of C Essentials Part I

Name :. Roll No. :... Invigilator s Signature :.. CS/B.TECH (NEW)/SEM-2/CS-201/ BASIC COMPUTATION & PRINCIPLES OF COMPUTER PROGRAMMING

Quick Reference Guide

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Part 1: Introduction to the C Language

PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur

Unit 7. Functions. Need of User Defined Functions

MPLAB C1X Quick Reference Card

TCS Technical interview Questions

cast.c /* Program illustrates the use of a cast to coerce a function argument to be of the correct form. */

Migrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051

Table of Figures Figure 1. Two pole two zero controller module...2

Computers Programming Course 5. Iulian Năstac

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

BLM2031 Structured Programming. Zeyneb KURT

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Multiple Choice Questions. Chapter 5

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

Mating Assembly with C

Migrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051

Algorithms & Data Structures

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

CSE 230 Intermediate Programming in C and C++ Functions

Quick Reference Guide

b. array s first element address c. base address of an array d. all elements of an array e. both b and c 9. An array elements are always stored in a.

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15


How to set Keil compiler environment v1.0

G Programming Languages - Fall 2012

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Lecture 2: C Programming Basic

CS 161 Exam II Winter 2018 FORM 1

Contents. Preface. Introduction. Introduction to C Programming

Chapter 09. Programming in Assembly

Holtek C and ANSI C Feature Comparison User s Guide

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

Functions in MIPS. Functions in MIPS 1

Objectives. ICT106 Fundamentals of Computer Systems Topic 8. Procedures, Calling and Exit conventions, Run-time Stack Ref: Irvine, Ch 5 & 8

KLiC C Programming. (KLiC Certificate in C Programming)

Xuan Guo. Lecture XIX: Subroutines (2) CSC 3210 Computer Organization and Programming Georgia State University. March 31, 2015.

real-time kernel documentation

C Language Programming

PESIT-BSC Department of Science & Humanities

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:

Functions. Systems Programming Concepts

Procedural programming with C

ME 4447/ME Microprocessor Control of Manufacturing Systems/ Introduction to Mechatronics. Instructor: Professor Charles Ume

OBJECTIVE QUESTIONS: Choose the correct alternative:

Lecture 04 FUNCTIONS AND ARRAYS

EK131 E5 Introduction to Engineering

Run Time Environment

Embedded Controller Programming 2

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM

Functions. Cedric Saule

Subject: Fundamental of Computer Programming 2068

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

C Language Programming

CSCI565 Compiler Design

15 FUNCTIONS IN C 15.1 INTRODUCTION

MPATE-GE 2618: C Programming for Music Technology. Syllabus

Remote Procedure Call Implementations

Back to RTOS. CSE466 Autumn 00-1

8. Functions (II) Control Structures: Arguments passed by value and by reference int x=5, y=3, z; z = addition ( x, y );

Object-Oriented Programming

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

C++ Arrays. Arrays: The Basics. Areas for Discussion. Arrays: The Basics Strings and Arrays of Characters Array Parameters

Pace University. Fundamental Concepts of CS121 1

Fixed-Point Math and Other Optimizations

CS201 Some Important Definitions

Assembler Programming. Lecture 10

DECLARAING AND INITIALIZING POINTERS

OpenCL C. Matt Sellitto Dana Schaa Northeastern University NUCAR

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

C Programming Review CSC 4320/6320

Course organization. Course introduction ( Week 1)

CS61C : Machine Structures

CMPE-013/L. Introduction to C Programming

CSCI 171 Chapter Outlines

Ch. 11: References & the Copy-Constructor. - continued -

ECE331: Hardware Organization and Design

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

Summary: Direct Code Generation

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

CET360 S12 DEMO PROGRAM #1 (C)

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

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

ME 461 C review Session Fall 2009 S. Keres

INTRODUCTION 1 AND REVIEW

CSE 1320 INTERMEDIATE PROGRAMMING - OVERVIEW AND DATA TYPES

Project 2: Signals. Consult the submit server for deadline date and time

What is Pointer? Pointer is a variable that holds a memory address, usually location of another variable.

Transcription:

Chapter 10 Programming in C

Lesson 05 Functions in C

C program Consists of three parts preprocessor directives macros main function functions 3

Function Each has a name (for identity ID) May have the arguments A function may or may not return certain data or data-set or object A standard C declaration <[>return_type<]> functionname (<[>argumnets<]>). 4

Routine A set of instructions The instructions of the routine execute as follows Has a distinct start address The program counter (PC) acquires the start address value after the earlier value of PC is saved, execute 5

Routine The start address has the first instruction, which executes first in a routine The routine has a return instruction at the end The previously saved value of program counter is restored back into the PC on the return from the routine A routine equivalent function in C 6

Main Function in C main in C, if it is the first function to execute at the beginning of a program Each function also has a start address The program source file execution starts from the main function invoked by void main ( ){...;}. Void means that this function (program codes) does not return any variable to any other function (routine) 7

Before the main Before this statement, there are preprocessor directives like include. 8

Interrupt Function in C Interrupt service routine interrupt function in C 9

Function Main Interrupt Function Function Library Function Reentrant Function Exception Handling Function Recursive function 10

Reentrant Function in C Function, which on interrupt or which on calling another function, reenters on the return to the same state of the variables and CPU registers as before the interrupt or call 11

void before function ID void timeset (int numticks) The void means function return type is void and it returns no variable or object The name of the function (Function ID) is timeset 12

timeset timeset one argument Uses the integer value of numticks as input The numticks a variable timeset gets the value of numticks from outside the function The value is passed to the functions from outside the function block [to a local variable memory address from another function] 13

int timeget ( ) int means function return type is not void but an integer The function returns value of an integer variable The name (ID) of the function timeget It gets the time using a global variable for specifying the time There are no arguments in the function 14

Library Function Library means the readily available functions Library functions are directly used by the programmer The compiler uses the functions statements from the library 15

1. Use of modifiers- C Function unsigned int; unsigned char; 2. Use of data types and struc 3. Declarations and Statements 4. Comments at appropriate places and lines 5. Control structures; if then else, case and for, while and repeat until loops 16

C Function 6. Use of pointersunsigned long *time_date; 7. Use of arrays char [ ] name; 8. Inline assembly codes 17

9. Use of arguments C Function Parameter passing void profile (name, address) 10. Use of passing values and addresses of variables in the arguments 11. Returning nothing (void) or data or data struc char [ ] welcomemsg (msg1, sig); 18

Keil Cx51 compiler library functions. A set of mathematical, memory, string and other ANSI standard library functions String manipulation functions used to manipulate the strings. 19

String manipulation functions For example, strlen ( ) is a String manipulation library-function. It evaluates the length of the string (number of characters in a string). 20

Memory allocation functions Allot the memory calloc ( ) is a library-function calloc ( ) allots the memory for an array from available memory pool 21

memcopy ( ) Additional library function copy from one memory to other memory space 22

Exclusion in Keil C Exclusion of certain ANSI standard function For qsort ( ) for quick sorting of array is excluded. 23

In-line Assembly in Fucntion Function outportbpinv (b, p); /*b is the address of bit 1 of a port and p is the memory address of bit n to be transferred after complementing.*/ void outportbpinv (b, p) { asm { CPL p; MOV C, p; MOV b, C;} }; 24

Summary

We learnt C program consists of functions only A function can also be declared as void function 26

We learnt meanings of Function Main Interrupt Function Function Library Function Reentrant Function Exception Handling Function Recursive function 27

We learnt A function is a routine, which can be passed the values or pointers through the arguments and which additionally can return a value or data-object or pointer by the function name 28

We learnt Parameters to a function can be passed by value or by reference 29

End of Lesson 05 on Functions in C