Getting the Least Out of Your C Compiler
|
|
- Brett William Bates
- 5 years ago
- Views:
Transcription
1 Getting the Least Out of Your C Compiler Strategic Development IAR Systems jakob.engblom@iar.se Jakob Engblom Dept. of Computer Systems Uppsala University, Sweden jakob@docs.uu.se Embedded Systems Conference San Fransisco 2001 Class #508 This Class Coding Coding tips and usage tips for C To keep code size down To help the compiler optimize Assumed background: Embedded Systems Hardware Embedded Systems Software C Programming Level: basic 1 2 The Target Systems Why Care About Size? Microcontrollers: CPU Core Integrated memory Integrated peripherals Integrated services System on a chip 8-16 bit most common RAM (small) UART CPU Core A/D LCD D ROM (big) Timer Outside World Keep Keep memory cost down Avoid external memory Use smaller external memory Use a smaller derivative Keep absolute limits HW done before the software Application can only use on-chip memory 3 4
2 Compiler System Compiler Technology User Code C Source C Source C Source Compiler System Compiler Object File Object File Object File C Runtime C Library Linker 5 OS Other Lib Third-Party Code Executable Hardware 6 The Compiler Optimization x = C Source x + 15 Parser Intermediate Code ld R10,$_x add R10,#15 st $_x,r10 x = x + 15; Code Generator Target Code High-Level Optimizer Assembler Object Code Compiler Low-Level Optimizer Analysis: Understand the code Data flow, control flow More info = better code Transformation: Change the code Based on heuristics Should improve but does not have to And definitely not optimality of the code! Improvement not guaranteed! 7 8
3 Basic Transformations Use cheaper operation Find common calculations Propagate constant values Remove useless computations a=b*2 a=b+c*d e=f+c*d a=17 b=56+2*a a=b*c+k a=k+7 a=b+b temp=c*d a=b+temp e=f+temp a=17 b=90 a=b*c+k a=k+7 Basic Transformations Remove unreachable code Move invariant code out of loops if(a>10) b=b*c+k; if(a<5) a+=6; for(i=0;i<10;i++) b = k * c; p[i] = b; if(a>10) b=b*c+k; if(a<5) a+=6; b = k * c; for(i=0;i<10;i++) p[i] = b; 9 10 Pitfall: Empty Loops Optimization Settings Empty Empty delay loop does not work Code with no effect Gets removed Delay is zero For For delay: Access volatile variable Use OS services Use CPU timer Use delay intrinsic void delay(int time) int i; for (i=0;i<time;i++) ; return; void InitHW(void) /* Timing-dependent code */ OUT_SIGNAL (0x20); delay(120); OUT_SIGNAL (0x21); delay(121); OUT_SIGNAL (0x19); Typically available: Minimize size ( size ) Minimize execution time ( speed ) Enable/disable individual transformations Use Use highest settings! Settings only approximate Best guess by compiler writer Test several settings, check the results Disable destructive transformations 11 12
4 Optimization Settings Code Generation Global Global setting Over entire project IDE or command-line Per-file Per-file settings Example: collect all speed in one file Per-function #pragma in source file Compiler dependent #pragma optimize(all,off) void delay(int time) From From Intermediate to Target Implement C operations Break down big operations Insert calls to C runtime (more on this later) May introduce jumps, loops, etc. Assign Assign variables to registers Register Allocation Heuristics for best variables Language rules followed (volatile) Shouldn t be considered optimization Compiler Libraries The C Library User Code C Source C Source C Source Compiler System Compiler Object File Object File Object File OS Other Lib Third-Party Code C Runtime C Library Linker Executable Hardware 15 printf() () etc. etc. Programmer-visible Standardized in ANSI C Standalone profile: No file operations Suitable for run-from-rom systems Limited Limited versions: Smaller code through less functionality Provided with compiler Non-standard 16
5 The C Run-Time System Not Not very well known item Part Part of compiler Designed with the compiler Implements complex functions Called from compiled code Not visible to programmer Whatever is needed that the hardware does not support Bigger Bigger for simpler machines 17 The C Run-Time System 32-bit 32-bit arithmetic Floating-point arithmetic Pointer Pointer use: Banked, generic, large, function pointers, Operations missing from CPU: Multiply, divide, modulo, Variable-length shifts ( a<<x a<<x ) May May have a large footprint Tens of kilobytes of code Tens of bytes of data 18 Coding Techniques Structuring a Program To be efficient and portable Isolate device-dependent code Leave most of the code undisturbed Use tuned code where needed Generic Program Files Tuned Program Files Device-dependent Program Files Hardware 19 20
6 Device Descriptions Chips Chips have many derivatives Different I/O ports Different available memories, sizes, etc. Special features Compiler device description: As As #include include files and command-line options #include files from compiler: Describes chip in best way for compiler Saves work for programmer Do not write your own unless necessary! Use of Data Types Types Types very important Factors Factors to consider: Size Signed or unsigned Floating point or integers Memory placement Pointer types Casting Data Size Performing operations: 32-bit operations hard for 8-bit CPU 8-bit operations less efficient on 32-bit Sometimes type is forced char long char for byte I/O etc long for large counters Often, Often, we can choose Smallest possible type for 8-bit int for 32-bit machines Data Size: Header Files 8-bit machine /* Fixed size types */ typedef unsigned char uint8_t; typedef short int16_t; typedef unsigned long uint32_t; /* Adjusting types */ typedef char best_int8_t; typedef short best_int16_t; typedef long best_int32_t; /* Use best_x_t for ranges */ best_int8_t i; for(i=0; i<10; i++) 32-bit machine /* Fixed size types */ typedef unsigned char uint8_t; typedef short int16_t; typedef unsigned int uint32_t; /* Adjusting types */ typedef int best_int8_t; typedef int best_int16_t; typedef int best_int32_t; All are 32-bit values. Most efficient for calculations 23 24
7 Signed or Unsigned Think Think about the signedness SignedSigned Negative values possible Arithmetic operations performed Unsigned Negative values impossible Bit operations performed + - * / % << >> & ^ ~ 25 Integer or Floating Point Floating point very expensive Brings large library (from C runtime lib) Use only when really needed Can Can be done inadvertently: Example code: #define ImportantRatio ((int)(1.95 * Other)) #define Other 20 #define ImportantRatio (1.95 * Other) int i=a + b * ImportantRatio; This is a floating-point multiplication. Float library linked in! To obtain an integer constant from ImportantRatio, and thus integer code: bits Memory Placement Typical micro- Use smaller areas: controller memory: Smaller addresses 16 bits 8 bits Far Near Tiny Smaller instructions Smaller pointers =more efficient =less code! Place Place variables: Using keywords tiny char a; a Using #pragma Using In tuned files 27 Pointers & Memory Pointer Pointer types: One for each addressing space/mode near char * nearptr; tiny int * tinyptr; Generic, huge, etc: Point to all memories (for disjoint memories) Point to objects crossing banks Software-emulated = expensive Use Use the smallest applicable type Beware of compiler default settings! Memory model, Data model, 28
8 Casting C C has implicit and explicit casts Casting Casting is not free Sign-extend and zero-extend Complex conversions to/from floats Casting Casting to/from pointers is bad Can lose information (different size) Inefficient code Avoid unless really necessary Don t do explicit casts Don t mix types in expressions Register Allocation Important for good code To To facilitate: Register keyword? Use parameters Use local variables Don t take addresses Group function calls Don t use varargs Register keyword Hint Hint to compiler Cannot Cannot take address of variable May May be ignored Modern compilers ignore register register Register allocation heuristics usually better Use Parameters & Locals Global Global variables Written back at function calls Have to be given memory Do not use globals for parameter passing! Parameters and local variables Give compiler more freedom Need not be given memory Parameter passing: Parameters often passed in registers Registers to use = calling convention 31 32
9 Use Parameters & Locals Register allocation targets: Simple values (integers, pointers, floats) Small CPUs: maybe not the biggest values Hard Hard to allocate: Arrays indexing addressing the norm Structs large, often pointed to StructStruct as parameter: Value copied, and a pointer passed Pass pointer directly for efficiency! Use Parameters & Locals void foo(char a) char b,i,j; char h[10]; b=a<<5; for(i=0; ) OUTPUT(b); for(j=0; ) h[j]=a; live ranges a b i j Array usually not in registers Register usage: Variables can share a register Only present in register while live Don t worry about extra variables j, i, b all optimized away at this point Many registers Optimize: needed here Minimize lifetime j can use the same Minimize register overlap as i or b Don t Take Addresses Address taken not in register Always written back to memory Variable has to have memory Since: Since: The address escapes a function Compiler cannot know who reads Note: Note: not too bad for globals Local variables behave like global register keyword prevents Examples of address taking Input Input functions: int a; scanf( %d,&a); int a, temp; scanf( %d,&temp); a=temp; Watch Watch out for smart tricks: #define highbyte(x) ( *((char *)(&x)+1) ) #define highbyte(x) ( (x>>8) & 0xFF ) 35 36
10 Group Function Calls Function calls: Increase register pressure Require certain registers =impediment to register allocation Group Group to minimize effects s.a = a; s.b = bar(b); s.c = c; s.d = c; s.e = baz(d); s.a = a; s.c = c; s.d = c; s.b = bar(b); s.e = baz(d); Don t Use Varargs Variable number of arguments int printf(char *,...) Special macros to access arguments Force Force arguments to the stack Step through them using pointers No No parameters in registers Source Source code gets more complex Object Object code gets bigger Bad Bad idea, simply Facilitate Transformations Convey Convey maximal information Write Write clear code Techniques: Use function prototypes Mark file-locals using static Don t use inline assembler Don t write clever code Write nice loops Access hardware as variables 39 Use Function Prototypes C C and function calls: No declaration: call out of the blue K&R declarations: extern void foo(); ANSI prototypes: char bar(short); extern void foo(); Without ANSI prototypes: No proper type checking All arguments promoted Introduces casting code Parameter data is larger = more stack used Always Always use ANSI prototypes! Turn on checking in compiler! 40
11 File Locals Don t Use Inline Assembly The The static keyword: Object not visible outside the file All references known More aggressive optimization possible Functions: Higher chance of inlining Variables: Knows address taken, etc. for all uses Better optimization possible 41 Major Major hinder to optimization Inline assembly can do anything (Some inline assemblers allow annotations) Put Put assembly into: Separate assembly-source files Assembly-only functions in C files To To access special instructions: Use intrinsic functions (if available) disable_interrupts() disable_interrupts() delay( delay(n) Generates single assembly instructions 42 Don t Write Clever Code Example Clever Code Clever Clever code: Fewer source characters = better code Using dark corners of C semantics Straightforward code: Easier for compiler and humans Safer for portability Use common constructions: Likely to be better optimized Less likely to contain bugs Use of constant: Check Check If Low high likelihood 21 Bits of Zero Depends on semantics of NOT operator unsigned in C long int a; unsigned char b; b =!!(a << 11); Explicit check against zero for the creating bit-set lower bits instruction unsigned long int a; unsigned char b; if( (a & 0x1FFFFF)!= 0) b = 0x01; Explicit check: Calculating Add with result of with Conditionals comparison: forces generation int of 1 or bad(char 0 *str) foo(str+(*str=='+')); only do an inc if needed. Smaller int code. good(char *str) if(*str=='+') str++; foo(str); 43 44
12 Write Nice Loops The The compiler is able to: Adjust loop statements to the machine Change count direction Utilize Utilize loop instructions if available (DJNZ) Remove initial check in for -loops Convert array indexing to pointer walking Unroll loops, fuse loops, many other tricks Regular, simple loops: Easier to understand for maintenance Easier to optimize for compiler 45 Write Nice Loops int i=0; do i+=2; temp = b[i]; i-=1; b[i] = temp + 2; while (i<80); for()-loop should always be used if possible! /* use that i is 80 after loop*/ a = i; Do not read value of loop index after the loop best_int8_t i=0; for(i=0; i<80; i++) b[i+1]=b[i+2]+2; Update loop a = 80; index only in the loop declaration Think Fortran 46 Access to Hardware Ports Do Do not cast a constant: #define PORT (*((BYTE *) 0x41FF)) Use Use a variable: volatile no_init BYTE PORT; Locate it: special syntax, or use linker Easier to locate in the right memory Often provided in devicexx devicexx.h Provides better type checking Gives better code Can be simulated on PC 47 Inhibit Optimizations Sometimes, optimizations are not desirable Reordering of computations Removing redundant code Register allocation Examples: Shared variables I/O ports Side effects must be ordered Use volatile variables! 48
13 Volatile Semantics VolatileVolatile keyword means Can change outside program control = Can change asynchronously Effect Effect on compiler: Never in registers All reads and writes to memory immediately Accesses not reordered No assignments considered dead Put Put in: Header files for I/O and shared data Volatile Examples volatile Boolean glock; while( glock == kfalse ) /* spinlock */ ; volatile no_init uint8_t outporta; volatile no_init uint16_t outportb; /* Setup sequence for hardware */ outporta = 0x00; outportb = 0x1000; outporta = 0x3A; outportb = 0xFFFF; Use Another Compiler Outside the Code Compilers are different Different priorities Different sets of optimizations Different ideas of target programs Test Test several compilers See what works best with your code Use Use real application code! Benchmarks are usually misleading ( benchmarketing benchmarketing ) 51 52
14 Try Better Architectures Some Some chips are inherently better More suited for application More suited for C programming More efficient instruction sets (Good example: AVR vs ) Compacted instruction sets Works in practice, gives smaller code ARM/Thumb MIPS16 Closing Remarks Optimization gives bugs? Exposes existing bugs Very particular about C semantics Reduces redundancy in code Code was wrong to begin with Only correct code is optimized correctly Optimization is necessary Write maintainable, non-tuned code Trust compiler to optimize Without optimization, compiler handicapped Summary: Code Write Write easy-to-understand code Provide maximal information Maintenance easier Optimizations work better =Everybody happy Do not suboptimize Keep code free of target assumptions Let the compiler optimize for target Manually optimize only where needed 55 56
15 Summary: C Compilers Compilers are heuristic Usually work OK No guarantees of improving code No hard facts like always always gains n% Try Try different compiler settings All programs are different Use Use common constructions Fewer bugs, better optimized (Many more details in paper) 57 The End Fill in Evaluation Forms Updates of Paper: docs.uu.se/~.se/~jakob
Boost Performance Optimizations. Rafael Taubinger Sr. FAE
Boost Performance Optimizations Rafael Taubinger Sr. FAE Agenda Company Overview Company The Compiler Overview The Reasons Compiler to Optimize Reasons Structure to your Optimize application to boost optimization
More information5.Coding for 64-Bit Programs
Chapter 5 5.Coding for 64-Bit Programs This chapter provides information about ways to write/update your code so that you can take advantage of the Silicon Graphics implementation of the IRIX 64-bit operating
More informationIAR Embedded Workbenches for Renesas
IAR Embedded Workbenches for Renesas Shawn A. Prestridge, Senior Field Applications Engineer IAR Systems, Inc. Class ID: 3C19I Renesas Electronics America Inc. Shawn A. Prestridge Senior Field Applications
More informationA 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
More informationImportant From Last Time
Important From Last Time Embedded C Pros and cons Macros and how to avoid them Intrinsics Interrupt syntax Inline assembly Today Advanced C What C programs mean How to create C programs that mean nothing
More informationPage 1. Today. Important From Last Time. Is the assembly code right? Is the assembly code right? Which compiler is right?
Important From Last Time Today Embedded C Pros and cons Macros and how to avoid them Intrinsics Interrupt syntax Inline assembly Advanced C What C programs mean How to create C programs that mean nothing
More informationC Review. MaxMSP Developers Workshop Summer 2009 CNMAT
C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***
More informationHacking in C. The C programming language. Radboud University, Nijmegen, The Netherlands. Spring 2018
Hacking in C The C programming language Radboud University, Nijmegen, The Netherlands Spring 2018 The C programming language Invented by Dennis Ritchie in the early 70s First Hello World program written
More informationImportant From Last Time
Important From Last Time Embedded C Ø Pros and cons Macros and how to avoid them Intrinsics Interrupt syntax Inline assembly Today Advanced C What C programs mean How to create C programs that mean nothing
More informationCMPE-013/L. Introduction to C Programming
CMPE-013/L Introduction to C Programming Bryant Wenborg Mairs Spring 2014 What we will cover in 13/L Embedded C on a microcontroller Specific issues with microcontrollers Peripheral usage Reading documentation
More informationMigrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051
Migration guide Migrating from Keil µvision for 8051 to for 8051 Use this guide as a guideline when converting project files from the µvision IDE and source code written for Keil toolchains for 8051 to
More informationMigrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051
Migration guide Migrating from Keil µvision for 8051 to for 8051 Use this guide as a guideline when converting project files from the µvision IDE and source code written for Keil toolchains for 8051 to
More informationCSCI 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
More information>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.
>B
More informationComputers Programming Course 5. Iulian Năstac
Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction
More informationBLM2031 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
More informationQUIZ. What is wrong with this code that uses default arguments?
QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code
More informationSpecial Topics for Embedded Programming
1 Special Topics for Embedded Programming ETH Zurich Fall 2018 Reference: The C Programming Language by Kernighan & Ritchie 1 2 Overview of Topics Microprocessor architecture Peripherals Registers Memory
More informationC Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming
C Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming Course Overview This course transforms an IT-Professional or a Student into an expert C Programming Person with concepts
More informationHacking in C. The C programming language. Radboud University, Nijmegen, The Netherlands. Spring 2018
Hacking in C The C programming language Radboud University, Nijmegen, The Netherlands Spring 2018 The C programming language Invented by Dennis Ritchie in the early 70s First Hello World program written
More informationQUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:
QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the
More informationLecture 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
More informationAgenda. 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
More informationIntroduction. Keywords: MAXQ, IAR, memory allocation, flash data, flash storage, SRAM
Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 5262 Maxim > Design Support > Technical Documents > Application Notes > Optoelectronics > APP 5262 Maxim > Design
More informationZiLOG Z8 Encore! Compiler Compliance With ANSI STANDARD C
ZiLOG Z8 Encore! Compiler Compliance With ANSI STANDARD C ZiLOG Worldwide Headquarters 532 Race Street San Jose, CA 95126 Telephone: 408.558.8500 Fax: 408.558.8300 www.zilog.com 2 Abstract The purpose
More informationAgenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion
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,
More informationPhysics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu
Physics 2660: Fundamentals of Scientific Computing Lecture 3 Instructor: Prof. Chris Neu (chris.neu@virginia.edu) Announcements Weekly readings will be assigned and available through the class wiki home
More informationCS 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,
More informationFixed-Point Math and Other Optimizations
Fixed-Point Math and Other Optimizations Embedded Systems 8-1 Fixed Point Math Why and How Floating point is too slow and integers truncate the data Floating point subroutines: slower than native, overhead
More informationL2 - C language for Embedded MCUs
Formation C language for Embedded MCUs: Learning how to program a Microcontroller (especially the Cortex-M based ones) - Programmation: Langages L2 - C language for Embedded MCUs Learning how to program
More information0x0d2C May your signals all trap May your references be bounded All memory aligned Floats to ints round. remember...
Types Page 1 "ode to C" Monday, September 18, 2006 4:09 PM 0x0d2C ------ May your signals all trap May your references be bounded All memory aligned Floats to ints round remember... Non -zero is true ++
More informationThe component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science
The component base of C language Nguyễn Dũng Faculty of IT Hue College of Science Content A brief history of C Standard of C Characteristics of C The C compilation model Character set and keyword Data
More informationQUIZ How do we implement run-time constants and. compile-time constants inside classes?
QUIZ How do we implement run-time constants and compile-time constants inside classes? Compile-time constants in classes The static keyword inside a class means there s only one instance, regardless of
More informationUnder the Compiler's Hood: Supercharge Your PLAYSTATION 3 (PS3 ) Code. Understanding your compiler is the key to success in the gaming world.
Under the Compiler's Hood: Supercharge Your PLAYSTATION 3 (PS3 ) Code. Understanding your compiler is the key to success in the gaming world. Supercharge your PS3 game code Part 1: Compiler internals.
More informationQUIZ. What are 3 differences between C and C++ const variables?
QUIZ What are 3 differences between C and C++ const variables? Solution QUIZ Source: http://stackoverflow.com/questions/17349387/scope-of-macros-in-c Solution The C/C++ preprocessor substitutes mechanically,
More informationWhy Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...
Why Pointers Pointers They provide the means by which functions can modify arguments in the calling function. They support dynamic memory allocation. They provide support for dynamic data structures, such
More informationCENG 447/547 Embedded and Real-Time Systems. Review of C coding and Soft Eng Concepts
CENG 447/547 Embedded and Real-Time Systems Review of C coding and Soft Eng Concepts Recall (C-style coding syntax) ; - Indicate the end of an expression {} - Used to delineate when a sequence of elements
More informationThe 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
More informationC Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:
C Programming Code: MBD101 Duration: 10 Hours Prerequisites: You are a computer science Professional/ graduate student You can execute Linux/UNIX commands You know how to use a text-editing tool You should
More informationCompiler Optimization
Compiler Optimization The compiler translates programs written in a high-level language to assembly language code Assembly language code is translated to object code by an assembler Object code modules
More informationContents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides
Slide Set 1 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section
More informationHW1 due Monday by 9:30am Assignment online, submission details to come
inst.eecs.berkeley.edu/~cs61c CS61CL : Machine Structures Lecture #2 - C Pointers and Arrays Administrivia Buggy Start Lab schedule, lab machines, HW0 due tomorrow in lab 2009-06-24 HW1 due Monday by 9:30am
More informationCS 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
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationPage 1. Today. Last Time. Is the assembly code right? Is the assembly code right? Which compiler is right? Compiler requirements CPP Volatile
Last Time Today Compiler requirements CPP Volatile Advanced C What C programs mean int my_loop (int base) { int index, count = 0; for (index = base; index < (base+10); index++) count++; urn count; my_loop:
More informationFinal CSE 131B Winter 2003
Login name Signature Name Student ID Final CSE 131B Winter 2003 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 _ (20 points) _ (25 points) _ (21 points) _ (40 points) _ (30 points) _ (25 points)
More informationMPLAB C1X Quick Reference Card
MPLAB C1X Quick Reference Card 34 MPLAB C17 Quick Reference MPLAB C17 Command Switches Command Description /?, /h Display help screen /D[=] Define a macro /FO= Set object file name /FE=
More informationEmbedded Controller Programming 2
Embedded Controller Programming 2 Section 1: Introduction and Getting Started - Ken Arnold ecp2@hte.com Copyright 2006 Ken Arnold Welcome! ECP II Course Overview Instructor & Student Introductions Review
More informationQUIZ. Source:
QUIZ Source: http://stackoverflow.com/questions/17349387/scope-of-macros-in-c Ch. 4: Data Abstraction The only way to get massive increases in productivity is to leverage off other people s code. That
More informationTwo 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
More informationBasic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces
Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationProgramming 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
More informationCS 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
More informationLecture 3: C Programm
0 3 E CS 1 Lecture 3: C Programm ing Reading Quiz Note the intimidating red border! 2 A variable is: A. an area in memory that is reserved at run time to hold a value of particular type B. an area in memory
More informationTypes II. Hwansoo Han
Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping
More informationA QUICK INTRO TO PRACTICAL OPTIMIZATION TECHNIQUES
A QUICK INTRO TO PRACTICAL OPTIMIZATION TECHNIQUES 0. NO SILVER BULLETS HERE. 1. Set Compiler Options Appropriately: Select processor architecture: Enables compiler to make full use of instructions which
More informationCS 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
More informationThere are 16 total numbered pages, 7 Questions. You have 2 hours. Budget your time carefully!
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING MIDTERM EXAMINATION, October 27, 2014 ECE454H1 Computer Systems Programming Closed book, Closed note No programmable electronics allowed
More informationPreview from Notesale.co.uk Page 6 of 52
Binary System: The information, which it is stored or manipulated by the computer memory it will be done in binary mode. RAM: This is also called as real memory, physical memory or simply memory. In order
More informationData Types. Data Types. Integer Types. Signed Integers
Data Types Data Types Dr. TGI Fernando 1 2 The fundamental building blocks of any programming language. What is a data type? A data type is a set of values and a set of operations define on these values.
More informationCS 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
More informationPage 1. Last Time. Today. Embedded Compilers. Compiler Requirements. What We Get. What We Want
Last Time Today Low-level parts of the toolchain for embedded systems Linkers Programmers Booting an embedded CPU Debuggers JTAG Any weak link in the toolchain will hinder development Compilers: Expectations
More informationHigh Performance Computing and Programming, Lecture 3
High Performance Computing and Programming, Lecture 3 Memory usage and some other things Ali Dorostkar Division of Scientific Computing, Department of Information Technology, Uppsala University, Sweden
More informationEL6483: Brief Overview of C Programming Language
EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions
More informationCSE 333 Lecture 2 Memory
CSE 333 Lecture 2 Memory John Zahorjan Department of Computer Science & Engineering University of Washington Today s goals - some terminology - review of memory resources - reserving memory - type checking
More informationedunepal_info
facebook.com/edunepal.info @ edunepal_info C interview questions (1 125) C interview questions are given with the answers in this website. We have given C interview questions faced by freshers and experienced
More informationCodeWarrior Development Studio for Microcontrollers V10.0 MISRA-C:2004 Compliance Exceptions for the HC(S)08, RS08 and ColdFire Libraries Reference
CodeWarrior Development Studio for Microcontrollers V10.0 MISRA-C:2004 Compliance Exceptions for the HC(S)08, RS08 and ColdFire Libraries Reference Manual Revised: May 12, 2010 Freescale, the Freescale
More informationNetwork Embedded Systems Sensor Networks. Tips and Tricks. Marcus Chang,
Network Embedded Systems Sensor Networks Tips and Tricks Marcus Chang, mchang@cs.jhu.edu 1 Project Part 3 PC --UART--> Telosb --radio--> Telosb Reliable communication and storage Data corruption Missing
More informationCS 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
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 4 Introduction to C (pt 2) 2014-09-08!!!Senior Lecturer SOE Dan Garcia!!!www.cs.berkeley.edu/~ddgarcia! C most popular! TIOBE programming
More informationJava and C CSE 351 Spring
Java and C CSE 351 Spring 2018 https://xkcd.com/801/ Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: get_mpg: pushq
More informationPragma intrinsic and more
Pragma intrinsic and more C Language Extensions: This section gives a brief overview of the C language extensions available in the MSP430 IAR C/C++ Compiler. The compiler provides a wide set of extensions,
More informationDSP Mapping, Coding, Optimization
DSP Mapping, Coding, Optimization On TMS320C6000 Family using CCS (Code Composer Studio) ver 3.3 Started with writing a simple C code in the class, from scratch Project called First, written for C6713
More informationEmbedded Systems - FS 2018
Institut für Technische Informatik und Kommunikationsnetze Prof. L. Thiele Embedded Systems - FS 2018 Lab 0 Date : 28.2.2018 Prelab Filling the gaps Goals of this Lab You are expected to be already familiar
More informationC 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,
More informationFinal CSE 131B Spring 2004
Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)
More informationAppendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.
A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators
More information2/6/2018. ECE 220: Computer Systems & Programming. Function Signature Needed to Call Function. Signature Include Name and Types for Inputs and Outputs
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming C Functions and Examples Signature Include Name and Types for Inputs and
More informationIntroduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C
Final Review CS304 Introduction to C Why C? Difference between Python and C C compiler stages Basic syntax in C Pointers What is a pointer? declaration, &, dereference... Pointer & dynamic memory allocation
More informationAdvanced use of the C language
Advanced use of the C language Content Why to use C language Differences from Java Object oriented programming in C Usage of C preprocessor Coding standards Compiler optimizations C99 and C11 Standards
More informationC Language Programming
Experiment 2 C Language Programming During the infancy years of microprocessor based systems, programs were developed using assemblers and fused into the EPROMs. There used to be no mechanism to find what
More informationOptimising for the p690 memory system
Optimising for the p690 memory Introduction As with all performance optimisation it is important to understand what is limiting the performance of a code. The Power4 is a very powerful micro-processor
More informationAnnotation Annotation or block comments Provide high-level description and documentation of section of code More detail than simple comments
Variables, Data Types, and More Introduction In this lesson will introduce and study C annotation and comments C variables Identifiers C data types First thoughts on good coding style Declarations vs.
More informationCh. 3: The C in C++ - Continued -
Ch. 3: The C in C++ - Continued - QUIZ What are the 3 ways a reference can be passed to a C++ function? QUIZ True or false: References behave like constant pointers with automatic dereferencing. QUIZ What
More informationLecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar
Examples of Software Programming and Data Structure Lecture 2 Sudeshna Sarkar Read an integer and determine if it is a prime number. A Palindrome recognizer Read in airline route information as a matrix
More informationprintf( Please enter another number: ); scanf( %d, &num2);
CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful
More informationC 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
More informationBut 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?
More informationRecap. 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
More informationTechnical Questions. Q 1) What are the key features in C programming language?
Technical Questions Q 1) What are the key features in C programming language? Portability Platform independent language. Modularity Possibility to break down large programs into small modules. Flexibility
More informationPage 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10?
Where Have We Been? Class Introduction Great Realities of Computing Int s are not Integers, Float s are not Reals You must know assembly Memory Matters Performance! Asymptotic Complexity It s more than
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #3 C Strings, Arrays, & Malloc 2007-06-27 Scott Beamer, Instructor Sun announces new supercomputer: Sun Constellation CS61C L3 C Pointers
More informationMotivation was to facilitate development of systems software, especially OS development.
A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.
More informationCS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018
CS 31: Intro to Systems Pointers and Memory Kevin Webb Swarthmore College October 2, 2018 Overview How to reference the location of a variable in memory Where variables are placed in memory How to make
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More informationA Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013
A Bad Name Optimization is the process by which we turn a program into a better one, for some definition of better. CS 2210: Optimization This is impossible in the general case. For instance, a fully optimizing
More informationCS16 Week 2 Part 2. Kyle Dewey. Thursday, July 5, 12
CS16 Week 2 Part 2 Kyle Dewey Overview Type coercion and casting More on assignment Pre/post increment/decrement scanf Constants Math library Errors Type Coercion / Casting Last time... Data is internally
More informationBasic Types, Variables, Literals, Constants
Basic Types, Variables, Literals, Constants What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet) But some machines had 7, or 9, or... A word is the basic
More information377 Student Guide to C++
377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided
More information