Consider the following function which is written in x86-assembly
foo:
rep
nop
ret
Using NASM to assemble the code and disassemble it with gdb
we have:
(gdb) disas foo
Dump of assembler code for function foo:
0x0000000000000610 <+0>: pause ;pause ????
0x0000000000000612 <+2>: ret
0x0000000000000613 <+3>: nop WORD PTR cs:[rax+rax*1+0x0]
0x000000000000061d <+13>: nop DWORD PTR [rax]
End of assembler dump.
It uses the pause
instruction which was not presented in the original assembly. Why does it work this way? Is that an intentional documented behavior of NASM? So in case some earlier x86 cpu
s do not have pause
we can just use rep nop
?