ALIGN Directive


The directive causes the assembler to align the next data item or instruction on an address according to a given value.
       ALIGN  number
The could be 1, 2, or 4. If it equals 1, the next variable or byte is aligned on a 1-byte boundary. If is 2, the next variable is aligned on an even-numbered address, and if is 4, the next address is a multiple of 4.

ALIGN 1 ALIGN 2 ALIGN 4
 INCLUDE Irvine32.inc 
 .data
  X  BYTE  0FFh
  ALIGN 1
  Y  DWORD  12345678h
 .code
 main PROC 
  mov   eax, 0
  mov   ebx, OFFSET X
  mov   ax, [ebx + 2]
  call  WriteHex
  exit
 main ENDP
 END main
 INCLUDE Irvine32.inc
 .data
  X  BYTE  0FFh
  ALIGN 2
  Y  DWORD  12345678h
 .code
 main PROC 
  mov   eax, 0
  mov   ebx, OFFSET X
  mov   ax, [ebx + 2]
  call  WriteHex
  exit
 main ENDP
 END main

 INCLUDE Irvine32.inc
 .data
  X  BYTE  0FFh
  ALIGN 4
  Y  DWORD  12345678h
 .code
 main PROC 
  mov   eax, 0
  mov   ebx, OFFSET X
  mov   ax, [ebx + 2]
  call  WriteHex
  exit
 main ENDP
 END main

Output Output Output

 

 

 

 

 

 

†The CPU can process data stored at even-numbered addresses more quickly than those at odd-numbered addresses.

If the offset is already at the required address, it is not advanced. The assembler fills unused bytes with zeros for data and for instruction. The instruction is used to delete/insert machine code, to delay execution for purposes of timing, or to align a subsequent instruction on a word boundary. simply performs a null operation by executing:
        XCHG AX, AX
NOP — No Operation

Usage: NOP

Flag O D I S Z A P C
Result                
Clocks
Operands 286 386 486 Size Bytes
none 3 3 1 1









      “I’m not arguing, I’m just explaining why I’m right.”    
      ― Unknown