Download presentation
Presentation is loading. Please wait.
Published byRolf Logan Modified over 9 years ago
1
9/20/6Lecture 3 - Instruction Set - Al1 Program Design Examples
2
9/20/6Lecture 3 - Instruction Set - Al2 Lecture Overview Have seen the initial part of Top down design Modular design Parameter Passing Stack and Local Variables Today Structured Programming continued HLL Structures to assembler Example
3
9/20/6Lecture 3 - Instruction Set - Al3 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
4
If the data L to be tested in reg If the data L to be tested is in register D0 and the test is L = 0 with action S if L=0 Could do CMPI.W #0, D0 BNE around action S around following_instructions Note: This does explain how to do a test with the results of the test in D0. That would take a couple of instructions to do. Ref page 66. 9/20/6Lecture 3 - Instruction Set - Al4
5
9/20/6Lecture 3 - Instruction Set - Al5 Assembler for HLL Expressions 2 Here D0 has result of test of condition HLL: IF (cond L) THEN S1 ELSE S2 TST.B D0 BEQ.S ELSE S1_actions BRA.S EXIT ELSE S2_actions … EXIT
6
9/20/6Lecture 3 - Instruction Set - Al6 Assembler for HLL Expressions 3 HLL: FOR I = N1 TO N2 DO S MOVE.B #N1,D1 d1 is loop cntr NEXT S_actions ADDQ.B #1,D1 inc loop cntr CMP.B #N2+1,D1 test BNE NEXT EXIT
7
9/20/6Lecture 3 - Instruction Set - Al7 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: A while loop may or may not execute once. Why TST is at start.
8
9/20/6Lecture 3 - Instruction Set - Al8 Assembler for HLL Expressions 5 HLL: REPEAT S UNTIL L NEXT S_actions --and code that puts result of ‘L’ in D0 as T/F (F=0) TST.B D0 BEQ NEXT EXIT
9
9/20/6Lecture 3 - Instruction Set - Al9 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
10
9/20/6Lecture 3 - Instruction Set - Al10 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 tested
11
9/20/6Lecture 3 - Instruction Set - Al11 Recoverabiltiy Also called 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, such as divide by 0. A poorly designed plan may be far worse than no plan at all.
12
9/20/6Lecture 3 - Instruction Set - Al12 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
13
9/20/6Lecture 3 - Instruction Set - Al13 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 $01 0000 and is 1,024 bytes
14
9/20/6Lecture 3 - Instruction Set - Al14 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
15
9/20/6Lecture 3 - Instruction Set - Al15 Circular Buffer concept
16
9/20/6Lecture 3 - Instruction Set - Al16 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
17
9/20/6Lecture 3 - Instruction Set - Al17 PDL Level 2 Module: Circular_buffer Save working registers IF [D1]=0 THEN Initialize END IF IF [D1]=1 THEN Input_char END IF IF [D1]=2 THEN Output_char END IF End Circular_buffer
18
9/20/6Lecture 3 - Instruction Set - Al18 PDL – level 2 continued Initialize Count=0 In_pointer := Start Out_pointer := Start End Initialize
19
9/20/6Lecture 3 - Instruction Set - Al19 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
20
9/20/6Lecture 3 - Instruction Set - Al20 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)
21
9/20/6Lecture 3 - Instruction Set - Al21 continued IF Out_pointer>End Then Out_pointer:=Start END IF END END IF End Input_character This can then be coded in assembler or even HLL by translating HLL or pseudocode to assembler.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.