Introduction

Add to My manuals
704 Pages

advertisement

Introduction | Manualzz

Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT) Chapter 7

Swap Byte (SWPB)

Operands:

The SWPB instruction rearranges the bytes of a value.

Relay Ladder

Operand

Source

Type

INT

DINT

REAL

Format

tag

Enter

tag that contains the bytes that you want to rearrange

Order Mode

Destination INT

DINT

REAL tag

If the Source

Is an

And You Want To Change the Bytes To

This Pattern (Each Letter Represents a

Different Byte)

INT

DINT

REAL n/a

ABCD

ABCD

ABCD

⇒ tag to store the bytes in the new order

If the Source

Is an

Then the Destination Must Be an

INT INT

DINT

REAL

DINT

DINT

REAL

Then Select

any of the options

REVERSE (or enter 0)

WORD (or enter 1)

HIGH/LOW (or enter 2)

Structured Text

SWPB(Source,OrderMode,Dest);

The operands are the same as those for the relay ladder SWPB instruction. If you select the HIGH/LOW order mode, enter it as HIGHLOW or

HIGH_LOW (without the slash).

Publication 1756-RM003K-EN-P - July 2008

Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com

299

Chapter 7 Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT) bar code reader

B A

42969

42968

A B

Arithmetic Status Flags:

not affected

Fault Conditions:

none

Execution:

Condition

prescan rung-condition-in is false rung-condition-in is true

EnableIn is set

Relay Ladder Action

The rung-condition-out is set to false.

The rung-condition-out is set to false.

The rung-condition-out is set to true.

na instruction execution postscan

Description:

The SWPB instruction rearranges the order of the bytes of the Source. It places the result in the Destination.

When you read or write ASCII characters, you typically do not need to swap characters. The ASCII read and write instructions (ARD, ARL, AWA, AWT) automatically swap characters, as shown below.

The instruction rearranges the specified bytes.

The rung-condition-out is set to false.

Tag Name

bar_code[0]

Value Style Type

AB ASCII INT

Structured Text Action

No action taken na na

EnableIn is always set.

The instruction executes.

The instruction rearranges the specified bytes.

No action taken.

300

Publication 1756-RM003K-EN-P - July 2008

Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com

Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT) Chapter 7

Example 1:

The three SWPB instructions each reorder the bytes of DINT_1 according to a different order mode. The display style is ASCII, and each character represents one byte. Each instruction places the bytes, in the new order, in a different Destination.

Relay Ladder

Structured Text

SWPB(DINT_1,REVERSE,DINT_1_reverse);

SWPB(DINT_1,WORD,DINT_1_swap_word);

SWPB(DINT_1,HIGHLOW,DINT_1_swap_high_low);

Example 2:

The following example reverses the bytes in each element of an array. For an

RSLogix 5000 project that contains this example, open the

RSLogix 5000\Projects\Samples folder, Swap_Bytes_in_Array.ACD file.

1.

Initialize the tags. The SIZE instruction finds the number of elements in

array and stores that value in array_length. A subsequent instruction uses this value to determine when the routine has acted on all the elements in the array.

2.

Reverse the bytes in one element of array.

The SWPB instruction reverses the bytes of the element number that is indicated by the value of index. For example, when index equals 0, the

SWPB instruction acts on array[0].

The ADD instruction increments index. The next time the instruction executes, the SWPB instruction acts on the next element in array.

3.

Determine when the SWPB instruction has acted on all the elements in the array.

If index is less then the number of elements in the array (array_length), then continue with the next element in the array.

If index equals array_length, then the SWPB has acted on all the elements in the array.

Publication 1756-RM003K-EN-P - July 2008

Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com

301

Chapter 7 Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)

Relay Ladder

Initialize the tags.

Reverse the bytes.

Determine whether the SWPB instruction has acted on all the elements in the array.

Structured Text

index := 0;

SIZE (array[0],0,array_length);

REPEAT

SWPB(array[index],REVERSE,array_bytes_reverse[index]); index := index + 1;

UNTIL(index >= array_length)END_REPEAT;

302

Publication 1756-RM003K-EN-P - July 2008

Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com

advertisement

Related manuals

advertisement

Table of contents