in the snippet below of x86 assembly code that was produced by Visual Studio 2017, I see the instruction

shl         eax,0

What is the purpose of this instruction, as It should act as NOP as I understand it.

int main(int argc, char ** argv){
011C1340  push        ebp  
011C1341  mov         ebp,esp  
011C1343  push        ecx  
    int a;
    a = atoi(argv[1]);
011C1344  mov         eax,4  
011C1349  shl         eax,0  
011C134C  mov         ecx,dword ptr [argv]  
011C134F  mov         edx,dword ptr [ecx+eax]

1 Answer 1


It seems to be an unoptimized version of the array access calculation. When optimization is not enabled, you may see all kinds of redundant/useless calculations which are eliminated with optimization. The compiler probably did something like this:

delta = elemsize*index
elemsize = 4, index=1
delta = 4*1 -> 4*(1 shl 0) -> 4 shl 0

which was then faithfully reproduced by codegen in assembly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.