Home/Instructions/Environment Call
ECALL

RISC-V ECALL Instruction Details

Instruction ManualI-type

Request service from the execution environment by raising an environment-call exception

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 Behavior

ECALL is an RV32I/RV64I SYSTEM instruction encoded with funct12=000000000000, rs1=x0, funct3=000, rd=x0, and opcode=1110011. It raises a precise environment-call exception whose cause is distinguished by the current privilege mode, such as environment call from U/S/M mode, and the exception PC records the ECALL instruction itself. Argument passing, syscall numbers, and return conventions are defined by the execution environment or OS ABI, not by ECALL encoding semantics.

ECALL Decode And Trap Animation

Starts from the SYSTEM encoding, then shows fixed fields, execution context, synchronous exception, and EPC/cause state update.

no explicit operands
ecallecall
Execution Context
31..20
19..15
14..12
11..7
6..0
000000000000
funct12
00000
rs1=x0
000
funct3
00000
rd=x0
1110011
SYSTEM
instruction
0x00000073
opcode
1110011 -> SYSTEM
funct3
000
fixed
funct12=000000000000, rs1=x0, rd=x0
context
mode=U, pc=0x0000000000002000
exception
Environment call from U-mode (code 8)
state
trap target EPC=0x0000000000002000; trap target cause=8
next EPC
if continuing after instruction: 0x0000000000002004

This animation shows only ISA-visible synchronous exception and state recording; syscall ABI, debugger action, trap-handler policy, and timing are execution-environment or privileged-architecture matters.

Quick Understanding & Search Notes

ECALL means the current privilege mode raises an environment-call exception. It has no explicit operands and does not define Linux or other OS syscall ABIs; the page animation shows only fixed encoding, current mode, trap cause, and EPC recording.

SYSTEM encoding: opcode=1110011, funct3=000, rs1=x0, rd=x0, funct12=000000000000.
ECALL raises an environment-call exception; the cause is distinguished by current privilege mode, such as from U/S/M mode.
The exception PC records the ECALL instruction itself; returning to the following instruction requires the handler to update EPC according to the architecture.
Syscall number, argument registers, and return values are execution-environment or OS ABI conventions, not ECALL instruction semantics.

Common Usage Scenarios

System & Privilege

Understand this scenario with real code like «ecall # raise environment-call exception».

Execution Environment Call

Understand this scenario with real code like «ecall # raise environment-call exception».

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

ECALL only raises an environment-call exception; syscall number, argument registers, and return-value convention are defined by the execution environment or OS ABI.
The exception cause is distinguished by the current privilege mode; do not collapse all ECALLs into one trap cause.
The exception PC records the ECALL instruction itself; a handler that continues after it must adjust EPC according to the architecture rules.

FAQ

Does the RISC-V ISA define ECALL argument registers?

No. The ISA defines that ECALL raises an environment-call exception; argument registers, syscall numbers, and return values are defined by the execution environment or OS ABI.

Where does ECALL record EPC?

The exception PC records the ECALL instruction itself, not automatically the next instruction. A handler that returns to the following instruction normally advances EPC.