Webcentive RISC-V Reference

c.lh

Load signed halfword, 16-bit encoding

Extension
Zcb
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
c.lh xd, imm(xs1)
Length
16-bit (compressed)

Encoding

1513121097654210
100001rs1′1c_uimm1rd′00

Match 0x8440, mask 0xfc43. Source: c.lh rd_p rs1_p c_uimm1 1..0=0 15..13=4 12..10=1 6=1 in riscv-opcodes/extensions/rv_zcb.

FieldBitsriscv-opcodes name
rs1′9:7rs1_p
c_uimm15c_uimm1
rd′4:2rd_p

Description

Loads a 16-bit value from memory into register xd. It computes an effective address by adding the zero-extended offset, to the base address in register xs1. It expands to lh xd, offset(xs1).

Description from riscv-unified-db, reformatted.

Operation

if (implemented?(ExtensionName::C) && MISA_CSR_IMPLEMENTED && (CSR[misa].C == 1'b0)) {
  reserved_instruction($encoding);
}

XReg virtual_address = X[creg2reg(xs1)] + imm;

X[creg2reg(xd)] = sext(read_memory(16, virtual_address, $encoding), 16);

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages