Problem 2A
NOP (no operation) instruction is included in most of processors.
Is just idles the CPU hardware for one instruction cycle and does
nothing useful. Why is it needed?
Answer
The NOP instruction
has several important applications, including:
- Modern pipelined
processors sometimes have a "branch delay" slot following each branch
instruction. An instruction placed there will be executed whether
or not the branch is taken. If the compiler doesn't have anything
that needs to be done at that point, it must fill the slot with
a NOP.
- When doing
physical I/O (especially in embedded applications), it is sometimes
necessary to introduce tiny time delays between actions. A sequence
or loop of NOP instructions is one way to do this.
- When hand-patching
binary code, NOP instructions can be used to blot out an unwanted
instruction, or to pad a patch that is shorter than the code it
is replacing.
Contributor:
Naveen P N
10-01
NEXT Q&A
|