views:

120

answers:

4

I was wondering what are "semantic NOPs" in assembly?

+3  A: 

Code that isn't an actual nop but doesn't affect the behavior of the program.

In C, the following sequence could be thought of as a semantic NOP:

{
    // Since none of these have side affects, they are effectively no-ops
    int x = 5;
    int y = x * x;
    int z = y / x;
}
R Samuel Klatchko
A: 

A semantic NOP is a collection of machine language instructions that have no effect at all or almost no effect (most instructions change condition codes) whose only purpose is obfuscation of what the program is actually doing.

Anonymous Coward
A: 

Code that executes but doesn't do anything meaningful. These are also called "opaque predicates," and are used most often by obfuscators.

BlueRaja - Danny Pflughoeft
+1  A: 

They are instructions that have no effect, like a NOP, but take more bytes. Useful to get code aligned to a cache line boundary. An instruction like lea edi,[edi+0] is an example, it would take 7 NOPs to fill the same number of bytes but takes only 1 cycle instead of 7.

Hans Passant