CS Programming In C

Similar documents
Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Sources: On the Web: Slides will be available on:

Number Representation

The C Programming Language course syllabus associate level

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Lecture 2. Binary and Hexadecimal Numbers

Informatica e Sistemi in Tempo Reale

As previously noted, a byte can contain a numeric value in the range Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

The programming language C. sws1 1

The string of digits in the binary number system represents the quantity

Chapter 7D The Java Virtual Machine

So far we have considered only numeric processing, i.e. processing of numeric data represented

Systems I: Computer Organization and Architecture

DNA Data and Program Representation. Alexandre David

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Semantic Analysis: Types and Type Checking

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Pemrograman Dasar. Basic Elements Of Java

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

How To Write Portable Programs In C

Lecture 22: C Programming 4 Embedded Systems

Numbering Systems. InThisAppendix...

Java Interview Questions and Answers

Faculty of Engineering Student Number:

Chapter 5 Instructor's Manual

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Computer Science 281 Binary and Hexadecimal Review

Introduction to Data Structures

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

1 Abstract Data Types Information Hiding

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Module 816. File Management in C. M. Campbell 1993 Deakin University

Instruction Set Architecture (ISA)

Unit Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]

Solution for Homework 2

Embedded C Programming, Linux, and Vxworks. Synopsis

Chapter 2: Elements of Java

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

This section describes how LabVIEW stores data in memory for controls, indicators, wires, and other objects.

5 Arrays and Pointers

Illustration 1: Diagram of program function and data flow

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Chapter 4: Computer Codes

Base Conversion written by Cathy Saxton

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

arrays C Programming Language - Arrays

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

Lab Experience 17. Programming Language Translation

Introduction to Java

Habanero Extreme Scale Software Research Project

Simple Image File Formats

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

The New IoT Standard: Any App for Any Device Using Any Data Format. Mike Weiner Product Manager, Omega DevCloud KORE Telematics

HOMEWORK # 2 SOLUTIO

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

2011, The McGraw-Hill Companies, Inc. Chapter 3

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

System Calls and Standard I/O

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

winhex Disk Editor, RAM Editor PRESENTED BY: OMAR ZYADAT and LOAI HATTAR

Storing Measurement Data

Technical Information. Digital Signals. 1 bit. Part 1 Fundamentals

Subject knowledge requirements for entry into computer science teacher training. Expert group s recommendations

C++ Programming Language

OKLAHOMA SUBJECT AREA TESTS (OSAT )

Stacks. Linear data structures

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

10CS35: Data Structures Using C

Motorola 8- and 16-bit Embedded Application Binary Interface (M8/16EABI)

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Keil C51 Cross Compiler

Stack Allocation. Run-Time Data Structures. Static Structures

Intel Hexadecimal Object File Format Specification Revision A, 1/6/88

Assessment for Master s Degree Program Fall Spring 2011 Computer Science Dept. Texas A&M University - Commerce

ELEG3924 Microprocessor Ch.7 Programming In C

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

B.Sc.(Computer Science) and. B.Sc.(IT) Effective From July 2011

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Hexadecimal Object File Format Specification

X86-64 Architecture Guide

MACHINE INSTRUCTIONS AND PROGRAMS

C PROGRAMMING FOR MATHEMATICAL COMPUTING

IPC. Semaphores were chosen for synchronisation (out of several options).

Embedded Systems Design Course Applying the mbed microcontroller

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Transcription:

CS 24000 - Programming In C Week 16: Review (cont d) Zhiyuan Li Department of Computer Science Purdue University, USA

Scope of the Final Exam We have covered issues related to the address space and the relationship between memory addresses and pointers (including function pointers) The next issue in C language that is not present in Java-like languages is the direct manipulation of data bits

The Concept of Data Representation The address space is addressable in bytes C, unlike many other languages, allows the program to directly manipulate the individual bytes of a piece of data (e.g. integer, float) This makes C well suited for implementing low-level system operations Data conversion between different systems (different endianess) Control status (interrupt registers) Extracting specific bits, e.g. part of a data packet in the network This also make C suitable for applications that must manipulate data at bit level, e.g. data compression, encryption

Number representation In order to extract bit-level information, we need to know how a number (int, float) is represented by bits Decimal to binary (or its compact representation by hexadecimal ) Binary to decimal Unsigned int Signed int under 2 s complement representation

The Endianess It has two aspects Byte organization of a number in the address space (how do we extract a certain byte) How we linearize the data, i.e. when we print a number, which byte comes first In computer organization and networking courses, we will see endianess is an issue at the bit level also When transmit a byte through the network, which bit goes first? But in the address space or at the modern processor hardware level, bit-level endianess has no practical meaning Because bits are accessed in parallel, unlike in some networks

We often need to either truncate or to expand a piece of data (e.g. from byte to int and vice versa) Understanding data representation will enable us to do such conversion correctly Sign extension of signed numbers Char to int, int to long long, e.g. Floating point number representation 32-bit to 64-bit

Review of Quiz 12 #2 What does the following program print? (assume 32 bit machine) #include <stdio.h> int main() { int x; char a = 0xaa, b = 0x11; a = b+a; x = a; printf ("%x", x); } The answer is ffffffbb, why? We go through the intermediate steps.

Declarations and Definitions This is related to the issue of memory allocation Definition binds a variable to a memory location and defines how it will be accessed Static, local, heap-allocated Function declarations versus definitions Global variables, external variables

Data representation versus interpretation There is a conceptual difference between how a piece of data is represented internally on computer hardware versus the data is interpreted Data interpretation is application dependent Do we view a word of four bytes as Four ASCII characters? Four char-sized integers? A pointer An integer Signed? Unsigned A float number? The printing function (e.g. printf) simply displays it the way we want the data to be interpreted

Floating point number representation The IEEE standard Sign, exponent, mantissa Normalized form of the mantissa Bias of the exponent We don t require to remember the special (non-normalized) forms

Parameter passing and function return value C function calls pass parameters by value In order for a called function to modify variables that are in the scope of the calling function, the addresses of those variables must be passed as parameters Passing a big structure by value is expensive, because the entire structure will be copied to the callee s stack frame Returning a big structure is also expensive, for the same reason Passing the base address of the structure is more efficient In Java, the reference to the structure (object) is passed as the parameter

Strings In C, strings are perhaps one of most error prone data structure The type of a string is an array of chars. Since the length of the string is often undetermined at compile time, the proper composition of a string must be null-terminated A quoted string is always automatically null terminated But if we explicitly pack a string to an array, we must remember to terminate it.

Syntax Rules We assume students are familiar with the basic syntax rules We will not pose questions involving obscure syntax rules, e.g. obscure expressions and obscure library function interfaces We assume students are familiar with the basic precedence ordering among operations and associativities E.g. left associative arithmetic operations E.g. postfix expressions having higher precedence than prefix expressions

Basic I/O functions We assume students are familiar with the basic concepts associated with file I/O Read, write, fread, fwrite, getchar, putchar, printf, scanf And their impact on seek positions Open, fopen, close, fclose, seek, fseek

Processes and IPC The impact of fork() calls on the semantics of the calling program Impact on file I/O Impact on variable values etc Pipe calls and the proper use of pipes Shared memory and proper operations to allocate, attach, and remove shared memory blocks Semaphores and proper use of semaphore operations (sem_init, sem_wait, sem_post) and destroy operations

Summary The scope of final exam will basically be midterm 1 + midterm 2 + scope of the four projects