Indirect adressing in an FC, hmmm

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
What I need is:

Load Byte DB205.DBB23
Transfer to Byte DB32.DBB3 with offset 6

So DB205.DBX23.0 must be = = = DB32.DBX3.6
So DB205.DBX23.1 must be = = = DB32.DBX3.7
So DB205.DBX23.2 must be = = = DB32.DBX4.0
.
.
.


See the problem here:

zrzezz.jpg
 
Code:
	  OPN   DB   205
	  LAR1  P#DBX 23.0				  //source
	  OPN   DI	32
	  LAR2  P#DIX 3.6				   //Destination
	  L	 10
A:	T	 #iBitCount
	  A	  [AR1,P#0.0]
	  =	  [AR2,P#0.0]
	  +AR1  P#0.1
	  +AR2  P#0.1
	  L	 #iBitCount
	  LOOP  A
 
euh

Okay, I'm blown away, can you explain what you wrote pelase...

You open DB205.

The offset adress 23.0 in DB205 is loaded in AR1

The you open DI 32 ??? This has to be DB32 I guess ?

There you load the offset 3.6 in AR2.

The rest I don't understand...



L D[AR2 said:
Code:
	 OPN DB 205
	 LAR1 P#DBX 23.0				 //source
	 OPN DI	32
	 LAR2 P#DIX 3.6				 //Destination
	 L	 10
A:	T	 #iBitCount
	 A	 [AR1,P#0.0]
	 =	 [AR2,P#0.0]
	 +AR1 P#0.1
	 +AR2 P#0.1
	 L	 #iBitCount
	 LOOP A
 
Neat solution from Simon (as usual)....

I won't tread on his toes and explain the code to you (that's his job!) but would just like to mention that if you have a large number of bits to process, then using the LOOP command as he has would add approx 1mS to your scan time for every 100 bits.
 
The second was opened as an instance to take advantage of AR1 and AR2.

Your right, an instance DB is in the end just a DB, usually AR2 holds the IDB start address within a FB, as this was an FC it wasn't used.

If doing this within an FB, you would have to save and recover AR2 after use.
 
Here's the example slightly re-coded but running in the simulator so you can see the register contents.

If AR1 contains P#DBX23.0 then
Code:
OPN DB205
A [AR1,P#0.0]

is the same as
Code:
A DB205.DBX23.0

+AR1 P#0.1 adds 1 to AR1

The currently open global DB is accessed using DBX instrictions, The currently open instance DB is accessed using DIX instructions.
I chose a loop count of 10 for the number of bits to process as you did not specify how many bits were required.

bitcopy001.JPG
 
If you only want to perform this type of operation on bytes you could also use the following FC which allows you to specify an arbitrary destination for each bit of the byte

Code:
	  CALL  FC	 1
	   byData:=DB205.DBB23
	   bBit0 :=DB32.DBX3.6
	   bBit1 :=DB32.DBX3.7
	   bBit2 :=DB32.DBX4.0
	   bBit3 :=DB32.DBX4.1
	   bBit4 :=DB32.DBX4.2
	   bBit5 :=DB32.DBX4.3
	   bBit6 :=DB32.DBX4.4
	   bBit7 :=DB32.DBX4.5


Code:
FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  byData : BYTE ; 
END_VAR
VAR_OUTPUT
  bBit0 : BOOL ; 
  bBit1 : BOOL ; 
  bBit2 : BOOL ; 
  bBit3 : BOOL ; 
  bBit4 : BOOL ; 
  bBit5 : BOOL ; 
  bBit6 : BOOL ; 
  bBit7 : BOOL ; 
END_VAR
BEGIN
NETWORK
TITLE =Byte to bit spew
	  L	 P##byData; 
	  LAR1  ; 
	  A	  [AR1,P#0.0]; 
	  =	 #bBit0; 
	  A	  [AR1,P#0.1]; 
	  =	 #bBit1; 
	  A	  [AR1,P#0.2]; 
	  =	 #bBit2; 
	  A	  [AR1,P#0.3]; 
	  =	 #bBit3; 
	  A	  [AR1,P#0.4]; 
	  =	 #bBit4; 
	  A	  [AR1,P#0.5]; 
	  =	 #bBit5; 
	  A	  [AR1,P#0.6]; 
	  =	 #bBit6; 
	  A	  [AR1,P#0.7]; 
	  =	 #bBit7; 
	  SET   ; 
	  SAVE  ; 
END_FUNCTION
 
used this

I used this, and wrote the opposite for bits to bytes

works great

thanks


L D[AR2 said:
If you only want to perform this type of operation on bytes you could also use the following FC which allows you to specify an arbitrary destination for each bit of the byte

Code:
	 CALL FC	 1
	 byData:=DB205.DBB23
	 bBit0 :=DB32.DBX3.6
	 bBit1 :=DB32.DBX3.7
	 bBit2 :=DB32.DBX4.0
	 bBit3 :=DB32.DBX4.1
	 bBit4 :=DB32.DBX4.2
	 bBit5 :=DB32.DBX4.3
	 bBit6 :=DB32.DBX4.4
	 bBit7 :=DB32.DBX4.5


Code:
FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1
 
VAR_INPUT
byData : BYTE ; 
END_VAR
VAR_OUTPUT
bBit0 : BOOL ; 
bBit1 : BOOL ; 
bBit2 : BOOL ; 
bBit3 : BOOL ; 
bBit4 : BOOL ; 
bBit5 : BOOL ; 
bBit6 : BOOL ; 
bBit7 : BOOL ; 
END_VAR
BEGIN
NETWORK
TITLE =Byte to bit spew
	 L	 P##byData; 
	 LAR1 ; 
	 A	 [AR1,P#0.0]; 
	 =	 #bBit0; 
	 A	 [AR1,P#0.1]; 
	 =	 #bBit1; 
	 A	 [AR1,P#0.2]; 
	 =	 #bBit2; 
	 A	 [AR1,P#0.3]; 
	 =	 #bBit3; 
	 A	 [AR1,P#0.4]; 
	 =	 #bBit4; 
	 A	 [AR1,P#0.5]; 
	 =	 #bBit5; 
	 A	 [AR1,P#0.6]; 
	 =	 #bBit6; 
	 A	 [AR1,P#0.7]; 
	 =	 #bBit7; 
	 SET ; 
	 SAVE ; 
END_FUNCTION
 

Similar Topics

Gents, I've not had much dealings with indirect addressing, but I'm troubleshooting a program now, and I just wanted to verify that I've come to...
Replies
9
Views
2,978
Hi everyone. I need some help with a problem I'm having. Any help is greatly appreciated. situation: I need a way to program a data table of...
Replies
2
Views
1,459
No clue on indirect adressing any smart people that can help on pointers and indirect adressing using Allen Bradley Contrologix. Please help.
Replies
1
Views
1,838
Im getting a little more involved in programming using AB Contrologix, I can not understand what is indirect adressing or how to use it, is there...
Replies
2
Views
2,369
Hi In a program i'm addig code to, the following is found to compare a constant to a value stored in N51 EQU #N51:[N51:0] 14 What use is the...
Replies
6
Views
2,609
Back
Top Bottom