Search code examples
assemblyx86reverse-engineering

x86 pointless piece of small code or?


I have a project assignment in school which is the infamous x86 bomb. At one point in the code, the compiler does this instruction:

mov 0x1c(%esp),%eax

followed by

and $0xf,%eax

then puts %eax back into where it was taken from with this instruction:

mov %eax,0x1c(%esp)

Do you think it is something done by the compiler automaticly or is it something done by the instructor to just confuse me and make it harder for me to figure out what's going on? Because from what I understand, this portion of the code does absolutely nothing. Takes a 4 byte word from the stack, uses and instruction on its last 4 bits with the binary number "1111" and puts it back on to the same spot on the stack. Which seems kind of pointless to me. Am I missing something?


Solution

  • Props to @lurker and @RossRidge , the instruction;

    and $0xf, %eax

    is used to mask all but the last 4 bits of the contents of %eax.