






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of modular software development in the context of embedded systems. It covers the benefits of modular programming, the concept of software modules, and the implementation of modular software in assembly language. The document also discusses issues in modular software and provides guidelines for dividing a software task into modules. Slides include examples of module implementation and calling sequences, as well as rules for layered software systems.
Typology: Study notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!







& '
% $
Chris J. Myers
Lecture 4: Software Development (cont)
& '
% $
Modular Software Development
distinct and independent modules.Modular programming breaks software problems in
Modular software development provides:
Functional abstraction to allow software reuse.
Complexity abstraction (i.e., divide and conquer).
Portability.
program module
is a self-contained software task with
clear
entry
and
exit points
their entirety perform a well-defined set of tasks.Can be a collection of subroutines or functions that in
1
Slide 3
& '
Software Module
Slide 4
& '
Stack Contents
jsr movb ss,1,-sp ;push parameter onto stack
sqrt
;call sqrt subroutine
stab ttins
;save result
2
& '
% $
Example Module in Assembly
sqrt pshy
leas -4,sptsy
;allocate t,oldt,s
bne nextdec cnt,ystab t,y...ldaa s8,yclrb
done tys
rtspuly
& '
% $
Returning Multiple Parameters in Assembly 1
module: ldaa #
ldxldab #
ldy
rts
;returns 4 parameters in 4 registers
********calling sequence******
jsr module
3
Slide 7
& '
Returning Multiple Parameters in Assembly 2
module movb #2,data2,sp ;2nd parameter onto stackmodule movb #1,data1,sp ;1st parameter onto stackdata2 equ 3 data1 equ 2
rts
*******calling sequence******
pulajsr moduleleas -2,sp ;allocate space for results
;1st parameter from stack
pulastaa first
;2nd parameter from stack
staa second
Slide 8
& '
More Issues in Modular Software
stack and return parameters in the same way.All exit points in an assembly routine must balance the
harder to reuse at a later time.Performing unnecessary I/O in a subroutine makes it
of modules that can access them should be restricted.I/O devices must be considered global, and the number
Information hiding
means to separate mechanism from
policies (i.e., hiding the inner workings from the user).
4
Slide 13
& '
% $
Layered Approach for Parallel Port
Slide 14
& '
% $
Three-Layer Software System (High Level)
org
$E
main:
lds
#$00FF
bsr
Initialize ;simple call to a function
loop:
bsr
PrintInfo
;simple call to a function
bra
loop
Initialize:
ldaa #
;function code for InitPrinter
swi
;call to middle level
org $FFFErts
;high level vector (reset)
fdb
main
7
Slide 15
& '
Three-Layer Software System (Middle Level)
org
$F
swihandler:
cmpa #
;function code for InitPrinter
bne
notIP
bsr
InitPrinter
bra
swidone
notIP:
cmpa #
;function code for PrintInfo
bne
notPI
bsr
PrintInfo
bra
swidone
notPI:
;****error
swidone:
rti
InitPrinter: ldaa #
;function code for InitIEEE
ldx
$FF
;vector into low level
jsr
0,x
;call lower level
orgrts
$FFF
;middle level vector (SWI)
fdb
swihandler
Slide 16
& '
Three-Layer Software System (Low Level)
org
$F
lowhandler:
cmpa #
;function code for InitIEEE
bne
notInit
bsr
InitIEEE
bra
lowdone
notInit:
cmpa #
;function code for SetDAV
bne
notDAV
bsr
SetDAV
bra
lowdone
notDAV:
;rest of the functions
lowdone:
rts
InitIEEE:
;access to hardware
orgrts
$FF
; Lower level vector
fdb
lowhandler
8
& '
% $
Layered Software Rules
variable in another layer (w/o going through a gate).
level’s handler(s).
it is the purpose of the module to do such I/O.
& '
% $
Threads
9
Slide 19
& '
Interrupts and Threads
Slide 20
& '
Recursion
A program segment is
reentrant
if it can be concurrently
executed by two (or more) threads.
recursive
program is one that calls itself.
When we draw a calling graph, a circle is formed.
Recursive subroutines must be reentrant.
void OutUDec(unsigned int number){memory, but use more stack space and are slower.Often easy to prove correct and use less permanent
if (number>=10){
OutUDec(number%10); }OutUDec(number/10);
else
OutChar(number+’0’); }
10
& '
% $
SCI Initialization
init
ldaa #$
;1200 baud
ldaa #$00staa BAUD
;mode
ldaa #$0Cstaa SCCR
;tie=rie=0,
rtsstaa SCCR2 ;te=re=
& '
% $
SCI Input
InChar ldaa SCSR
;status
bita #$
;rdrf?
beq
InChar
ldaa SCDR
;SCI data
rts
13
Slide 27
& '
SCI Output
OutChar ldab SCSR
;status
bitb #$
;tdre?
beq
OutChar
staa SCDR
;output
rts
Slide 28
& '
Input Decimal Number
; Inputs: ; Input a byte from the SCI
none
; ; Outputs: Reg B 0 to 255
C=1 if error
DIGIT
rmb
1
;global
InUDec
clrb
;N=
InUDloop bsr
InChar
;Next input
bsr
OutChar ;Echo
cmpa #
;done if cr
beq
InUDret ;with C=
blocmpa #’
InUDerr ;error?
bhicmpa #’
InUDerr ;error?
14
Slide 29
& '
% $
Input Decimal Number (cont)
anda #$0F
;0-9 digit
tstamulldaa #10staa DIGIT
;overflow?
bne
InUDerr
braaddb DIGIT ;N=10*N+DIGIT
InUDloop
InUDerr
bsrldaa #’?
OutChar
secclrb
;error flag
InUDret
rts
Slide 30
& '
% $
SCI Output String
; Inputs: ; Output a string to the SCI
Reg X points to string
String ends with 0
OutString ldaa 0,X; Outputs: none
beq
OSdone
;0 at end
bsr
OutChar
brainx
OutString
OSdone
rts
15
Slide 31
& '
SCI Output Decimal Number
; Inputs: ; Output unsigned byte to the SCI
Reg B= 0 to 255,
print as 3 digit ascii
OutUDec; Outputs: none
clra
;Reg D=number
ldx
idiv
;X=num/100,
xgdx
;B=100s digit
bsradda #’0 ;A=100’s asciitba
OutChar
xgdx
;D=num
ldx
Slide 32
& '
SCI Output Decimal Number (cont) idiv
;X=num/10,
xgdx
;B=tens digit
bsradda #’0 ;A=tens asciitba
OutChar
xgdx
;D=num
bsradda #’0 ;A=ones asciitba
OutChar
rts
16
& '
Performance (Dynamic) Debugging
Performance debugging
is verification of timing behavior.
System is run and dynamic behaviors of I/O checked.
before
rmb
2
;TCNT value before the call
elasped rmb
2
;# of cycles to execute sqrt
movw
TCNT,before
movb
ss,1,-sp
;push parameter on stack
jsr
sqrt
;call sqrt module
stabins
tt
;save result
ldd
TCNT
;TCNT value after the call
subd
before
std
elasped
;execute time in cycles
& '
Profiling
Profiling
collects time history of strategic variables.
techniques to determine the thread activity.When multiple threads are running can use these
19