Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Structures and Macros - Computer Organization and Assembly Language - Lecture Slides, Slides of Assembly Language Programming

This lecture is part of lecture series on Computer Organization and Assembly Language. Main points of this lecture are: Structures and Macros, Defining Structures, Declaring Structure, Referencing Structure Variables, Displaying the System Time, Nested Structures, Drunkard'S Walk, Using Unions, Containing Data, Logically Related

Typology: Slides

2012/2013

Uploaded on 04/25/2013

aristel
aristel 🇺🇸

4.2

(34)

316 documents

1 / 84

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Organization &
Assembly Languages
Structures & Macros
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54

Partial preview of the text

Download Structures and Macros - Computer Organization and Assembly Language - Lecture Slides and more Slides Assembly Language Programming in PDF only on Docsity!

Computer Organization &

Assembly Languages

Structures & Macros

Overview

 Structures

 Macros

 Conditional-Assembly Directives

 Defining Repeat Blocks

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

Using Structure

 Structures in assembly are essentially the same as

structures in C and C++

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

Employee Structure

Employee STRUCT

IdNum BYTE "000000000"

LastName BYTE 30 DUP(0)

Years WORD 0

SalaryHistory DWORD 0,0,0,

Employee ENDS

A structure is ideal for combining fields of

different types:

"000000000" (null) 0 0 0 0 0 Lastname SalaryHistory

Years

Idnum

initializers

Declaring Structure Variables

 Structure name is a user-defined type

 Insert replacement initializers between brackets or

braces:

<... > or {... }

 Empty brackets <> retain the structure's default

field initializers (or braces {})

 Examples:

.data

point1 COORD <5,10>

point2 COORD <>

worker Employee <>

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

Referencing Structure Variables

.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

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

Looping Through An Array of Points

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

Sets the X and Y coordinates of the AllPoints array to

sequentially increasing values (1,1), (2,2), ...

Example: Displaying System Time

 Retrieves and displays the system time at a

selected screen location using Windows functions.

 How to obtain the system time?

SYSTEMTIME Structure in Assembly

SYSTEMTIME STRUCT

wYear WORD?

wMonth WORD?

wDayOfWeek WORD?

wDay WORD?

wHour WORD?

wMinute WORD?

wSecond WORD?

wMilliseconds WORD?

SYSTEMTIME ENDS

Moving Cursor

 How to move cursor to a selected position?

Example: Displaying System Time

 Uses a Windows API call to get the standard console

output handle. SetConsoleCursorPosition positions

the cursor. GetLocalTime gets the current time of day:

.data

sysTime SYSTEMTIME <>

XYPos COORD <10,5>

consoleHandle DWORD?

.code

INVOKE GetStdHandle, STD_OUTPUT_HANDLE

mov consoleHandle,eax

INVOKE SetConsoleCursorPosition,

consoleHandle, XYPos

INVOKE GetLocalTime, ADDR sysTime

Example: Displaying System Time

 Display the time using library calls:

mov edx,OFFSET TheTimeIs ; "The time is " call WriteString movzx eax,sysTime.wHour ; hours call WriteDec mov edx,offset colonStr ; ":" call WriteString movzx eax,sysTime.wMinute ; minutes call WriteDec mov edx,offset colonStr ; ":" call WriteString movzx eax,sysTime.wSecond ; seconds call WriteDec