UNIVERSITY OF INFORMATION TECHNOLOGY

Low-Level C Programming

ThS. Le Hoai Nghia

nghialh@uit.edu.vn

February 2009

Low-Level C Programming – p. 1/49

Goals

Low-Level C Programming – p. 2/49

Like Writing English

Low-Level C Programming – p. 3/49

Arithmetic

Low-Level C Programming – p. 4/49

Simple benchmarks

Low-Level C Programming – p. 5/49

Simple benchmarks

Low-Level C Programming – p. 6/49

C Arithmetic Trivia

Low-Level C Programming – p. 7/49

Arithmetic Lessons

Low-Level C Programming – p. 8/49

Bit Manipulation

Low-Level C Programming – p. 9/49

Bit-manipulation basics

Low-Level C Programming – p. 10/49

Advanced bit manipulation

Low-Level C Programming – p. 11/49

Faking Multiplication

Low-Level C Programming – p. 12/49

Faking Multiplication

Low-Level C Programming – p. 13/49

Faking Division

Low-Level C Programming – p. 14/49

Multi-way branches

Low-Level C Programming – p. 15/49

Nios code for if-then-else

Low-Level C Programming – p. 16/49

Nios code for switch (1)

Low-Level C Programming – p. 17/49

Nios code for switch (2)

Low-Level C Programming – p. 18/49

Computing Discrete Functions

Low-Level C Programming – p. 19/49

Computing Discrete Functions

Low-Level C Programming – p. 20/49

Function calls

Low-Level C Programming – p. 21/49

Code for foo() (unoptimized)

Low-Level C Programming – p. 22/49

Code for foo() (optimized)

Low-Level C Programming – p. 23/49

Strength Reduction

Low-Level C Programming – p. 24/49

Unoptimized array code (fragment)

Low-Level C Programming – p. 25/49

Unoptimized pointer code (fragment)

Low-Level C Programming – p. 26/49

Optimized (–O2) array code

Low-Level C Programming – p. 27/49

Optimized (–O2) pointer code

Low-Level C Programming – p. 28/49

How Rapid is Rapid?

Low-Level C Programming – p. 29/49

Double-checking

Low-Level C Programming – p. 30/49

Features in order of increasing cost

Low-Level C Programming – p. 31/49

Storage Classes in C

Low-Level C Programming – p. 32/49

Dynamic Storage Allocation

Low-Level C Programming – p. 33/49

Dynamic Storage Allocation

Low-Level C Programming – p. 34/49

Simple Dynamic Storage Allocation

Low-Level C Programming – p. 35/49

Dynamic Storage Allocation

Low-Level C Programming – p. 36/49

Simple Dynamic Storage Allocation

Low-Level C Programming – p. 37/49

Storage Classes Compared

Low-Level C Programming – p. 38/49

Memory-Mapped I/O

Low-Level C Programming – p. 39/49

Memory-Mapped I/O Access in C

Low-Level C Programming – p. 40/49

What’s With the Volatile?

Low-Level C Programming – p. 41/49

Altera I/O

Low-Level C Programming – p. 42/49

HW/SW Communication Styles

Low-Level C Programming – p. 43/49

HW/SW Communication: Interrupts

Low-Level C Programming – p. 44/49

Unix Signals

Low-Level C Programming – p. 45/49

Interrupts under Altera (1)

Low-Level C Programming – p. 46/49

Interrupts under Altera (2)

Low-Level C Programming – p. 47/49

Debugging Skills

Low-Level C Programming – p. 48/49

The Edwards Way to Debug

Low-Level C Programming – p. 49/49