Move ASCII from byte to DWORD

BNA

Member
Join Date
Sep 2003
Location
Give
Posts
117
Hi'

I have 8 input bytes containing an ASCII value, now I want to move the contents of the first byte into an double word on the first place (First byte of this Dword) and the second byte into the second place, and so on.

Is there an easy way to do this.

Regards Brian
 
L FirstByte
T FirstDoubleWord
L SecondByte
T SecondDoubleWord
etc.

If you you to swap the byte order, insert CAW then CAB in between each load/transfer.
 
Last edited:
Where are the double word destinations located - in consecutive locations in a global DB, temp data, marker words ?

There are various options:

Use the block copy SFC
Use indirect addresssing and load/transfers
Use loads + shifts to create the each double word before storing it

Which sounds easiest to you ?
 
Last edited:
Here's an example FC1 which gives 4 methods of performing the processing requested:



Code:
FUNCTION FC 1 : VOID
TITLE =chars packed into dword example
VERSION : 0.1
 
VAR_INPUT
cChar1 : CHAR ; 
cChar2 : CHAR ; 
cChar3 : CHAR ; 
cChar4 : CHAR ; 
cChar5 : CHAR ; 
cChar6 : CHAR ; 
cChar7 : CHAR ; 
cChar8 : CHAR ; 
iMethod : INT ; 
END_VAR
VAR_OUTPUT
dwOutput1 : DWORD ; 
dwOutput2 : DWORD ; 
END_VAR
VAR_TEMP
acTempChars : ARRAY [1 .. 8 ] OF CHAR ; 
adwTempDwords : ARRAY [1 .. 2 ] OF DWORD ; 
iSFC20Return : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =pack chars from input into temp array of chars
	 L	 #cChar1; 
	 T	 #acTempChars[1]; 
	 L	 #cChar2; 
	 T	 #acTempChars[2]; 
	 L	 #cChar3; 
	 T	 #acTempChars[3]; 
	 L	 #cChar4; 
	 T	 #acTempChars[4]; 
	 L	 #cChar5; 
	 T	 #acTempChars[5]; 
	 L	 #cChar6; 
	 T	 #acTempChars[6]; 
	 L	 #cChar7; 
	 T	 #acTempChars[7]; 
	 L	 #cChar8; 
	 T	 #acTempChars[8]; 
NETWORK
TITLE =select method required, default to method 1
	 L	 #iMethod; 
	 JL	list; 
	 JU	m1; 
	 JU	m1; 
	 JU	m2; 
	 JU	m3; 
	 JU	m4; 
list: JU	m1; 
NETWORK
TITLE =method 1 - read 4 chars as dwords and copy to temp dwords
m1: LAR1 P##acTempChars; 
	 L	 D [AR1,P#0.0]; 
	 T	 #adwTempDwords[1]; 
	 L	 D [AR1,P#4.0]; 
	 T	 #adwTempDwords[2]; 
	 JU	exit; 
NETWORK
TITLE =method 2 - read chars and copy into successive bytes of dwords
m2: LAR1 P##adwTempDwords; 
	 L	 #acTempChars[1]; 
	 T	 B [AR1,P#0.0]; 
	 L	 #acTempChars[2]; 
	 T	 B [AR1,P#1.0]; 
	 L	 #acTempChars[3]; 
	 T	 B [AR1,P#2.0]; 
	 L	 #acTempChars[4]; 
	 T	 B [AR1,P#3.0]; 
	 L	 #acTempChars[5]; 
	 T	 B [AR1,P#4.0]; 
	 L	 #acTempChars[6]; 
	 T	 B [AR1,P#5.0]; 
	 L	 #acTempChars[7]; 
	 T	 B [AR1,P#6.0]; 
	 L	 #acTempChars[8]; 
	 T	 B [AR1,P#7.0]; 
	 JU	exit; 
NETWORK
TITLE =method 3 - read chars into the accumulator and shift
m3: L	 #acTempChars[1]; 
	 SLD 8; 
	 L	 #acTempChars[2]; 
	 OD	; 
	 SLD 8; 
	 L	 #acTempChars[3]; 
	 OD	; 
	 SLD 8; 
	 L	 #acTempChars[4]; 
	 OD	; 
	 T	 #adwTempDwords[1]; 
	 L	 #acTempChars[5]; 
	 SLD 8; 
	 L	 #acTempChars[6]; 
	 OD	; 
	 SLD 8; 
	 L	 #acTempChars[7]; 
	 OD	; 
	 SLD 8; 
	 L	 #acTempChars[8]; 
	 OD	; 
	 T	 #adwTempDwords[2]; 
	 JU	exit; 
NETWORK
TITLE =method 4 - use block copy
m4: CALL SFC20 (
		 SRCBLK				 := #acTempChars,
		 RET_VAL				 := #iSFC20Return,
		 DSTBLK				 := #adwTempDwords);
	 JU	exit; 
NETWORK
TITLE =output the result
exit: L	 #adwTempDwords[1]; 
	 T	 #dwOutput1; 
	 L	 #adwTempDwords[2]; 
	 T	 #dwOutput2; 
	 SET ; 
	 SAVE ; 
END_FUNCTION
 
I'm a little confused at why the complication?

If its the the same input byte loaded 4 times into the DD then why not

1st time

L IB0
T DBB0

2nd time

L IB0
T DBB1

3rd time

L IB0
T DBB2

4th time

L IB0
T DBB3

just write the conditional jumps or a JL instruction to guide the IB to the correct DBB.
 
If you don't want to use indirect addressing and prefer to see all your code in symbolic representation, you can use M area as intermediate variable. In first, define in symbol table 8 bytes and 2 dwords at the same place (you can do it only in M area).

Code:
mByte0: MB300
...........
mByte7: MB307
mDWORD0: MD300
mDWORD1: MD304
 
L Char0
T mByte0
........
L Char7
T mByte7
 
L mDWORD0
T MyDB.dbDWORD0 // DB1.DBD0
L mDWORD1
T MyDB.dbDWORD1 // DB1.DBD4
 
Thanks guys.


As always you all came up with good solutions, I tried the BLKMOV but unfortunatly it did not work as I intented.

Now I intend to try out the solutions posted by L D[AR2,P#0.0], PeterW and Gambrinus. I must admit that I like all tree solutions and that I cannot wait to see which soltion is the best in regards to my project.

Thanks Again.

Regards Brian
 

Similar Topics

I am using SLC500 how do you move ASCII (A10) into a string (ST9)? I tried cop FLL and no go Thanks
Replies
6
Views
2,210
Hi everyone, I am working with micro850, a proximity sensor (FOTEK, PL-05P) and a 3DOF serial arm robot. I use MC_MoveRelative to control the...
Replies
1
Views
57
So I'm pretty green when it comes to troubleshooting in the field so bear with me. We have a Danfoss valve that opens/closes from an analog output...
Replies
23
Views
953
Hi. This is pretty basic but I'm struggling to find an efficient solution. I have a float value of let say 666.555 that I want to move / split...
Replies
3
Views
207
hi, I got a plc S7-1200 with SEW movitrac **** and i need to program something ridiculous if my application reaches sensor 1 then my SEW has to...
Replies
0
Views
188
Back
Top Bottom