AND

RISC-V AND Instruction Details

Instruction ManualR-type

Bitwise AND of rs1 and rs2, result in rd

Instruction Syntax

and rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
RV32ILogical

Instruction Behavior

AND uses the R-type format. It performs bitwise AND of rs1 and rs2 and writes the result to rd. funct7=0000000 and funct3=111.

AND Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
rs2
and
,
,
Execution Context
t1(x6)
0x00000014
t2(x7)
0x00000007
31..25
24..20
19..15
14..12
11..7
6..0
0000000
funct7
00111
rs2
00110
rs1
111
funct3
00101
rd
0110011
opcode
Execution Data Path
instruction
0x007372B3
opcode
0110011 -> OP
funct3
111 -> AND bitwise AND
funct7
0000000 -> base ALU op
rd / rs1 / rs2
t0(x5) / t1(x6) / t2(x7)
bitwise ALU
0x00000014 & 0x00000007 = 0x00000004
x5
t0(x5) = 0x00000004
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x007372B3
syntax : and t0(x5), t1(x6), t2(x7)
result : t0(x5) = 0x00000004
Architectural Result
t0(x5) = 0x00000004
Bit-by-Bit Logic View
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
0
rs1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
rs2
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

Quick Understanding & Search Notes

AND is an RV32I/RV64I base integer R-type logical instruction: it reads two XLEN-wide register values from rs1 and rs2, applies bitwise AND, and writes rd. It is commonly used to keep bits selected by 1s in a mask and clear bits selected by 0s.

opcode=0110011 selects the OP class; funct3=111 with funct7=0000000 selects AND.
AND has no immediate field; use ANDI for a signed 12-bit immediate mask, or build a larger mask in a register first.

Common Usage Scenarios

Address & Pointer

Understand this scenario with real code like «and x5, x6, x7 # x5 = x6 & x7».

Bit Operations & Masks

Understand this scenario with real code like «and x5, x6, x7 # x5 = x6 & x7».

Register Operations

Understand this scenario with real code like «and x5, x6, x7 # x5 = x6 & x7».

Pre-Use Checklist

Syntax Check
  • Verify rd, rs1, rs2 (and rs3) are valid GPRs.
  • Confirm funct3 and funct7 encoding is correct.
Semantic Check
  • Check if the result affects subsequent branches or address calculations.
  • Ensure the rd register is not overwritten by another instruction.

Pitfalls / Common Confusions

AND with x0 always yields zero
Alignment mask must be correct

FAQ

What is the difference between AND and ANDI?

AND reads two registers, rs1 and rs2. ANDI reads rs1 and uses a sign-extended 12-bit immediate.

Does AND update condition-code flags?

No. The RISC-V base integer ISA has no condition-code flags; AND only writes rd, and a write to x0 is discarded.