W03-05_C-Programming

W03-05_C-Programming - 03 C Programming CSC 230 Department...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
03 C Programming CSC 230 Department of Computer Science University of Victoria
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C Programming These notes cover aspects of C that are relevant to interfacing with ARM code and the understanding of computer architecture and organization These are NOT complete notes on C programming These notes are only a starting point Î consult any C anual (not just online) manual (not just online) 2
Background image of page 2
Important Concepts Here ± Variables and memory allocation for them ± Pointers egular control structures (IF/ELSE WHILE FOR ± Regular control structures (IF/ELSE, WHILE, FOR, SWITCH) ± Data structures, static allocation (arrays up to 2 imensions) dimensions) ± Declaration of a function or procedure ± Call to a function or procedure ± Input parameters passing by value ± Input parameters passing by reference ± Returning output parameters ± File I/O in Lab and by self study (documentation posted) 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Small Example 1 #include <stdio.h> /* include standard library */ int main() { /* define a function main */ int a, b, c; /* declare variables */ a = 3; /* assignment statements */ = 5; b 5; c = a + b; printf("a + b = %d\n", c); /* call libr. function */ hat exactly does a return 0; } What exactly does a declaration of “ int ” mean? main as a function called by OS and that returns to OS 4
Background image of page 4
C Integer Datatypes (assuming 32 bit words) hort 6 bit integer hort h1 h2 h3; short 16 bit integer Î short h1, h2, h3; or short int h1, h2, h3; int 32 bit integer Î int i, j, k; ong 32 or 64 bit integer? ng a b c; Long 32 or 64 bit integer? Î long a, b, c; or long int a, b, c; char 1 byte character Î char temp; Note: we can also attach the keyword unsigned to these declarations Î unsigned int clock; 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What does a declaration of an integer type mean exactly? int Csize, Num; 1. Ask to allocate space in RAM for 2 words of 32-bits (4 p ( bytes). 2. Where are they? No need to know precisely where in RAM, they are within the same “frame” of space in RAM where the program is allocated space overall. By using the labels the corresponding address is referenced and the location in memory accessed. 3. In the code, whenever “ Csize ” is used directly, it refers to the content of memory at the address for the allocation of “ Csize Î the program need never know e address itself the address itself. 4. Similarly for “ Num ” . 6
Background image of page 6
What about a data structure like an array? int Grades[6]; Consecutive elements Homogeneous type []; 1. It asks to allocate in memory 6 consecutive words of 32 bits each = 4 bytes each 2. The array name refers to the address of the leftmost word at position [0] 3. Each word can be accessed by its index relative to position [0] and its given address in memory Grades[0] Grades[2] Grades[4] Grades[1] Grades[3] Grades[5] Grades 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Consider each element of the array int Grades[6]; Distance Grades[0] Grades[2] Grades[4] 20 from Grades[0] Distance istance Grades[1] Grades[3] Grades[5] Grades 16 from Grades[0] Distance 8 from rades[0] Distance 4 from rades[0] Distance 0 from Grades[0] Distance 12 from Grades[0] Grades[0] Grades[0] 8
Background image of page 8
Consider the addresses of each element of the array int Grades[6]; Grades[0] Grades[2] Grades[4]
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2012 for the course CSC 230 taught by Professor Jasond.corless during the Summer '11 term at University of Victoria.

Page1 / 76

W03-05_C-Programming - 03 C Programming CSC 230 Department...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online