[ASM]Nop is good for...?

Thread Starter

nikon

Joined May 3, 2007
17
Hi,

I began to study MicroProcessors (Assembly 8086)
and yesterday I heard about the "nop" command.
From what I UNDERSTOOD this command target is to "waste"
time, to create a sort of "delay".

I also heard that some people use it as a note to themselves to
write commands in the future.

But you allways can write "notes" ( ; need to put here bla bla bla )
So What is the main and real target of the "nop" command?

Does Intel has docs about the commands and their targets?

Thanks in advance,
Ofir
 

hgmjr

Joined Jan 28, 2005
9,029
NOP or "No Operation" is most often used to introduce a machine-cycle delay in the code. This can be handy when you are need to introduce a slight delay between two related events such as changing an output to a slow peripheral followed by an input of the results from that same peripheral.

There are other uses that don't immediately leap to mind.

hgmjr
 

Dave

Joined Nov 17, 2003
6,960
So What is the main and real target of the "nop" command?
Since the nop command is essentially an instruction that does nothing but waste processor cycles, it should be no surprise that its most useful purpose is in the form of processing timing management. The most obvious example is prevention of hazards - a process where dependant instructions in the processor pipeline become out of sequence. It is also useful for forcing data allignment in the computers memory.

Dave
 

JasonDorie

Joined Jan 26, 2008
2
It's also useful for debugging on some hardware. It's possible to 'remove' an instruction from a running program in a debugger by overwriting the instruction with NOPs.

Jason
 

Papabravo

Joined Feb 24, 2006
12,301
It sometimes falls out of an orthogonal instruction set for free because one possible implementation is to move a register into itself without modification of condition codes. Another possible NOP is a Branch Always to the next instruction. It's not like processor designers have to strain very hard to create instructions which do nothing.
 
Top