Difference between CLR and MOV 0?

PlastekGroup

Member
Join Date
Sep 2016
Location
North Carolina
Posts
28
Are there an differences between using a CLR instruction or using the MOV instruction with a zero in RSLogix 500?

I am wondering what would be considered more "efficient". Thanks!
 
In most systems CLR operates slightly faster than MOV, but in today's modern systems it's insignificant in most cases.
A more significant difference may be that with CLR the old data is gone, with MOV there is still a copy if the destination was different than the source and not a constant value.
YMMV.
 
Last edited:
A more significant difference may be that with CLR the old data is gone, with MOV there is still a copy if the destination was different than the source and not a constant value.

Well, MOV 0 would be a constant.

Also, can you elaborate on the "there is still a copy"? If I have two DINTs. Say... "TAG1" and "TAG2". TAG2 had "5280" in it. And I wanted to clear (zero) that number. Are you saying if I have TAG1 = 0 and do a MOV TAG1 TAG2, that the 5280 still exists somewhere? An accumulator or stack somewhere in the processor?
 
Well, MOV 0 would be a constant.

Also, can you elaborate on the "there is still a copy"? If I have two DINTs. Say... "TAG1" and "TAG2". TAG2 had "5280" in it. And I wanted to clear (zero) that number. Are you saying if I have TAG1 = 0 and do a MOV TAG1 TAG2, that the 5280 still exists somewhere? An accumulator or stack somewhere in the processor?

In a properly developed PLC/PAC when "Moving" data from 'Source' to 'Destination', the 'Source' data is not automatically cleared or altered.

In some systems one must indicate a MOV_DINT or MOV_INT to get desired results.

So be sure to "Know your system" and when asking assistance one should always indicate the system type and revision in question and sometimes for both hardware and software.

When I have time, I like to try answering questions on a forum that both satisfies the OP and any that someone in the future who has the sense to search can benefit from.

It was my (faulty?) assumption that one who did not know that "0" is a constant should not be programming a PLC. 👨🏻‍🏫
As always YMMV.
 
Last edited:
Ok. So the destination of a MOV no longer exists once you execute it. Same as a CLR. The way you compared the two was misleading, because while the CLR only has one definition, and the MOV has two, the comparison would be focus on the Destination of the MOV, not the Source.

Using a MOV to "Clear" a value (by moving a constant zero, or by moving a tag containing zero) would result in that old data not existing anymore, same as a CLR.
 
Are there an differences between using a CLR instruction or using the MOV instruction with a zero in RSLogix 500?

I am wondering what would be considered more "efficient". Thanks!

If its binary (non float), why not also compare an Exclusive OR (with itself).
XOR
IN1: Tag_1
IN2: Tag_1
OUT: Tag_1
 
What I'm doing is an extremely simple hit a button and clear a value type situation.

This running on SLC 5/05s FYI, I just noticed that the programmers before me never seemed to use the CLR command instead used a MOV command with 0 as the source.
 
This running on SLC 5/05s FYI, I just noticed that the programmers before me never seemed to use the CLR command instead used a MOV command with 0 as the source.
It could be that the logic was written with a view to a version of it someday being installed on a processor without a CLR instruction. MOV is more universal. Or maybe just programmer preference.
 
Interesting to note: According to the ML1400 reference, MOV 0 takes 1.4 microseconds while CLR takes 2.
 
Interesting to note: According to the ML1400 reference, MOV 0 takes 1.4 microseconds while CLR takes 2.

Bad programming practices exist everywhere, even in the operating system.

Instinctively I would have said that CLR ought to win hands-down, but there's got to be something slowing it down - I'm guessing that the processor has to "formulate" a source value in a temporary register in order to internally execute a "MOV", so on that basis the MOV would be faster, since the source is already defined.

As for programming "style", I prefer CLR, even if it does take a smidge longer, on the basis that it reduces program memory requirements, because the instruction only has one operand.
 
Last edited:
As for programming "style", I prefer CLR, even if it does take a smidge longer, on the basis that it reduces program memory requirements, because the instruction only has one operand.

I vary it a bit. Depending on what the logic is doing.

If I have a stored number value that I need to set to 0, I will tend to do a MOV 0 instruction. Since it matches what has been done previously in the logic where different values are being MOV into it. Makes the logic look visually more appealing to me.

If I have a word that is being used just for bit statuses. Sequences, Alarms, etc. that I need to reset, I will use the CLR instruction.
 

Similar Topics

Hello, I have a problem with AO- and AA-Tags. When I use for example the tag AO_Test with the address 200 and type the value 1,2 in, the AA-Tag...
Replies
7
Views
1,411
As per the title. This might seem like a basic question to many, but I'm unclear about the difference between a coil ( ) and an application...
Replies
28
Views
4,033
Good Morning , I have 2 Frequency Drive panels to build and commission . It is for 2 pump systems . Just wondering , what is the...
Replies
4
Views
1,971
Hi Experts, Good day! What are the differences between PCS7 SIMATIC Batch and PM Control? Do you have any manual like "Getting Started "...
Replies
0
Views
809
I have a Automation Direct Click Plus that you can buy option CPU slot modules for input/outputs. The slot modules have the options of sinking...
Replies
9
Views
2,819
Back
Top Bottom