Download presentation
Presentation is loading. Please wait.
Published byGodfrey Ferguson Modified over 9 years ago
1
© 2000 Morgan Kaufman Overheads for Computers as Components Program design and analysis zDesign patterns zRepresentations of programs zAssembly and linking
2
© 2000 Morgan Kaufman Overheads for Computers as Components Design patterns zDesign pattern: generalized description of the design of a certain type of program. zDesigner fills in details to customize the pattern to a particular programming problem.
3
© 2000 Morgan Kaufman Overheads for Computers as Components List design pattern List create() add-element() delete-element() find-element() destroy() List-element 1 *
4
© 2000 Morgan Kaufman Overheads for Computers as Components Design pattern elements zClass diagram zState diagrams zSequence diagrams zetc.
5
© 2000 Morgan Kaufman Overheads for Computers as Components State machine zState machine is useful in many contexts: yparsing user input yresponding to complex stimuli ycontrolling sequential outputs
6
© 2000 Morgan Kaufman Overheads for Computers as Components State machine example idle buzzerseated belted no seat/- seat/timer on no belt and no timer/- no belt/timer on belt/- belt/ buzzer off Belt/buzzer on no seat/- no seat/ buzzer off
7
© 2000 Morgan Kaufman Overheads for Computers as Components State machine pattern State machine state output step(input)
8
© 2000 Morgan Kaufman Overheads for Computers as Components C implementation #define IDLE 0 #define SEATED 1 #define BELTED 2 #define BUZZER 3 switch (state) { case IDLE: if (seat) { state = SEATED; timer_on = TRUE; } break; case SEATED: if (belt) state = BELTED; else if (timer) state = BUZZER; break; … }
9
© 2000 Morgan Kaufman Overheads for Computers as Components Circular buffer x1x2x3x4x5x6 t1t1 t2t2 t3t3 Data stream x1x2x3x4 Circular buffer x5x6x7
10
© 2000 Morgan Kaufman Overheads for Computers as Components Circular buffer pattern Circular buffer init() add(data) data head() data element(index)
11
© 2000 Morgan Kaufman Overheads for Computers as Components Circular buffer implementation: FIR filter int circ_buffer[N], circ_buffer_head = 0; int c[N]; /* coefficients */ … int ibuf, ic; for (f=0, ibuff=circ_buff_head, ic=0; ic<N; ibuff=(ibuff==N-1?0:ibuff++), ic++) f = f + c[ic]*circ_buffer[ibuf];
12
© 2000 Morgan Kaufman Overheads for Computers as Components Models of programs zSource code is not a good representation for programs: yclumsy; yleaves much information implicit. zCompilers derive intermediate representations to manipulate and optimize the program.
13
© 2000 Morgan Kaufman Overheads for Computers as Components Data flow graph zDFG: data flow graph. zDoes not represent control. zModels basic block: code with one entry, exit. zDescribes the minimal ordering requirements on operations.
14
© 2000 Morgan Kaufman Overheads for Computers as Components Single assignment form x = a + b; y = c - d; z = x * y; y = b + d; original basic block x = a + b; y = c - d; z = x * y; y1 = b + d; single assignment form
15
© 2000 Morgan Kaufman Overheads for Computers as Components Data flow graph x = a + b; y = c - d; z = x * y; y1 = b + d; single assignment form + - +* DFG a bc d z x y y1
16
© 2000 Morgan Kaufman Overheads for Computers as Components DFGs and partial orders Partial order: z a+b, c-d; b+d x*y Can do pairs of operations in any order. + - +* a bc d z x y y1
17
© 2000 Morgan Kaufman Overheads for Computers as Components Control-data flow graph zCDFG: represents control and data. zUses data flow graphs as components. zTwo types of nodes: ydecision; ydata flow.
18
© 2000 Morgan Kaufman Overheads for Computers as Components Data flow node Encapsulates a data flow graph: Write operations in basic block form for simplicity. x = a + b; y = c + d
19
© 2000 Morgan Kaufman Overheads for Computers as Components Control cond T F Equivalent forms value v1 v2 v3 v4
20
© 2000 Morgan Kaufman Overheads for Computers as Components CDFG example if (cond1) bb1(); else bb2(); bb3(); switch (test1) { case c1: bb4(); break; case c2: bb5(); break; case c3: bb6(); break; } cond1 bb1() bb2() bb3() bb4() test1 bb5()bb6() T F c1 c2 c3
21
© 2000 Morgan Kaufman Overheads for Computers as Components for loop for (i=0; i<N; i++) loop_body(); for loop i=0; while (i<N) { loop_body(); i++; } equivalent i<N loop_body() i++ T F i=0
22
© 2000 Morgan Kaufman Overheads for Computers as Components Assembly and linking zLast steps in compilation: HLL compile assembly assemble HLL assembly link executable load
23
© 2000 Morgan Kaufman Overheads for Computers as Components Multiple-module programs zPrograms may be composed from several files. zAddresses become more specific during processing: yrelative addresses are measured relative to the start of a module; yabsolute addresses are measured relative to the start of the CPU address space.
24
© 2000 Morgan Kaufman Overheads for Computers as Components Assemblers zMajor tasks: ygenerate binary for symbolic instructions; ytranslate labels into addresses; yhandle pseudo-ops (data, etc.). zGenerally one-to-one translation. zAssembly labels: ORG 100 label1ADR r4,c
25
© 2000 Morgan Kaufman Overheads for Computers as Components Symbol table ADD r0,r1,r2 xxADD r3,r4,r5 CMP r0,r3 yySUB r5,r6,r7 assembly code xx0x8 yy0x10 symbol table
26
© 2000 Morgan Kaufman Overheads for Computers as Components Symbol table generation zUse program location counter (PLC) to determine address of each location. zScan program, keeping count of PLC. zAddresses are generated at assembly time, not execution time.
27
© 2000 Morgan Kaufman Overheads for Computers as Components Symbol table example ADD r0,r1,r2 xxADD r3,r4,r5 CMP r0,r3 yySUB r5,r6,r7 xx0x8 yy0x16 PLC=0x4PLC=0x8PLC=0x12PLC=0x16
28
© 2000 Morgan Kaufman Overheads for Computers as Components Two-pass assembly zPass 1: ygenerate symbol table zPass 2: ygenerate binary instructions
29
© 2000 Morgan Kaufman Overheads for Computers as Components Relative address generation zSome label values may not be known at assembly time. zLabels within the module may be kept in relative form. zMust keep track of external labels---can’t generate full binary for instructions that use external labels.
30
© 2000 Morgan Kaufman Overheads for Computers as Components Pseudo-operations zPseudo-ops do not generate instructions: yORG sets program location. yEQU generates symbol table entry without advancing PLC. yData statements define data blocks.
31
© 2000 Morgan Kaufman Overheads for Computers as Components Linking zCombines several object modules into a single executable module. zJobs: yput modules in order; yresolve labels across modules.
32
© 2000 Morgan Kaufman Overheads for Computers as Components external reference entry point Externals and entry points xxxADD r1,r2,r3 B a yyy%1 aADR r4,yyy ADD r3,r4,r5
33
© 2000 Morgan Kaufman Overheads for Computers as Components Module ordering zCode modules must be placed in absolute positions in the memory space. zLoad map or linker flags control the order of modules. module1 module2 module3
34
© 2000 Morgan Kaufman Overheads for Computers as Components Dynamic linking zSome operating systems link modules dynamically at run time: yshares one copy of library among all executing programs; yallows programs to be updated with new versions of libraries.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.