tingxing

IR register operation

17 posts in this topic

Hello, Can I add an offset value to IR register? for example, MOVR D0, IR0 and I have an offset value stored in D1, for example, &100, could I add the offset of D1 into IR0, to get IR0 pointing to D100? I know I can just do MOVR D100, IR0, but for purpose of versatility, I want an offset to be added in such a way. Thanks in advance. Xing

Share this post


Link to post
Share on other sites
Never thought about this, but think it will work. But why don't you just try? This would not be a difficult test.

Share this post


Link to post
Share on other sites
You are describing exactly what use of IR and DR together does for you. This is likely pointed out in the link that PdL provided, but here is my input on this matter: If you point IR0 at D0 using the MOVR command and then use a MOV instruction to move a value of 100 into DR0 as shown below, it will point at D100. Here is the sample code with the value of D100 shown before the last command is executed: and the image below shows the value in D100 after the last instruction is executed: IR0 in this example acts like a pointer while DR0 is an offset from the IR0 pointer.

Share this post


Link to post
Share on other sites
Michael, you misunderstood the question. He does not want to use DR0 as an offset. Instead, he wants to add the offset value to the IR0, which is preset to D0 with MOVR.

Share this post


Link to post
Share on other sites
Sergei, Thanks, but I understood. If he wants to offset his IR by some value (presumably in loop), then using DR in conjunction with IR gets this done for him. He makes no mention of DR in his question, so I thought that maybe he was not aware of how to use it. For instance he could start with IR0 = to D0 and use DR0 as the offset. Then in each loop he could add 10 (or whatever the incremental offset is) to DR0 and leave IR0 defined at D0. This would accomplish exactly the same thing that he is describing.

Share this post


Link to post
Share on other sites
It is true, he may want to do that differently than I am interpreting, but it is also true that he may not know about DR being the offset for IR pointers. He knows about MOVR, but does he know about DRs? Just throwing in an option in case he does not. tingxing could probably clarify this for us with a quick response. IR values are just HEX (Integer) pointers, so if he really wanted to do as he is asking, it will work. The example below shows that when the MOVR instruction is executed a value of 65536 is set into IR0 as a pointer to D0. When MOV D500 ,IR0 is executed, the value in D500 (initially 1) is written into D0: Then D500 is incremented to 2 and IR0 is incremented by 100 and this is the result: One last time, D500 is incremented to 3 and IR0 is incremented by 100 and this is the result:

Share this post


Link to post
Share on other sites
Thank you for the detailed advices (sorry for the delay) What I want to do is, to assign a sequence of values to a memory block. for example: MOV #1, +1,IR0 MOV #9, +2,IR0 the +1, +2 indicate the offset from IR0, and putting instructions in this way is of great readability. if the lines extends to +10, +11 ....., and every offset position has its own meaning. The problem is, IR0, i.e. the starting address will subject to change, for example, currently the following is just fine: MOVR D100, IR0 but later or in any other cases, I need MOVR D200, IR0 I do not want to modify the MOVR instruction, instead, I want to specify D100 or D200 (or their offsets') in a memory, for example MOV #100, D0 or MOV #200, D0 and if D0 is changed, the starting address will be changed. Since DR0,IR0 indicates an address, if the MOVR instruction could assign the address to IR register the problem would be solved: MOVR DR0,IR0 IR1 <- psudo code Xing

Share this post


Link to post
Share on other sites
Maybe I could make it clearer in this way. We define several blocks of memory, and specify the starting addresses in a table: MOV #100, D0 -> block 1, starting from D100 MOV #200, D1 -> block 2, starting from D200 MOV #500, D2 -> block 3, starting from D500 and there are related instructions to assign values to these memory blocks, which might use MOVR instructions and IR registers. But if there is time to make any change to the starting address, I expect to limit the modification ONLY to the table itself. for example: MOV #1000, D0 MOV #2000, D1 MOV #5000, D2 Xing

Share this post


Link to post
Share on other sites
So then my post at #8 has addressed your question, correct? We can consider this issue closed?

