1 / 14

Chapter 6

Chapter 6. Introduction to Data Structures. Defining Constant. <Label> EQU <value> XVAL EQU 7 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

bailey
Download Presentation

Chapter 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6 Introduction to Data Structures

  2. Defining Constant • <Label> EQU <value> • XVAL EQU 7 • 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 • <label> DC.size <value> • This is particularly useful when we initialize an array of data or collection of identical data types. • MNO DC.B 1, 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. • SVAL DS.B 6 • TVAL DS.W 2 • UVAL DS.BL 3

  5. Accessing one Dimensional Array • MOVE.B (A0, D7), D0// read • MOVE.B D0, (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 • BSR Lookup • CMPI.B #0, D5 • BEQ ThenCode • Code for else • Repeat-Until Loop • MOVE.B #100, D2 • AGAIN BSR GETDATA • BSR ProcessData • SUBI.B #1, D2 • BNE AGAIN

  8. LOOPS • Do-While Loop • WHILE CMPI.B #’A’, D1 • BEQ NEXT • <other loop instructions> • BRA WHILE • NEXT ---- • CASE Statement • CMPI.B #0, D1 • BNE C1 • CLR.B D2 • BRA Next • C1 CMPI.B #1, D1 • BNE C2 • ADDI.B #1, D2 • BRA Next • C2 CMPI.B #2, D2 • BNE Next • SUBI.B #1, D2 • Next ----

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

  10. 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.B 6, 1, 8 • DC.B 7, 5, 3 • DC.B 2, 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

  11. Searching an Item from the DataBase • ORG $8000 • DATA DS.B 100 • ITEM DS.B 1 • ORG $8100 • FINDBYTE MOVEA.L #DATA, A0 • MOVE.W #99, D0 • MOVE.B ITEM, D1 • COMPARE CMP.B (A0)+, D1 • BEQ FOUND • DBRA D0, COMPARE • ANDI #$FE, CCR • RTS • FOUND ORI #$01, CCR • RTS

  12. STACK • Push CMPA.L A0,A1 • BEQ STKFULL • MOVE.L D0, -(A0) • CLR.B D1 • RTS • STKFULL MOVE.B #$80, D1 • RTS • CMPA.L A0, A2 • BEQ STKEMPTY • MOVE.L (A0)+, D0 • CLR.B D1 • RTS • STKEMPTY MOVE.L #$FF, D1 • RTS

  13. 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.L A0, A2 • BNE NO • MOVEA.L A3, A0 • NO MOVE.L D0, (A0) • SUBA.L #4, A0 • RTS • OUTQUEUE CMPA.L A1, A2 • BNE NO1 • MOVEA.L A3, A1 • NO1 MOVE.L (A1), D0 • SUBA.L #4, A1 • RTS

More Related