[ASM]Nop is good for...?

Discussion in 'Programmer's Corner' started by nikon, Jan 25, 2008.

  1. nikon

    Thread Starter Member

    May 3, 2007
    17
    0
    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
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  3. Dave

    Retired Moderator

    Nov 17, 2003
    6,960
    144
    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
     
  4. JasonDorie

    New Member

    Jan 26, 2008
    2
    0
    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
     
  5. Papabravo

    Expert

    Feb 24, 2006
    10,148
    1,791
    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.
     
Loading...