or
lyszt.net covers or and other RISC-V instructions in more detail.
Encoding format
Description
or is a bitwise instruction, so it works on the 32 bits of a register independently (the and page explains this). At a bit position the result is 1 if either input bit is 1 or both are. The result is 0 only when both inputs are 0. The form below applies this to all 32 positions of rs1 and rs2 and writes the result to rd.
or rd, rs1, rs2
OR sets bits. To turn on one bit and leave the others as they were, OR the value with a mask that has a 1 only in that position. Settings and flags packed into one register are switched on this way.
OR also merges values. When two values are shifted to positions that do not overlap, one OR combines them into a single register. Separate red, green and blue values combine into one color in the same way.
The RISC-V manual lists or among the register-register operations. It reads the source registers rs1 and rs2, performs a bitwise logical OR and writes the result to the destination register rd.
OR can only set bits to 1. Clearing a bit takes AND with a mask, and flipping a bit takes XOR. ori is the version that ORs a register with a fixed constant.
Example
li t0, 0b1100 li t1, 0b0011 or t2, t0, t1 # t2 = 0b1111