Share this post


Link to post
Share on other sites
Hello, Michael, your solution surely addresses the problem, but it lacks a point I need very much: specifying address shift(offset) by using +1, +2, +3 ... I know that using DR0,IR0 and shifting DR0 one by one could iterate the memory block, just like MOV #1, DR0,IR0 -> assign #1 to ex. D2000 ++DR0 MOV #2, DR0, IR0 -> assign #2 to ex. D2001 ++DR0 MOV +3, DR0,IR0 -> assign #3 to ex. D2002 but this kind of writing is not good for maintenance, because it is hard to check the actual address offset just by reading the code, and the offset is in fact calculated at runtime. the following is expected: MOV #1 +0,IR0 MOV #2 +1,IR0 MOV #3 +2,IR0 this way, the address shift is clear, and definite by checking the code. any mistakenly deleted or added any line can be identified without difficulty, on the contrary, the previous method is hard and time consuming when any problem occurs. to use +0,IR0 poses no difficulty, if I just assign the starting address to IR0, MOVR D2000 IR0 but, to go back to my initial question, the problem is how to avoid using D2000 directly, but indirectly, for example, MOVR D0 IR0 -> yes, we use D device, and we just assign its initial address of D0 MOV D100 DR0 -> D100 has our memory block's starting address, we maintain it as a member of a table for all the memory blocks MOV #??? DR0,IR0 -> OK, we address the first unit of the memory block MOV #??? +1,DR0,IR0 -> this is what I want: offset the DR0,IR0 from here by using +1, +2, +3..... instead of ++DR0: because later I will forget where I am if the memory has tens or hundreds of items, which is normal, for example, in the case of control recipe application. MOV #??? +2,DR0,IR0 MOV #??? +3,DR0,IR0 ... MOV #??? +1024,DR0,IR0 Xing

Share this post


Link to post
Share on other sites
Ting Xing, It looks as if you are referring to my note in #4 (note # is in top right corner of the note). I agree that note 4 does not do what you want. Please see my note above in #8. It increments the IR address only and does not use DR. I think this is what you want. In note 4, I do this (this is the order in which I executed the code, not necessarily a statement list as there is really only one MOV and one +L instruction, I just execute each one 3x): MOVR D0 IR0 MOV D500 0,IR0 +L IR0 &100 IR0 MOV D500 0, IR0 +L IR0 &100 IR0 MOV D500 0, IR0 I also am incrementing D500, just so that it is easy to see that different values are being written into D0, D100, D200, etc. You could easily add additional MOV instructions in between incrementing the IR address, like this: MOVR D0 IR0 MOV D500 0,IR0 MOV D501 1,IR0 MOV D502 2,IR0 +L IR0 &100 IR0 MOV D500 0, IR0 MOV D501 1,IR0 MOV D502 2,IR0 +L IR0 &100 IR0 MOV D500 0, IR0 MOV D501 1,IR0 MOV D502 2,IR0

Share this post


Link to post
Share on other sites
Hi, Michael, Thank you very much. I got your idea. you mean adding offset to IR0? and I understand what to do: MOVR D0 IR0 -> yes, we use D device, and we just assign its initial address of D0 ; MOV D100 DR0 -> D100 has our memory block's starting address, we maintain it as a member of a table for all the memory blocks +L D100 IR0 IR0 MOV #1, +0,IR0 MOV #2, +1,IR0 MOV #3, +3,IR0 this is just what I wanted. before I posted here for help, in fact I had tested these codes, but not successful, because I mistakenly used +D100 IR0 IR0, in fact the instruction of +L should have been used. This is due to my ignorance of IR registers. Thank you Michael, and you all, for the enlightening instructions. Xing

Share this post


Link to post
Share on other sites

hello everybody :-), i want to define an IR adress to a contact  or a coil .how can i do that ?i will appreciate if some one could answer me thanks ;-)

Share this post


Link to post
Share on other sites

Isn't he awesome!

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