Unformatted text preview:

Chapter 8 Structures and MacrosTopicsStructuresStructures ContinuedSlide 5Slide 6Slide 7Defining MacrosDefining Macros ContinuedSlide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Macros Calling ProceduresMacros Calling Procedures ContinuedConditional-Assembly DirectivesAdvance Macros and DirectivesCSC 20601/14/19 1Chapter 8 Structures and MacrosInstructor: James HutchinsonCSC 20601/14/19 2TopicsStructuresDefining MacrosMacros Calling ProceduresThe Rep MacroApplicationCSC 20601/14/19 3Structures Assembly Language StructureDefinition: A structure is a composite data type consisting of a group of possibly dissimilar data components that can be accessed as a unit or by component.General Form: name STRUC field-declaration name ENDSWhere: name is the name of the structure.STRUC is an assembler keyword used to specify a structure.field-declaration is a list of one or more variable declarations.ENDS is an assembler keyword that marks the end of the structure declaration.CSC 20601/14/19 4Structures ContinuedA Structure declaration defines a data type.Memory is not allocated until an instance of structure is defined. Defining Variables of structure typeGeneral Form: [Variable_Name] TypeName <[initializer], [initializer]>OR [Variable_Name] TypeName constant DUP <initializer>Where:Variable_Name is a valid Assembler identifier that is the symbolic name of the variableTypeName is the name of the structure.Constant is an optional numeric constant the defines the number of time the structure definition should be repeated.CSC 20601/14/19 5Structures ContinuedExample of a Date Structure:Date strucmonth db ?Day db 0Year dw 0 Date endsNewYear Date <1,1,2003> //declaration of a variable of typed dateIndependence Date <7,4,1776>Date is a structure type consisting of three fieldsAny number of fields can be defined within a struc.The structure type declaration does not actually place a structure in memory. It describes the format that any structure variable of this type will have.CSC 20601/14/19 6Structures ContinuedThe DUP operator can be used to define an array of structure.Example:StudentType Struc StudentID dw ? FirstName db 10 LastName db 10 Grades db 16 dup (0)StudentType EndsMike StudentType <1239, ‘Mike’,’Harris’,>CSC206 StudentType 35 DUP (<>)Accessing the components of a structure.Structures variables can be accessed by name.Fields within the structure also is accessed individually by name or address using a dot (.) notation.VariableName.FieldNameCSC 20601/14/19 7Structures ContinuedExample of Structure Access.Mov al, NewYear.Day //Store a 1 in alMov ax, Independance.Year //store 1776 in AXMov si, Offset MikeMov di, 2Mov ax, si.grades[di] //store Mike’s second score in grades.Access Elements of an Array of Structures.RecordSize = 38Mov si, 4 //Relative record indexMov di, 1//Load the score indexMov RecordSize ax//Load the size of the structurexor dx,dx //Clear DXmul simov ax, siMov al, CSC206[SI].Grades[di]CSC 20601/14/19 8Defining MacrosDefinition:A macro is a group of assembler statements referenced by a single symbolic identifier.A macro expands inline and does not place a return address on the stack.General Form of a Macro definition.macroName Macro [parameters]Where:macroName is a valid Assembler identifier.Macro is an Assembler Language reserve word that designates the group of statements is a macro.Parameters is a list of dummy parameters that will be replaced at run time by actual paramters.CSC 20601/14/19 9Defining Macros ContinuedExample: A macro to display a string.datastring db ‘The house is blue ‘DisplayString Macro dstring mov dx. Offset dstring mov ah, 9 int 21hEndMHow called: DisplayString stringA macro definition consists of three parts:The Macro HeaderThe Macro BodyThe ENDM DirectiveCSC 20601/14/19 10Defining Macros ContinuedThe Macro Heading Contains The macro-nameThe Key-word MacroThe Macro Parameter listExample; Print_Character Macro charInvocation Print_char al ;al contains the char to be printed.The Macro BodyConsists of the group of statements you would like the assembler to insert when the macro is invoked.The sequence of statement can be instructions, data definitions, directives, interrupts, or other macros.The Macro Body can also contain conditional and repeat statements to provide for complex logic within the macro expansion.CSC 20601/14/19 11Defining Macros ContinuedThe Macro Ending consists only of the ENDM (End Macro) statement.The endm directive marks the end of the macro.When the Macro is invoked, the macro name is expanded to all of the statements contained in the body of the macro.The endm directive does not require the name of the macro.One and only on endm directive must appear in each macro.Macro Example: Define a macro that inputs a single character from the keyboardGetChar Macro Headingmov ah, 1 ;;designate DOS function 1int 21h ;;Call the OSEndm EndingBodyCSC 20601/14/19 12Defining Macros ContinuedMacro ParametersParameters are the mechanism used to supply variable information to the macro.Parameters are valid assembler identifiers that appear in the macro heading separated by commas.There is no limit to the number of parameters in the macro definition.The Parameter appear in statements within the body of the macro definition.When the macro is invoke, values are supplied for the parameters. These values are substituted for the parameters during macro expansion.ExampleDisplay_Message Macro Messagemov dx, Messagemov ah, 9int 21hENDMCSC 20601/14/19 13Defining Macros ContinuedInvocation of the macro:Prompt db ‘Enter your Name => $’Name db 20 dup(‘ ‘)Display_Message PromptThe assembler will expand Display_Message Prompt into the following:mov dx, Promptmov ah, 9int 21hMacro Expansion occurs at Assembly. At each place where the macro name is used, the assembler will replace the name of the macro with the statements contained within the body of the macro definition.CSC 20601/14/19 14Defining Macros ContinuedRequired ParametersA parameter can be designated as required by use of the REQ qualifier.General form of the REQ qualifier:Macro_Name Macro Parm1:REQ, Parm2:REQ, …,ParmN:REQIf a parameter is defined with the REQ


View Full Document

NOVA CSC 206 - Structure and Macros

Download Structure and Macros
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Structure and Macros and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Structure and Macros 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?