Anda di halaman 1dari 15

EECE237

Embedded Systems

Sukgi Choi, Ph.D.


Week 2-b, Fall 2017

(C)2017 CSU-Chico 1
Announcement for W2-b
In your email, make sure to put the class and
section number in the subject.
Reading assignment: Chapter 3. Skip 2.8
Quiz 1 on 9/7 (Thursday) 20 minutes
TI Launchpad kit (TM4C123G) and small parts
are coming on 9/5/17 (~$40)
Self study (not homework): 1.1, 1.2, 1.3, 1.4,
1.10, 1.13, 1.19, 1.25, 1.41, 2.5, 2.15
(C)2017 CSU-Chico 2
Todays Topics
Algorithm
Flow chart and its symbols
Interrupt
Concurrent and Parallel programming
Low-level language (Assembly)
High-level language ( C )

(C)2017 CSU-Chico 3
Algorithm
Algorithm is a high level description of the steps to execute
a task. An algorithm can be directly coded into a program.
But the algorithm itself is not dependent on a particular
program language.
An analogy is a cooking recipe.
Fix a dinner is not an algorithm.
Fix a hamburger is not an algorithm.
An algorithm describes each step of cooking an hamburger.
1. Prepare a bun and other ingredients
2. Make a paddy
3. Grill the paddy.
4. Put all of them together.

(C)2017 CSU-Chico 4
Algorithm - continued
An algorithm may be written in language. The
previous hamburger recipe is an algorithm.
Or, an algorithm may be drawn in a chart. This
is a flow chart.
Good grasp of what resources are available
precedes algorithm writing. This is the tricky
part.
You should know that a grill is available
beforehand.

(C)2017 CSU-Chico 5
Flow chart
A flow chart is a pictorial presentation of an
algorithm.
A flow chart is drawn from top (start) to bottom
(end). It flows.
Major blocks in a flow chart
Start and end (circle or oval)
Assignement block (rectangle)
Input/Output (parallelogram)
Condition (If) (diamond)
Subroutine call (rectangle with side bars)
Arrows connecting blocks and showing the flow.
(C)2017 CSU-Chico 6
Examples of flow charts

(C)2017 CSU-Chico 7
Interrupt
Two different methods of executing a task that
relies on external event. Ex. printing
1. Polling- Check if the event is ready constantly
until the event is ready. Polling is a part of the
main program. Easy coding but inefficient.
2. Interrupt Set a separate routine to check the
event readiness. Once set, the main resumes its
routine. When the event is ready, the main stops
and takes care of the task. The external event
interrupts the main. Complex but efficient.
(C)2017 CSU-Chico 8
Concurrent and parallel programing
Bare Metal: One processor runs one program at a
time.
Concurrent programing: One processor runs
multiple programs at the same time. The
multiplicity is illusion. An Operating System is
concurrent.
Parallel programming: A computer has multiple
processors. Multiple programs run on multiple
processors. An OS is required to manage the
multiple resources.
(C)2017 CSU-Chico 9
Assembly language
Assembly is a low-level language oriented more
for machine, not for human.
Assembler is a program that converts assembly
code to machine code. Machine code is a binary
code that a machine uses for execution.
Each code in assembly corresponds to a machine
code. Hence, assembly is machine dependent.
Assembly code is difficult to ready without
understanding how the machine works.
A program in assembly code is very efficient and
compact.
(C)2017 CSU-Chico 10
Assembly example
;This is an example of assembly code
area homework_1, code, readonly
export __main
__main b start
;Section 1
address_start equ 0x20002000
number_of_data equ 0x0a
address_step equ 0x04
start
ldr r5,=address_start;Get the starting address
mov r6, r5 ;copy r5 to r6
ldr r7, =number_of_data ;get the number of data
;Section 2
loop ldr r0, [r5] ; data at the starting address
ldr r1, [r6, #address_step]! ;increment r6 and fetch data
;This is a pre-indexed addressing. r6 changes by the step.
.....
(C)2017 CSU-Chico 11
C
C language is a high-low-level language oriented
more for human, than for human.
Compiler is a program that converts C code to
machine code. Each code in C is converted to
assembly first then to a machine code. C is
standardized. It is less, if not, machine
dependent.
C code is easier to ready even without
understanding how the machine works fully. But,
this is relative.
C code is more efficient and compact than other
high-level languages such as C++.
(C)2017 CSU-Chico 12
C Example
/* This is an example of a C program */
int main(void) {
int i, j = 0;
IO_Init(); //subroutine call
I2C2_init(); //subroutine call
while(I2C_GetFlagStatus(I2C2, I2C_ISR_BUSY) != RESET);
LCD_contrast(50); //subroutine call
LCD_backlight(8);
LCD_clear();
for (i=0; i < strlen(LCD_msg); i++)
LCD_write(0, i, LCD_msg[i]);
while (!ButtonPressed); //if condition
ButtonPressed = 0; //assignment

(C)2017 CSU-Chico 13
Compilation Process
Compilation uses multiple phases, usually three.
Linker collects all related programs such as a
library to the main program. It has relative
address.
Loader actually loads the binary code to the
machine memory. It has absolute address
Directives (Pseudo codes) are codes for the
compiler, not for machine. It tells how to compile.

(C)2017 CSU-Chico 14
The sea of words
Algorithm
Flow chart
Interrupt
Assembly
Assembler
C
Compiler
Linker
Loader
Binary code (machine code)
Low-level language
High-level language
Pseudo code

(C)2017 CSU-Chico 15

Anda mungkin juga menyukai