aboutsummaryrefslogtreecommitdiff
path: root/docs/reference/asm_thumb2_logical_bit.rst
blob: c57bfa8470f81c40ae035f85157bf292cee41684 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Logical & bitwise instructions
==============================

Document conventions
--------------------

Notation: ``Rd, Rn`` denote ARM registers R0-R7 except in the case of the
special instructions where R0-R15 may be used. ``Rn<a-b>`` denotes an ARM register
whose contents must lie in range ``a <= contents <= b``. In the case of instructions
with two register arguments, it is permissible for them to be identical. For example
the following will zero R0 (Python ``R0 ^= R0``) regardless of its initial contents.

* eor(r0, r0)

These instructions affect the condition flags except where stated.

Logical instructions
--------------------

* and\_(Rd, Rn) ``Rd &= Rn``
* orr(Rd, Rn) ``Rd |= Rn``
* eor(Rd, Rn) ``Rd ^= Rn``
* mvn(Rd, Rn) ``Rd = Rn ^ 0xffffffff`` i.e. Rd = 1's complement of Rn
* bic(Rd, Rn) ``Rd &= ~Rn`` bit clear Rd using mask in Rn

Note the use of "and\_" instead of "and", because "and" is a reserved keyword in Python.

Shift and rotation instructions
-------------------------------

* lsl(Rd, Rn<0-31>) ``Rd <<= Rn``
* lsr(Rd, Rn<1-32>) ``Rd = (Rd & 0xffffffff) >> Rn`` Logical shift right
* asr(Rd, Rn<1-32>) ``Rd >>= Rn`` arithmetic shift right
* ror(Rd, Rn<1-31>) ``Rd = rotate_right(Rd, Rn)`` Rd is rotated right Rn bits.

A rotation by (for example) three bits works as follows. If Rd initially
contains bits ``b31 b30..b0`` after rotation it will contain ``b2 b1 b0 b31 b30..b3``

Special instructions
--------------------

Condition codes are unaffected by these instructions.

* clz(Rd, Rn) ``Rd = count_leading_zeros(Rn)``

count_leading_zeros(Rn) returns the number of binary zero bits before the first binary one bit in Rn.

* rbit(Rd, Rn) ``Rd = bit_reverse(Rn)``

bit_reverse(Rn) returns the bit-reversed contents of Rn. If Rn contains bits ``b31 b30..b0`` Rd will be set
to ``b0 b1 b2..b31``

Trailing zeros may be counted by performing a bit reverse prior to executing clz.