BTST

Testing a bit

BTST

Bit TeST


[Syntax]

BTST src, src2

 

[Operation]

(1)When src2 is a memory location:

unsigned char src2;

Z = ~(( src2 >> ( src & 7 )) & 1 );

C = (( src2 >> ( src & 7 )) & 1 );

 

(2)When src2 is a register:

register unsigned long src2;

Z = ~(( src2 >> ( src & 31 )) & 1 );

C = (( src2 >> ( src & 31 )) & 1 );

 

[Function]

-

This instruction moves the inverse of the value of the bit of scr2, which is specified by src, to the Z flag and the value of the bit of scr2, which is specified by src, to the C flag.

-

The immediate value given as src is the number (position) of the bit.

-

The range for IMM:3 operands is 0 ≤ IMM:3 ≤ 7. The range for IMM:5 is 0 ≤ IMM:5 ≤ 31.

 

[Instruction Format]

Syntax

Processng Size

Operand

Code Size

(Byte)

src

src2

(1)BTST src, src2

B

#IMM:3

[Rs2].B

2

B

#IMM:3

dsp:8[Rs2].B

3

B

#IMM:3

dsp:16[Rs2].B

4

B

Rs

[Rs2].B

3

B

Rs

dsp:8[Rs2].B

4

B

Rs

dsp16:[Rs2].B

5

(2)BTST src, src2

L

#IMM:5

Rs2

2

L

Rs

Rs2

3

[Flag Change]

Flag

C

Z

S

O

Change

Conditions

C : The flag is set if the specified bit is 1; otherwise it is cleared.

Z : The flag is set if the specified bit is 0; otherwise it is cleared.

 

[Description Example]

BTST #7, [R2]

BTST R1, [R2]

BTST #31, R2

BTST R1, R2