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

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

Chapter 6 Introduction to Data Structures

Defining Constant EQU XVALEQU7 MOVE.B#XVAL, D0

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

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

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

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

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

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

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

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

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

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

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