Home/Instructions/Environment Call
ECALL

RISC-V ECALL Instruction Details

Instruction ManualI-type

Make a service request to the execution environment; generates a precise environment-call trap

Instruction Syntax

ecall
Operand Breakdown
Destination rd: general-purpose register receiving the result.
Source rs1: register holding the first operand.
Immediate imm: 12-bit signed value, sign-extended before operation with rs1.
RV32ISystemPrivileged

Instruction Encoding

31..20
imm[11:0]
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

ECALL uses opcode 1110011 (0x73), funct3 000, funct12 000000000000. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.

Format: I-type
opcode: 1110011 (0x73)
funct3: 000 (0x0)
funct12: 000000000000 (0x000)

Instruction Behavior

ECALL (I-type encoding with all-zero immediate, rs1=x0, funct3=000, rd=x0, opcode=SYSTEM=1110011) generates a precise trap, transferring control to the execution environment. The EEI defines parameter passing (usually via registers). Used for system calls: user-mode programs request OS services via ECALL. Previously named SCALL (Supervisor Call), renamed to reflect broader usage beyond supervisor calls.

Common Usage Scenarios

Device & IO

Understand this scenario with real code like «ecall # request service from execution environment».

System & Privilege

Understand this scenario with real code like «ecall # request service from execution environment».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is I-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

Parameter-passing convention is defined by the execution environment (EEI), not by the ISA
Return address after ECALL is held in a trap PC CSR such as mepc/sepc, not in ra