Asm Risc
Asm Risc
Arithmetic Instructions
Logical Instructions
Set Instructions
1. SLT (Set Less Than): Sets rd to 1 if rs1 < rs2 (signed comparison).
o Syntax: SLT rd, rs1, rs2
Example:
o SLT x5, x1, x2 # x5 = 1 if x1 < x2; otherwise, x5 = 0
2. SLTI (Set Less Than Immediate): Sets rd to 1 if rs1 < imm (signed comparison).
o Syntax: SLTI rd, rs1, imm
Example:
o SLTI x5, x1, 10 # x5 = 1 if x1 < 10; otherwise, x5 = 0
3. SLTU (Set Less Than Unsigned): Similar to SLT but for unsigned values.
o Syntax: SLTU rd, rs1, rs2
Example:
o SLTU x5, x1, x2 # x5 = 1 if x1 < x2 (unsigned); otherwise, x5
= 0
4. SLTIU (Set Less Than Immediate Unsigned): Similar to SLTI but for unsigned
values.
o Syntax: SLTIU rd, rs1, imm
Example:
o SLTIU x5, x1, 10 # x5 = 1 if x1 < 10 (unsigned); otherwise, x5
= 0
Shift Instructions
1. SRA (Shift Right Arithmetic): Shifts bits of rs1 right by rs2 places, preserving the
sign.
o Syntax: SRA rd, rs1, rs2
Example:
o SRA x5, x1, x2 # x5 = x1 >> x2 (arithmetic shift)
2. SRAI (Shift Right Arithmetic Immediate): Shifts bits of rs1 right by an immediate
value, preserving the sign.
o Syntax: SRAI rd, rs1, imm
Example:
o SRAI x5, x1, 2 # x5 = x1 >> 2 (arithmetic shift)
3. SRL (Shift Right Logical): Shifts bits of rs1 right by rs2 places, filling with zeros.
o Syntax: SRL rd, rs1, rs2
Example:
o SRL x5, x1, x2 # x5 = x1 >> x2 (logical shift)
4. SRLI (Shift Right Logical Immediate): Shifts bits of rs1 right by an immediate
value, filling with zeros.
o Syntax: SRLI rd, rs1, imm
Example:
o SRLI x5, x1, 2 # x5 = x1 >> 2 (logical shift)
5. SLL (Shift Left Logical): Shifts bits of rs1 left by rs2 places.
o Syntax: SLL rd, rs1, rs2
Example:
o SLL x5, x1, x2 # x5 = x1 << x2
Memory Instructions
PC Instructions
Jump Instructions
1. JAL (Jump and Link): Jumps to a target address and saves the return address in rd.
o Syntax: JAL rd, offset
Example:
o JAL x5, 16 # Jump to PC + 16 and store return address in x5
2. JALR (Jump and Link Register): Jumps to an address in a register and saves the
return address.
o Syntax: JALR rd, offset(rs1)
Example:
o JALR x5, 0(x1) # Jump to address in x1 and store return
address in x5
Branch Instructions