Variables (2D) Young Won Lim 3/28/18

Similar documents
Expressions (2E) Young Won Lim 3/10/18

Expressions (2E) Young Won Lim 4/9/18

Pointers (2G) Young Won Lim 3/7/18

Pointers (1A) Young Won Lim 3/5/18

Arrays and Strings (2H) Young Won Lim 3/7/18

Program Structure (2A) Young Won Lim 3/8/18

Pointers (1A) Young Won Lim 1/5/18

Pointers (1A) Young Won Lim 1/9/18

Pointers (1A) Young Won Lim 11/1/17

Program Structure (2A) Young Won Lim 5/28/18

Applications of Pointers (1A) Young Won Lim 12/26/17

Pointers (1A) Young Won Lim 2/6/18

ARM Assembly Exercise (1B) Young Won Lim 7/16/16

Pointers (1A) Young Won Lim 1/14/18

Pointers (1A) Young Won Lim 1/22/18

Pointers (1A) Young Won Lim 2/10/18

Pointers (1A) Young Won Lim 10/18/17

Applications of Structures (1A) Young Won Lim 12/8/17

Function Overview (1A) Young Won Lim 10/23/17

Applications of Pointers (1A) Young Won Lim 2/27/18

Applications of Arrays (1A) Young Won Lim 2/11/17

Applications of Pointers (1A) Young Won Lim 3/14/18

Pointers (1A) Young Won Lim 10/23/17

Applications of Pointers (1A) Young Won Lim 3/21/18

Arrays (1A) Young Won Lim 12/4/17

Structures (2I) Young Won Lim 4/17/18

ELF (1A) Young Won Lim 10/22/14

Applications of Arrays (1A) Young Won Lim 3/15/17

Applications of Structures (1A) Young Won Lim 12/4/17

Pointers (1A) Young Won Lim 12/4/17

Overview (1A) Young Won Lim 9/14/17

Applications of Pointers (1A) Young Won Lim 4/11/18

Overview (1A) Young Won Lim 9/9/17

Applications of Pointers (1A) Young Won Lim 3/31/18

Overview (1A) Young Won Lim 9/25/17

Type (1A) Young Won Lim 2/17/18

Structures (2I) Young Won Lim 3/7/18

Applications of Pointers (1A) Young Won Lim 1/5/18

Applications of Pointers (1A) Young Won Lim 4/24/18

Arrays (1A) Young Won Lim 1/27/17

Number System (1A) Young Won Lim 7/7/10

Memory Arrays (4H) Gate Level Design. Young Won Lim 3/15/16

Memory (1A) Young Won Lim 9/7/17

File (1A) Young Won Lim 11/25/16

Accessibility (1A) Young Won Lim 8/22/13

Preprocessing (2K) Young Won Lim 3/7/18

Example 1. Young Won Lim 11/17/17

Example 1 : using 1-d arrays. Young Won Lim 12/13/17

Structure (1A) Young Won Lim 7/30/13

Structures (1A) Young Won Lim 12/4/17

Structures (1A) Young Won Lim 11/8/16

Example 2. Young Won Lim 11/24/17

Example 3 : using a structure array. Young Won Lim 11/25/17

Class (1A) Young Won Lim 9/8/14

Example 3. Young Won Lim 11/22/17

Applications of Array Pointers (1A) Young Won Lim 11/22/18

Algorithms Bubble Sort (1B) Young Won Lim 4/5/18

ELF (1A) Young Won Lim 3/24/16

The Complexity of Algorithms (3A) Young Won Lim 4/3/18

Class (1A) Young Won Lim 11/20/14

Embedded System Design

HW / SW Implementation Overview (0A) Young Won Lim 7/16/16

Lecture 3. Variables. Variables

ARM Architecture (1A) Young Won Lim 3/20/18

ARM PROGRAMMING. When use assembly

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

Binary Search Tree (3A) Young Won Lim 6/2/18

Functions (4A) Young Won Lim 5/8/17

Day08 A. Young W. Lim Mon. Young W. Lim Day08 A Mon 1 / 27

Binary Search Tree (2A) Young Won Lim 5/17/18

Functions (4A) Young Won Lim 3/16/18

Monad (1A) Young Won Lim 6/9/17

Polymorphism (1A) Young Won Lim 8/22/13

ARM Cortex-M4 Programming Model

Polymorphism (1A) Young Won Lim 8/15/13

Lecture 3: Instruction Set Architecture

Eulerian Cycle (2A) Young Won Lim 4/26/18

Polymorphism Overview (1A) Young Won Lim 2/20/18

Programming in C++ 4. The lexical basis of C++

University of Texas at Austin Electrical and Computer Engineering Department. EE319K, Embedded Systems, Spring 2013 Final Exam

Binary Search Tree (3A) Young Won Lim 6/4/18

Exam 1. Date: March 1, 2019

Binary Search Tree (3A) Young Won Lim 6/6/18

Haskell Overview II (2A) Young Won Lim 8/9/16

Program SoC using C Language

Algorithms Overview (1A) Young Won Lim 3/29/18

Structure (1A) Component

Day02 A. Young W. Lim Sat. Young W. Lim Day02 A Sat 1 / 12

Exam 1. EE319K Spring 2013 Exam 1 (Practice 1) Page 1. Date: February 21, 2013; 9:30-10:45am. Printed Name:

Exam 1. Date: March 1, 2019

EE319K (Gerstlauer), Spring 2013, Midterm 1 1. Midterm 1. Date: February 21, 2013

C Pointers. 6th April 2017 Giulio Picierro

ARM Architecture and Assembly Programming Intro

Modes and Levels. Registers. Registers. Cortex-M3 programming

a data type is Types

Exercise: Inventing Language

