3.11 The INC and DEC Instructions


3.11 The INC and DEC Instructions

As the example in the last section indicates, indeed, as several examples up to this point have indicated, adding or subtracting one from a register or memory location is a very common operation. In fact, this operation is so common that Intel's engineers included a pair of instructions to perform these specific operations: the inc (increment) and dec (decrement) instructions.

The inc and dec instructions use the following syntax:

 inc( mem/reg ); dec( mem/reg ); 

The single operand can be any legal 8-bit, 16-bit, or 32-bit register or memory operand. The inc instruction will add one to the specified operand; the dec instruction will subtract one from the specified operand.

These two instructions are slightly more efficient (they are smaller) than the corresponding add or sub instructions. There is also one slight difference between these two instructions and the corresponding add or sub instructions: they do not affect the carry flag.

As an example of the inc instruction, consider the example from the previous section, recoded to use inc rather than add:

      malloc( 128 );      for( mov( 0, ebx ); ebx < 128; inc( ebx ) ) do           mov( 0, (type byte [eax+ebx]) );      endfor; 




The Art of Assembly Language
The Art of Assembly Language
ISBN: 1593272073
EAN: 2147483647
Year: 2005
Pages: 246
Authors: Randall Hyde

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