Run-Time Constructs

The constructs in the next two sections are converted to the microprocessor command in the course of assembling.

Conditional Constructs

  1.  .IF condition ... .ENDIF 
  2.  .IF condition ... .ELSE ... .ENDIF 
  3.  .IF condition 1 ... .ELSEIF condition 2 ... .ELSEIF condition 3 ... .ELSE ... .ENDIF 

Consider the following fragment containing a conventional construct and the corresponding Assembly code:

 .IF EAX==12H        MOV  EAX,'10H     .ELSE        MOV   EAX, 15H     .ENDIF 

The preceding fragment is equivalent to the following Assembly code:

 CMP  EAX,  12H        JNE  NO_EQ        MOV  EAX,  10H        JMP  EX_BLOK     NO_EQ:        MOV  EAX,  15H     EX_BLOK: 

It is rather convenient . However, do not be too enthusiastic about it because, in my opinion, this will carry you from the art of Assembly language programming.

The WHILE Loop

 .WHILE  condition     ...     .ENDW 

For example:

 WHILE EAX<64H     ADD   EAX, 10H     ENDW 

For MASM, the following is used:

 JMP   L2     L1:        ADD   EAX,  10H     L2        CMP   EAX,  64H        JB    L1 

For TASM, the following is used:

 L1:        CMP   EAX,  64H        JNB   EXI        ADD   EAX,  10H        JMP   L1     EXI: 

There is a minor differences related to how the two assemblers translate the .IF and .WHILE directives. TASM32 automatically optimizes the code by adding extra no-operation ( NOP ) commands to align by the quadruple word boundary. This makes the program execution somewhat faster but increases its size . I prefer the MASM attitude.



The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net