ALT by Bilal Ahmed Shaik - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

img65.png

 

 

  Assembly Constants

 

  There are several directives provided by NASM that define constants. We have already used the EQU directive in previous chapters. We will particularly discuss three directives:

 

   EQU

 

   %assign

 

   %define

 

  The EQU Directive

 

  The EQU directive is used for defining constants. The syntax of the EQU directive is as follows:

 

img66.png 

  For example,

 

img67.png 

  You can then use this constant value in your code, like:

 

img68.png 

  The operand of an EQU statement can be an expression:

 

img69.png 

  Above code segment would define AREA as 200.

 

  Example:

 

  The following example illustrates the use of the EQU directive:

 

img70.png

img71.png 

  When the above code is compiled and executed, it produces fol owing result:

 

img72.png 

  The %assign Directive

 

  The %assign directive can be used to define numeric constants like the EQU directive. This directive allows redefinition. For example, you may define the constant TOTAL as:

 

img73.png 

  Later in the code you can redefine it as:

 

img74.png 

  This directive is case-sensitive.

 

  The %define Directive

 

  The %define directive allows defining both numeric and string constants. This directive is similar to the #define in C. For example, you may define the constant PTR as:

 

img75.png The above code replaces PTR by [EBP+4].

 

  This directive also allows redefinition and it is case sensitive.