Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly: what are semantic NOPs?

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

like image 435
Benjamin Avatar asked Feb 05 '10 06:02

Benjamin


People also ask

What is NOP in assembly?

What Does No Operation (NOP) Mean? A no operation or “no-op” instruction in an assembly language is an instruction that does not implement any operation. IT pros or others might refer to this as a blank instruction or placeholder.

What are two purposes of the NOP instruction?

The NOP instruction does nothing. Execution continues with the next instruction. No registers or flags are affected by this instruction. NOP is typically used to generate a delay in execution or to reserve space in code memory.


2 Answers

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;
}
like image 136
R Samuel Klatchko Avatar answered Oct 31 '22 14:10

R Samuel Klatchko


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.

like image 41
Hans Passant Avatar answered Oct 31 '22 13:10

Hans Passant