0% found this document useful (0 votes)
53 views14 pages

11 Microprocessor Systems Lecture No 11 Arrays and Symbolic Constants

This document discusses various techniques for working with arrays and symbolic constants in assembly language, including: - Using the DUP operator to allocate arrays and initialize with repeated values. - Declaring uninitialized data segments with the .data? directive to reduce EXE file sizes. - Defining symbolic constants with directives like =, EQU, and TEXTEQU to associate names with values or text in a redefinable or non-redefinable way. - Calculating the size of a byte array by subtracting its address from the current location counter.

Uploaded by

Muhammad Zubair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views14 pages

11 Microprocessor Systems Lecture No 11 Arrays and Symbolic Constants

This document discusses various techniques for working with arrays and symbolic constants in assembly language, including: - Using the DUP operator to allocate arrays and initialize with repeated values. - Declaring uninitialized data segments with the .data? directive to reduce EXE file sizes. - Defining symbolic constants with directives like =, EQU, and TEXTEQU to associate names with values or text in a redefinable or non-redefinable way. - Calculating the size of a byte array by subtracting its address from the current location counter.

Uploaded by

Muhammad Zubair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Microprocessor Based

Systems
Lecture No 11 Arrays and Symbolic
Constants

By Nasir Mahmood
This Lecture
  Using the DUP Operator
  Declaring Unitialized Data
  Calculating the Size of a Byte Array
  Symbolic Constant

  Book Reading “Assembly Language for x86 Processors” 6th


Edition By Kip R. Irvine
  Section 3.4 and 3.5
Using the DUP Operator
  Use DUP to allocate (create space for) an array or string.
  Syntax: counter DUP ( argument )
  Counter and argument must be constants or constant
expressions
var1 BYTE 20 DUP(0) ; 20 bytes, all equal to zero
var2 BYTE 20 DUP(?) ; 20 bytes, uninitialized
var3 BYTE 4 DUP("STACK")
; 20 bytes: "STACKSTACKSTACKSTACK”

3
Declaring Unitialized Data
  Use the .data? directive to declare an
unintialized data segment:
.data?
  Within the segment, declare variables with "?"
initializers:
smallArray DWORD 10 DUP(?)

Advantage: the program's EXE file size is reduced.

4
Mixing Code and Data
  The assembler lets you switch back and forth between code
and data in your programs. You might, for example, want to
declare a variable used only within a localized area of a
program.
  The following example inserts a variable named temp between
two code statements :
.code
mov eax,ebx
.data
temp DWORD ?
.code
mov temp,eax
...
Symbolic Constants
  A symbolic constant (or symbol definition) is
created by associating an identifier (a symbol)
with an integer expression or some text.
  Symbols do not reserve storage. They are used
only by the assembler when scanning a
program, and they cannot change at runtime
Equal-Sign Directive
  name = expression
  expression is a 32-bit integer
(expression or constant)
  may be redefined

  name is called a symbolic constant

  good programming style to use symbols


COUNT = 500
.
.
7
mov al,COUNT
Redefinitions of a Symbol
  A symbol defined with = can be redefined within
the same program.
  The following example shows how the
assembler evaluates COUNT as it changes value:
COUNT = 5
mov al,COUNT ; AL = 5
COUNT = 10
mov al,COUNT ; AL = 10
COUNT = 100
mov al,COUNT ; AL = 100
Calculating the Size of a Byte Array
  current location counter: $
  subtract address of list
  difference is the number of bytes

list WORD 1000h,2000h,3000h,4000h


ListSize = ($ - list) / 2
list BYTE 10,20,30,40
ListSize = ($ - list)
9
EQU Directive
  The EQU directive associates a symbolic name
with an integer expression or some arbitrary text.
  There are three formats:
  name EQU expression
  name EQU symbol
  name EQU <text>

PI EQU <3.1416>
  No Redefinition Unlike the = directive, a symbol
defined with EQU cannot be redefined in the
same source code file
Examples EQU Directive
  Example 1

  Example 2
TEXTEQU Directive
  The TEXTEQU directive, similar to EQU, creates
what is known as a text macro. There are three
different formats: the first assigns text, the second
assigns the contents of an existing text macro, and
the third assigns a constant integer expression:
  name TEXTEQU <text>
  name TEXTEQU textmacro
  name TEXTEQU %constExpr
  A symbol defined by TEXTEQU can be redefined
at any time
Examples TEXTEQU Directive
Example 1

Example 2
THE END

You might also like