View Full Version : nop
Eibro
08-19-2002, 12:06 AM
I was writing a sleep function earlier.. and I was wondering, would there be any difference between an empty loop running until the time elapsed or a loop with some inline assembler and the command nop (no operation)? What exactly does nop do anyway? No operation for one CPU cycle?
Fordy
08-19-2002, 03:31 AM
Originally posted by Eibro
I was writing a sleep function earlier.. and I was wondering, would there be any difference between an empty loop running until the time elapsed or a loop with some inline assembler and the command nop (no operation)? What exactly does nop do anyway? No operation for one CPU cycle?
NOP is just an "ignore me......I do nothing" instruction....Usefull if your hex editing and you need to erase a section of code
Most sleep functions (Sleep() in WINAPI for instance) dont work with a loop, they tell the system to not preempt the thread that called the sleep function for the duration that was passed in the function...
IE Sleep(1000).....roughly means dont issue this thread any CPU time for 1 second after this call
ygfperson
08-20-2002, 03:05 PM
NOP's opcode is the same as AND ax,ax. i'm not sure how much time, if any, the instruction takes up, or how the computer handles the ambiguity.
Sayeh
09-02-2002, 09:07 PM
What exactly does nop do anyway? No operation for one CPU cycle?
NOP is a mnemonic placeholder. Many times in code, particularly assembler, you might want some scratch space to work with, without allocating a RAMblock. You could just have a small block of NOPs and the address to that RAM and use that. It makes it very convenient for Drivers.
Or, for some reason, you might require an instruction to begin on a cpu-word boundary-- in such case you'd have to pad the code with NOPs.
A NOP wastes 1 cycle.
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.