Structs.

Slides:



Advertisements
Similar presentations
Introduction to Assembly Language
Advertisements

Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Irvine, Kip R. Assembly Language For Intel-Based Computers TYPE and SIZE Operators TYPE –returns the size, in bytes of a single element of a data label.
CS2422 Assembly Language and System Programming Structure and Macros Department of Computer Science National Tsing Hua University.
Target Processor Directives , When using.386, the program can only run on 386 and above processors.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
CS2422 Assembly Language & System Programming October 3, 2006.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for Intel-Based Computers Chapter 3: Assembly Language Fundamentals Kip Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You may modify.
1 Structure A template or pattern given to a logically related group of variables. field - structure member containing data Program access to a structure:
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.
ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed.
Assembly Language for x86 Processors 6th Edition Chapter 4: Data-Related Operators and Directives, Addressing Modes (c) Pearson Education, All rights.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
CSC 221 Computer Organization and Assembly Language Lecture 27: 2-Dimensional Arrays + Structures.
Today's topics Multi-dimensional arrays Multi-dimensional arrays String processing String processing Macros Macros.
CSC 221 Computer Organization and Assembly Language Lecture 12: Addressing Modes in Assembly.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
CSC 221 Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 4: Data Transfers, Addressing, and Arithmetic Lecture 15: ADD, SUB, NEG and how they.
Assembly Language for x86 Processors 6th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You may modify and.
Structures and Macros Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/08 with slides by Kip Irvine.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
Data Structures Covers Chapter 5, pages 144 – 160 and Chapter 6, pages 198 – 203.
Lecture 17 Structures and Macros Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
CSC 221 Computer Organization and Assembly Language Lecture 11: Addressing Modes in Assembly.
Chapter 10 Structures and Macros Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
Addressing Modes Dr. Hadi Hassan.  Two Basic Questions  Where are the operands?  How memory addresses are computed?  Intel IA-32 supports 3 fundamental.
Lecture 15 Advanced Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for x86 Processors 7th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You may modify and.
CSC 221 Computer Organization and Assembly Language
Assembly Language for x86 Processors 6th Edition
Format of Assembly language
Presentation on Real Mode Memory Addressing
Assembly Language for Intel-Based Computers, 5th Edition
EasyCode Foundations Vocabulary Terms.
Additional Assembly Programming Concepts
Chapter 9.
High-Level Language Interface
Computer Organization & Assembly Language
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Microprocessor and Assembly Language
Assembly Language for x86 Processors 7th Edition
Computer Organization and Assembly Language
Chapter 4: Instructions
Chapter 10: Structures and Macros
Assembly Language for Intel-Based Computers, 5th Edition
Data-Related Operators and Directives
Stack Frames and Advanced Procedures
Memory Segments Code (.code) Data (.data) Stack Heap
(Array and Addressing Modes)
Chapter 3: Addressing Modes
(Array and Addressing Modes)
Basic Instructions.
Assembly Language for Intel-Based Computers, 5th Edition
Miscellaneous Topics.
Shift, Multiply, and Divide
Assembly Language for Intel-Based Computers, 4th Edition
Computer Organization and Assembly Language
Computer Architecture and System Programming Laboratory
(Array and Addressing Modes)
Presentation transcript:

Structs

Structure A template or pattern given to a logically related group of variables. field - structure member containing data Program access to a structure: entire structure as a complete unit individual fields Useful way to pass multiple related arguments to a procedure example: file directory information Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Using a Structure Using a structure involves three sequential steps: 1. Define the structure. 2. Declare one or more variables of the structure type, called structure variables. 3. Write runtime instructions that access the structure. Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Structure Definition Syntax name STRUCT field-declarations name ENDS Field-declarations are identical to variable declarations Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

COORD Structure The COORD structure used by the MS-Windows programming library identifies X and Y screen coordinates COORD STRUCT X WORD ? ; offset 00 Y WORD ? ; offset 02 COORD ENDS Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Employee Structure A structure is ideal for combining fields of different types: Employee STRUCT IdNum BYTE "000000000" LastName BYTE 30 DUP(0) Years WORD 0 SalaryHistory DWORD 0,0,0,0 Employee ENDS Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Declaring Structure Variables Structure name is a user-defined type Insert replacement initializers between brackets: < . . . > Empty brackets <> retain the structure's default field initializers Examples: .data point1 COORD <5,10> point2 COORD <> worker Employee <> Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Initializing Array Fields Use the DUP operator to initialize one or more elements of an array field: .data emp Employee <,,,2 DUP(20000)> Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Array of Structures An array of structure objects can be defined using the DUP operator. Initializers can be used NumPoints = 3 AllPoints COORD NumPoints DUP(<0,0>) RD_Dept Employee 20 DUP(<>) accounting Employee 10 DUP(<,,,4 DUP(20000) >) Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Referencing Structure Variables Employee STRUCT ; bytes IdNum BYTE "000000000" ; 9 LastName BYTE 30 DUP(0) ; 30 Years WORD 0 ; 2 SalaryHistory DWORD 0,0,0,0 ; 16 Employee ENDS ; 57 .data worker Employee <> mov eax,TYPE Employee ; 57 mov eax,SIZEOF Employee ; 57 mov eax,SIZEOF worker ; 57 mov eax,TYPE Employee.SalaryHistory ; 4 mov eax,LENGTHOF Employee.SalaryHistory ; 4 mov eax,SIZEOF Employee.SalaryHistory ; 16 Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

. . . continued mov dx,worker.Years mov worker.SalaryHistory,20000 ; first salary mov worker.SalaryHistory+4,30000 ; second salary mov edx,OFFSET worker.LastName mov esi,OFFSET worker mov ax,(Employee PTR [esi]).Years mov ax,[esi].Years ; invalid operand (ambiguous) ; (not clear what type of struct ; “Years” belongs to) Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.

Looping Through an Array of Points Sets the X and Y coordinates of the AllPoints array to sequentially increasing values (1,1), (2,2), ... .data NumPoints = 3 AllPoints COORD NumPoints DUP(<0,0>) .code mov edi,0 ; array index mov ecx,NumPoints ; loop counter mov ax,1 ; starting X, Y values L1: mov (COORD PTR AllPoints[edi]).X,ax mov (COORD PTR AllPoints[edi]).Y,ax add edi,TYPE COORD inc ax Loop L1 Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.