Sign in to follow this  
Followers 0
rwraley

NOP instruction for sub-routines

14 posts in this topic

I happened across a program that used the (JMP) instruction to access all subroutines contained within. Each subroutine began and ended with the (NOP) instruction. I am not an expert and I am not familiar with all instruction commands, so I went to instruction help and read the description for the (NOP) but I still don't fully understand the purpose. Can anyone shed a little light?

Share this post


Link to post
Share on other sites
NOP = No OPeration (NOP is actually used in many programming languages) It doesn't do anything and would usually be used for instance to give a rung to add a comment etc. A comment could be attached to a normal rung but if the comment relates to a section of code, the rung may be deleted in the future and the comment for that section of code lost. The NOP is usually used as a marker for a comment, or to break up code visually. It is also often used with a LBL as this needs a coil at the end of the rung, it saves waisting a normal coil. Edited by Snerkel

Share this post


Link to post
Share on other sites
Thats a very inefficient way to program and would be considered poor programming practice for most modern PLCs. My guess is that the programmer was someone who was unfamiliar with the concept of placing subroutines in a different file. Some of the early PLC programming languages (and some still in common use suchs as 984LL) are monolithic in nature. The subroutines are not organized into seperate files but are just sections of the main file. Have you ever heard the term "spaghetti code?"

Share this post


Link to post
Share on other sites
Yes it is an inefficient way to program, but NOPs and AFIs are great ways to put place markers for future code and things you bypass or need to address later

Share this post


Link to post
Share on other sites
NOP's are useless for almost everything. The only time I've ever used them - never with PLC's though - is to allow the pipeline in a processor to catch up (if you don't know what that is then don't bother). I suspect the reason the instruction exists is to allow program memory to be re-arranged whilst it's still running the program which that doesn't apply to user either.

Share this post


Link to post
Share on other sites
If you have a lot of machines that are very similar but some have a few rungs added here or there, you can use the NOPs to keep your rung numbers lined up. This makes it much easier for maintainence to look through programs when troubleshooting. Beyond this and place markers, I'm not aware of too many more uses of them

Share this post


Link to post
Share on other sites
Agreed. They do have their uses. In SLC programs (which does not support the NOP or AFI instruction, I often reserve a B word and create an always false, always true, and save the other 14 for scratch bits.

Share this post


Link to post
Share on other sites
Its normal for microprocessors to have NOP as an op-code; It would be seen in assembler.

Share this post


Link to post
Share on other sites
The only time I used NOP instructions is in beginning microprocessor programming classes in school.. When you need an accurate timing loop, you can use NOPs to give you a delay of exactly one machine cycle. We did the delays for the classic "traffic light" program this way.. By cascading LOTS of NOPs in a loop. Even in a simple example like that though, it isn't making efficient use of the processor. Instead of "doing nothing", why not use an interrupt-driven timer and actually be able to use the processor for other things during the dwell?

Share this post


Link to post
Share on other sites
How can you use this for a delay. Wouldn't it take a whole lot of these to bog down the processor enough to increase the scan time?

Share this post


Link to post
Share on other sites
In microprocessor machine language, the NOP instruction does nothing but consume one machine cycle. All the registers (well, other than the program counter) are in exactly the same state as before the NOP was fetched.. Only it is now one machine cycle later in time. The same is probably true of the PLC NOP instruction. Nothing's different afterward, but a little time is consumed. In this case, how ever much time the PLC needs to process one bit instruction. You are right in that it is a VERY short delay. You need to cascade several loops in order for the delay to be noticable to the human eye. But, nonetheless, you can get a delay of whatever length of time you need if you program it correctly. I don't mean to confuse things by mentioning a non-PLC example.. You wouldn't use a NOP in most PLCs for timing. There's better resources available to the PLC programmer for that. I mentioned the example I did because it was the only useful purpose I have EVER seen for a NOP!

Share this post


Link to post
Share on other sites
Sorry, missed the microprocessor machine language part of your post

Share this post


Link to post
Share on other sites
Doh! I've been using NOP's for the past 2 month's now while I'm learning pic-programming for that very reason. It must be a mental block!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0