Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6 Introduction to Data Structures. Defining Constant EQU XVALEQU7 MOVE.B#XVAL, D0.

Similar presentations


Presentation on theme: "Chapter 6 Introduction to Data Structures. Defining Constant EQU XVALEQU7 MOVE.B#XVAL, D0."— Presentation transcript:

1 Chapter 6 Introduction to Data Structures

2 Defining Constant EQU XVALEQU7 MOVE.B#XVAL, D0

3 Defining Variables with DC and DS For temporary storage of value Why we do not store it is registers? –Address & data registers are limited to 16 Initialize the memory DC – Define Constant DS – Define Storage DC.size This is particularly useful when we initialize an array of data or collection of identical data types. MNODC.B1, 2, 3, 4 STU DC.B‘Hello!’ When we want to reserve the space for the variable without initializing them then we use DS directive

4 Question How many bytes in total is reserved by the three statements below. SVALDS.B6 TVALDS.W2 UVALDS.BL3

5 Accessing one Dimensional Array MOVE.B(A0, D7), D0// read MOVE.BD0, (A0, D7)// write

6 Designing Modules Always design smaller modules for handeling your program. Some of the popular module may be –Initialize –Getword –Lookup –Insert –Makecount –Increase

7 Loops If-Else Loop –BSRLookup –CMPI.B#0, D5 –BEQThenCode –Code for else Repeat-Until Loop – MOVE.B#100, D2 –AGAINBSRGETDATA – BSRProcessData – SUBI.B#1, D2 – BNEAGAIN

8 LOOPS Do-While Loop –WHILECMPI.B#’A’, D1 – BEQ NEXT – – BRA WHILE –NEXT ---- CASE Statement – CMPI.B#0, D1 – BNEC1 – CLR.BD2 – BRANext –C1CMPI.B#1, D1 – BNEC2 – ADDI.B#1, D2 – BRANext –C2CMPI.B#2, D2 – BNENext – SUBI.B#1, D2 –Next----

9

10 Accessing 1-D Arrays EA : Effective Address Base: Base Address, The starting address of the array Index: Element Size Offset: Offset into array to element’s position EA = Base + Offset Offset = Size * Index Example: The starting address of a word array is 830C, What is the address of the word whose index value is 5

11 Accessing 2-D Arrays It is like a matrix containing row and column We can store the values using the keyword DC Example: –Sub DC.B6, 1, 8 – DC.B7, 5, 3 – DC.B2, 9, 4 – Val = sub [row] [column] Col: Column Number Row Offset: Offset into matrix to element’s row Column Offset: Offset into row to element’s position EA = Base + Rowoffset + ColumnOffset –RowOffset = Row * Size * NCols –ColumnOffset = Size * Col

12 Searching an Item from the DataBase ORG$8000 DATA DS.B100 ITEM DS.B1 ORG$8100 FINDBYTEMOVEA.L#DATA, A0 MOVE.W#99, D0 MOVE.BITEM, D1 COMPARE CMP.B(A0)+, D1 BEQFOUND DBRAD0, COMPARE ANDI#$FE, CCR RTS FOUND ORI#$01, CCR RTS

13 STACK Push CMPA.LA0,A1 BEQ STKFULL MOVE.LD0, -(A0) CLR.BD1 RTS STKFULL MOVE.B#$80, D1 RTS CMPA.LA0, A2 BEQSTKEMPTY MOVE.L(A0)+, D0 CLR.BD1 RTS STKEMPTYMOVE.L#$FF, D1 RTS

14 QUEUE A0: Pointer to write operation A1: Pointer to read operation A2: Contains the end of queue Address A3: Contains the beginning of queue Address INQUEQE CMPA.LA0, A2 BNENO MOVEA.LA3, A0 NO MOVE.LD0, (A0) SUBA.L #4, A0 RTS OUTQUEUE CMPA.LA1, A2 BNE NO1 MOVEA.LA3, A1 NO1 MOVE.L(A1), D0 SUBA.L#4, A1 RTS


Download ppt "Chapter 6 Introduction to Data Structures. Defining Constant EQU XVALEQU7 MOVE.B#XVAL, D0."

Similar presentations


Ads by Google