Introduction to Data Structures in Assembly Language Programming
Learn about defining constants, variables, modules, loops, arrays, and accessing data structures in assembly language programming. Explore designing modules and searching data in databases.
Introduction to Data Structures in Assembly Language Programming
E N D
Presentation Transcript
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 • 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
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
Accessing one Dimensional Array • MOVE.B (A0, D7), D0// read • MOVE.B D0, (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 • 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
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 ----
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.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
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
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
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