indirect addressing - fill memory function

kyoq

Member
Join Date
Sep 2006
Location
Poland
Posts
18
I am trying to write a function that fills a memory, for example from byte no. 6 write 100 bytes using certain pattern:
IN value: start address [INT]
byte_count (how many bytes to write) [INT]
byte_pattern (e.g. B#16#FF) [BYTE]
It would help me to understand indirect addressing
thanks
 
Which plc/cpu? If using Step7 300/400 series, there is a system function that will do this. Do you want to do this "long hand" though to gain familiarity with indirect addressing ?
 
example

Code:
	L	 W#16#FF
	T	 MB	 1
	CALL "FILL"
	 BVAL :=P#M 0.0 BYTE 1
	 RET_VAL:=MW2
	 BLK	:=P#DB5.DBX0.0 BYTE 500

That move hex ff into marker byte 1, then fills DB5.dbb0 to db5.dbb499 with the hex value.
 
PeterW said:
example

Code:
	L	 W#16#FF
	T	 MB	 1
	CALL "FILL"
	 BVAL :=P#M 0.0 BYTE 1
	 RET_VAL:=MW2
	 BLK	:=P#DB5.DBX0.0 BYTE 500

That move hex ff into marker byte 1, then fills DB5.dbb0 to db5.dbb499 with the hex value.

Just to streamline it a little bit, you really don't have to use the pointer format in this case for BVAL. Just type in MB1, and it will work the same way. I use "SFC Fill" to clear DBs all the time, and I just load a "0" in a temp int variable, enter it for BVAL, and it works fine.
 
Here is a fill function that does not use SFC21. Note that there is no error checking so if the db doesn't exist or is too small a CPU error will be generated.

Code:
FUNCTION FC 1 : VOID
TITLE =Fill without using SFC21
VERSION : 0.1
 
VAR_INPUT
dbBlock : BLOCK_DB ; 
iStartByteNumber : INT ; 
iNumberOfBytes : INT ; 
byFillValue : BYTE ; 
END_VAR
BEGIN
NETWORK
TITLE =
	 OPN #dbBlock; //Open DB to use
	 L	 #iStartByteNumber; //start byte number..
	 SLD 3; //convert to pointer format
	 LAR1 ; //and use AR1 for indirect addressing
	 L	 #byFillValue; //get fill value
	 L	 #iNumberOfBytes; //set up loop count
Loop:	 TAK ; 
	 T	 DBB [AR1,P#0.0]; //and write to DB
	 +AR1 P#1.0; //update indirect address to next byte
	 TAK ; 
	 LOOP Loop; 
END_FUNCTION
 
Thanks for source, I modified this to fill memory:

FUNCTION FC 70 : VOID
TITLE =
VERSION : 0.1


VAR_INPUT
start_address : INT ; //Initial address
byte_count : INT ; //Ammount of bytes to be write
byte_pattern : BYTE ; //Byte pattern
END_VAR
VAR_TEMP
pointr : INT ;
END_VAR
BEGIN
NETWORK
TITLE =

L #start_address;
L 0;
==I ;
BEC ;
//*
L #start_address;
SLD 3;
LAR1 ;
L #byte_pattern;
L #byte_count;
P: TAK ;
T MB [AR1,P#0.0];
+AR1 P#1.0;
TAK ;
LOOP P;

END_FUNCTION

for inputs:
// CALL FC 70
// start_address:=8
// byte_count :=0
// byte_pattern :=B#16#F

I got an error Event 2x23 ...why ??
 
Last edited:
A byte count of zero will actually loop 65535 times and you will run off the end of the M area. Did you mean to check for a zero byte count instead of a zero start address ?
 

Similar Topics

Howdy folks, I am an Allen Bradley guy currently living in an Emerson world. Working with Rx3i on PacSystems Machine Edition v. 9.6? i think...
Replies
3
Views
610
Hello, I'm very new to programming with absolutely zero schooling in this field and pretty hands off training in my new role, it's been fun...
Replies
4
Views
663
Hello Friends, I am trying to index M Bits, however GX Works2 is not allowing it with following message. https://ibb.co/zPcqj6M...
Replies
3
Views
1,372
Hi All, which the best way to do the indirect addressing in an optimize DB? Ccurrently this is my partial code inside an FB...
Replies
7
Views
2,267
Hey everyone, Just used the PLC5/Logix migration utility to convert a program, and while addressing the PCEs, I noticed a lot of errors for "XIC...
Replies
12
Views
1,949
Back
Top Bottom