Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program Design Examples

Similar presentations


Presentation on theme: "Program Design Examples"— Presentation transcript:

1 Program Design Examples
9/20/6 Lecture 3 - Instruction Set - Al

2 Lecture 3 - Instruction Set - Al
Lecture Overview Have seen the initial part of Top down design Modular design Parameter Passing Stack and Local Variables Today Structured Programming continued Example 9/20/6 Lecture 3 - Instruction Set - Al

3 Assembler for HLL Expressions
HLL: IF (cond L) THEN Action_S Assume data, result of evaluating condition L, to be tested in D0. It has a value of either 1 (true) or 0 (false). TST.B D0 test low byte DO BEQ.S EXIT action_S EXIT The BEQ.S is a short 8-bit branch where the target address displacement is <= what can be specified by 8-bits 9/20/6 Lecture 3 - Instruction Set - Al

4 Assembler for HLL Expressions 2
HLL: IF (cond L) THEN S1 ELSE S2 TST.B D0 BEQ.S ELSE S1_actions BRA.S EXIT ELSE S2_actions EXIT 9/20/6 Lecture 3 - Instruction Set - Al

5 Assembler for HLL Expressions 3
HLL: FOR I = N1 TO N2 DO S MOVE.B #N1,D1 d1 lp cntr NEXT S_actions ADDQ.B #1,D1 inc lp cntr CMP.B #N2+1,D1 test BNE NEXT EXIT 9/20/6 Lecture 3 - Instruction Set - Al

6 Assembler for HLL Expressions 4
HLL: WHILE L DO S REPEAT TST.B DO BEQ.S EXIT if 0 quit S_actions within actions will perform a compare that leaves the TRUE(1) or FALSE(0) in D0 BRA REPEAT EXIT NOTE: B 9/20/6 Lecture 3 - Instruction Set - Al

7 Assembler for HLL Expressions 5
HLL: REPEAT S UNTIL L NEXT S_actions TST.B D0 BEQ NEXT EXIT 9/20/6 Lecture 3 - Instruction Set - Al

8 Assembler for HLL Expressions 6
HLL: FOR I=N DOWNTO -1 DO S MOVE.W #n,D1 NEXT S_actions DBRA D1,NEXT Decrement D1 and loop if not -1 9/20/6 Lecture 3 - Instruction Set - Al

9 Lecture 3 - Instruction Set - Al
Testability In the real world $$$ come into play Could test to degree that errors never occur Test to degree that is rational Structured code is more testable than alternatives Modules are units to be tested Interaction of modules is tests 9/20/6 Lecture 3 - Instruction Set - Al

10 Lecture 3 - Instruction Set - Al
Recoverabiltiy Also call exception handling What does the system do with erroneous data What does system do in response to certain classes or errors. Decision on what action to take when these conditions occur A poorly designed plan may be far worse than no plan at all. 9/20/6 Lecture 3 - Instruction Set - Al

11 Lecture 3 - Instruction Set - Al
Pseudocode (PDL) PDL is a way to write down an algorithm A compromise between HLL and assembler Facilitates the production of reliable code Much like modern HLLs 9/20/6 Lecture 3 - Instruction Set - Al

12 Lecture 3 - Instruction Set - Al
Program Specs D0 used for character input and output – low order byte of D0 D1 contains code of 0,1, or 2 0 – clear the buffer and reset pointers 1 – place character in D0 into buffer 2 – remove character from buffer to D0 Buffer starts at $ and is 1,024 bytes 9/20/6 Lecture 3 - Instruction Set - Al

13 Lecture 3 - Instruction Set - Al
Program Specs 2 Scratch storage may be placed after the end of the buffer – up to 32 bytes When buffer is full oldest data is overwritten – bit 31 of D0 is set to indicate overflow Underflow action – D0.B set to 0 – msb set No other register modified 9/20/6 Lecture 3 - Instruction Set - Al

14 Circular Buffer concept
9/20/6 Lecture 3 - Instruction Set - Al

15 Lecture 3 - Instruction Set - Al
PDL Level 1 Module: Circular_buffer Save working registers Select one of: Initialize System Input a character Output a character Restore working registers End Circular_buffer 9/20/6 Lecture 3 - Instruction Set - Al

16 Lecture 3 - Instruction Set - Al
PDL Level 2 Module: Circular_buffer Save working registers IF [D1]=0 THEN Initialize END IF IF [D2]=1 THEN Input_char END IF IF [D1]=2 THEN Output_char END IF End Circular_buffer 9/20/6 Lecture 3 - Instruction Set - Al

17 Lecture 3 - Instruction Set - Al
PDL – level 2 continued Initialize Count=0 In_pointer := Start Out_pointer := Start End Initialize 9/20/6 Lecture 3 - Instruction Set - Al

18 Lecture 3 - Instruction Set - Al
PDL – level 2 cont. Input_character Store new character Deal with any overflow End Input_character Routine is still a level too high to encode 9/20/6 Lecture 3 - Instruction Set - Al

19 Lecture 3 - Instruction Set - Al
PDL – level 3 Input_character Store new character at in_pointer In_pointer := In_pointer + 1 If In_pointer>End THEN In_pointer:=Start endif If Count < Max THEN Count:=Count+1 ELSE BEGIN Set overflow flag Out_pointer := Out_pointer + 1 9/20/6 Lecture 3 - Instruction Set - Al

20 Lecture 3 - Instruction Set - Al
cont IF Out_pointer>End Then Out_pointer:=Start END IF END End Input_character This can then be coded in assembler or even HLL. 9/20/6 Lecture 3 - Instruction Set - Al


Download ppt "Program Design Examples"

Similar presentations


Ads by Google