EECS 388 C Introduction. Gary J. Minden August 29, 2016

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

Exam 1. Date: February 23, 2018

CSE /003, Fall 2014, Homework 4 Due October 7, 2014 in Class (at 2:00pm for 002, 3:30pm for 003)

Transcription:

Variables (2D)

Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Please send corrections (or suggestions) to youngwlim@hotmail.com. This document was produced by using LibreOffice.

Based on Embedded Software in C for an ARM Cortex M http://users.ece.utexas.edu/~valvano/volume1/ 3

Initialization short MyVariable; /* variable allows read/write access */ const short MyConstant=50; /* constant allows only read access */ #define fifty 50 void main(void) { MyVariable=50; /* write access to the variable */ OutSDec(MyVariable); /* read access to the variable */ OutSDec(MyConstant); /* read access to the constant */ OutSDec(50); /* "50" is a literal */ OutSDec(fifty); /* fifty is also a literal */ 4

Global Variables long TheGlobal; /* a regular global variable*/ void main(void) { TheGlobal = 1000; LDR R0,=1000 LDR R1,=TheGlobal STR R0,[R1] // address 5

Static Variables static short TheGlobal; /* a static global variable*/ void main(void) { TheGlobal = 1000; void main(void) { static stort TheLocal; /* a static local variable*/ TheLocal = 1000; 6

Static Local Variables void function1(void) { static short TheCount; TheCount = TheCount+1; void function2(void) { static short TheCount; TheCount = TheCount+1; 7

Volatile volatile unsigned long Time; void SysTick_Handler(void) { /* every 16ms */ Time = Time+1; void main(void){ SysTick_Init(); Time = 0; while (Time<100) { ; /* wait for 100 counts of the 16 ms timer*/ Time = 0; while (Time<100) { ; 8

Automatic unsigned char data[100]; #define GPIO_PORTA_DATA_R (*((volatile unsigned long *) 0x400043FC)) void Collect(void) { short i; for (i=0;i<100;i++) { /* collect 100 measurements */ data[i] = GPIO_PORTA_DATA_R; /* collect ith measurement */ int *BadFunction(void) { int z; z = 1000; return (&z); // returning the address of an automatic variable 9

Automatic Variables void fun(void) { long y1,y2,y3; y1 = 1000; y2 = 2000; y3 = y1+y2; /* 3 local variables*/ fun SUB SP,#12 ; y1 = 1000 LDR R0,=1000 STR R0,[SP,#0] ; y2 = 2000 LDR R0,=2000 STR R0,[SP,#4] ; y3 = y1+y2 LDR R0,[SP,#0] LDR R1,[SP,#4] ADD R2,R0,R1 STR R2,[SP,#8] ADD SP,#12 BX LR ; allocate3 local variables ; y1 ; y2 ;set y3 ;deallocate 10

Constant Local short TheGlobal; void main(void){ const short TheConstant=1000; /* a regular global variable*/ /* a constant local*/ TheGlobal=TheConstant; 11

External extern short ExtGlobal; /* an external global variable*/ void main(void){ ExtGlobal=1000; 12

Variable Scope unsigned char x; /* a regular global variable*/ void sub(void) { x=1; { unsigned char x; /* a local variable*/ x=2; { unsigned char x; /* a local variable*/ x=3; PORTA=x; PORTA=x; PORTA=x; 13

Scope void sub(void) { int x; /* a valid local variable declaration */ x=1; int y; /* This declaration is improper */ y=2; 14

Declaration Declaration Comment Range unsigned char uc; 8-bit unsigned number 0 to +255 char c1,c2,c3; three 8-bit signed numbers -128 to +127 unsigned int ui; 32-bit unsigned number 0 to +4294967296 int i1,i2; two 32-bit signed numbers -2147483648L to 2147483647L unsigned short us; 16-bit unsigned number 0 to +65535 short s1,s2; two 16-bit signed numbers -32768 to +32767 long l1,l2,l3,l4; four signed 32 bit integers -2147483648L to 2147483647L unsigned long ui; 32-bit unsigned number 0 to +4294967296 float f1,f2; two 32-bit floating numbers not recommended double d1,d2; two 64-bit floating numbers not recommended 15

Storage Classes Modifier auto extern static register Comment automatic, allocated on the stack defined in some other program file permanently allocated attempt to implement an automatic using a register instead of on the stack 16

Modifiers Modifier volatile const unsigned signed Comment can change value by means other than the current program fixed value, defined in the source code and can not be changed during execution range starts with 0 includes only positive values range includes both negative and positive values 17

Const Modifier void LegalFuntion(short in) { while (in) { UART_OutChar(Ret); in--; void NotLegalFuntion(const short in) { while (in){ UART_OutChar(13); in--; void NotLegalFuntion2(void) { const short count=5; while (count) { UART_OutChar(13); count--; // this operation is illegal // this operation is illegal 18

Promotion char x; /* signed 8 bit global */ unsigned short y; /* unsigned signed 16 bit global */ void sub(void) { y=y+x; /* x treated as unsigned even though defined as signed */ 19

Initialization of Global Variables short I; /* 16 bit global */ const short J=96; /* 16 bit constant */ #define K 97; void main(void) { I=J; I=K; /* poor style */ /* good style */ int I=95; int I; void main(void) { void main(void) { I=95; 20

References [1] Essential C, Nick Parlante [2] Efficient C Programming, Mark A. Weiss [3] C A Reference Manual, Samuel P. Harbison & Guy L. Steele Jr. [4] C Language Express, I. K. Chun [5] A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux http://cseweb.ucsd.edu/~ricko/cse131/teensyelf.htm [6] http://en.wikipedia.org [7] http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html [8] http://csapp.cs.cmu.edu/public/ch7-preview.pdf