9/20/6Lecture 3 - Instruction Set - Al1 Program Design Examples.

Slides:



Advertisements
Similar presentations
CENG 311 Decisions in C/Assembly Language
Advertisements

The University of Adelaide, School of Computer Science
Lecture 9: MIPS Instruction Set
Deeper Assembly: Addressing, Conditions, Branching, and Loops
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
Assembler Programming Chapter 6. EEL-4746 Best Practices.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 6 – Introduction to MIPS Data Transfer & Decisions I Pieter Abbeel’s recent.
CS61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Program Design and Development
Flow Control Instructions
EECC250 - Shaaban #1 lec #7 Winter Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
EECC250 - Shaaban #1 lec #15 Winter The Software Design Process The design process of software for microprocessor systems should incorporate the.
MIPS Instruction Set Advantages
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Programmers Model and Instruction Set.
CIS Computer Programming Logic
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
9/20/6Lecture 3 - Instruction Set - Al1 Program Design.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 7 – Subroutines These are lecture notes to accompany the book SPARC Architecture,
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
ECE Lecture 1 1 L7 – A First Program Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
Lecture 2b Dr. Robert D. Kent.  Structured program development  Program control.
MAL 3 - Procedures Lecture 13. MAL procedure call The use of procedures facilitates modular programming. Four steps to transfer to and return from a procedure:
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Lec. 7 Introduction to Assembly Programming Dr. Tamer Samy Gaafar Microprocessors.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
1 Subroutines Advanced Programming. 2 Top-Down approach to problem solving Algorithm step by step description of how to solve a problem Divide and Conquer.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
Stack Operations Dr. Hadi AL Saadi.
MIPS Instruction Set Advantages
Homework Reading Labs PAL, pp
BYTE AND STRING MANIPULATON
Introduction to Gobbit Programming
ECE 3430 – Intro to Microcomputer Systems
Decision Making.
Microprocessor and Assembly Language
Chapter 4 Addressing modes
Procedures (Functions)
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Stack Frames Stack frame = block of memory located in the system stack that contains: return address input parameters (from calling program to subroutine)
Microprocessor and Assembly Language
Program Design Examples
EECE.3170 Microprocessor Systems Design I
Shift & Rotate Instructions)
SME1013 PROGRAMMING FOR ENGINEERS
by Richard P. Paul, 2nd edition, 2000.
Program Logic and Control
Program Logic and Control
Write a program to calculate x**y, given x and y.
Symbolic Instruction and Addressing
SME1013 PROGRAMMING FOR ENGINEERS
EECE.3170 Microprocessor Systems Design I
Where is all the knowledge we lost with information? T. S. Eliot
Jump & Loop instructions
Chapter 7 –Program Logic and Control
Chapter 7 –Program Logic and Control
Lecture 3 - Instruction Set - Al
ECE511: Digital System & Microprocessor
Lecture 3 - Instruction Set - Al
Presentation transcript:

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

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

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

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

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

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

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.

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/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

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

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.

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

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 $ and is 1,024 bytes

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

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

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

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

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

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

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)

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.