You are on page 1of 2

Lecture 4

Review Assembly language


Branches
If-then
If-then-else
For loops
While loops
Stack size is limited
void stackOverflow2(void){
uint32_t a[1000];
a[0] = 0;
}

Review switch interface


Review LED interface
Functions in assembly: Passing parameters in AAPCS
First four inputs in R0,R1,R2,R3
Return parameter in R0
Even number of stack pushes (8-byte alignment)
R0-R3,R12 are free to use and not save
To use R4-R11 you must save and restore them
To call another function you must save LR

System design
What does being in a state mean?
List state parameters
What is the starting state of the system?
Define the initial state
What information do we need to collect?
List the input data
What information do we need to generate?
List the output data
How do we move from one state to another?
Actions we could do
What is the desired ending state?
Define the ultimate goal
main

Switch
off
Example: Insulin Pump for diabetics on
(cruise control for constant speed driving) Read setpoint
States: too high; just right; too low; idle
Start: idle Output to pump
Inputs: user input, setpoint, measurement blood sugar
Outputs: status, insulin, alarms, call 911 wait
Flowchart Read glucose

high low

ok
Increase Output Decrease Output
Lecture 4

Successive Refinement
Stepwise Refinement
Systematic Decomposition
Start with a task and decompose the task into a set of simpler subtasks
Subtasks are decomposed into even simpler sub-subtasks
Each subtask is simpler than the task itself
Make design decisions
document decisions and subtask requirements
Ultimately, subtask is so simple, it can be converted to software
Structured programming
  Sequential, conditional, iterative, interrupt
 “do A then do B” → sequential
 “do A and B in either order” → sequential (parallel)
 “if A, then do B” → conditional
 “for each A, do B” → iterative
 “do A until B” → iterative
 “repeat A over & over forever” → iterative (condition always true)
 “on external event do B” → interrupt
 “every t msec do B” → interrupt

Abstraction
Separate what it does from how it works
LED_Init
LED_On
LED_Off
LED_Toggle
LED_PWM(uint32_t duty)
Lab 3 demonstrations

You might also like