Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

noping

Hi,

if I want the NIOS to do nothing or nop for 100 cycles so does this code below work it well,

for (i=0; i< 99; i++) {

asm ("nop");

}

In other words, does every "nop" pause the processor for 1 cycle, or for how many cycle if he is writing to an I/O accelerator attached to avalon ??

regards Gabriel.

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Your little loop is going to result in a lot more than 100 cycles, You are incrementing a counter, doing a compare, and a branch in addition to your NOP each time through the loop. Enable the Object dump in the NIOS IDE, then when you compile this little project, you will get the objdump file and you can see what your code produced.

    Jake
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You might want to write the whole thing in assembly if you want exactly 100 cycles.

    Or better yet if you don't want the CPU doing anything during these delay times just create a custom instruction that takes 99 cycles to complete. This should be a simple as loading a down counter with 100 when the 'start' bit is asserted and when the counter reaches '1' assert the 'done' bit. Then when the counter hits 0 hold it until the next time the custom instruction is run.

    By the way what are you trying to do by stalling the CPU for 100 cycles?