Member-only story
RISC-V Instruction-Set Cheatsheet
Overview of the RV32I base instruction-set of RISC-V processors including an comparison with the AVR instruction-set.
A NUMBER OF people have tried to make sheets giving an overview of the RISC-V instruction-set, so here is my variant. I have tried to find a balance between being useful and easy to read. That means some things I have excluded from this overview. For instance, most instructions dealing with immediate values do sign-extension, and I chose to not document that in this overview. What is sign-extension you ask?

Computers only store binary numbers with ones and zeros. Thus to represent negative numbers we utilize the fact that integer numbers wrap around. Consider the classic mechanical counter shown below. If it says 9999, then what does adding 4 to it result in? It gives you the number 0003, because numbers wrap around. In essence 9999 acts as if it was -1. What did it say 9998 and you added 4? Then the result would be 0002, hence 9998 acts as if it was -2. Thus we can use high number values to represent negative numbers.

Digital computers work much the same. Thus binary numbers wrap around once you get to the max value. One complicating factor when dealing with this is that what constitutes -1, -2, -3 and so on depends on the number of digits used. With the decimal number system, if you only get to represent numbers with a single digit then 9 represents -1 and 8 represents -2, while if you got two digits then 99 represents -1, 98 is -2, 97 is -3, and so on.
The exact same thing applies to binary numbers. Sign extension for decimal numbers would mean that you add 9s as the first digit each time you add digits if the number was negative. Hence if 9 represents a signed number then 09 would not work as it would be a positive number. You would have to turn it into 99. For binary numbers, you check if the first digit is a 1 and then add 1s to the front as you add bits. Sign extensions apply even to logical operations such as AND
and OR
.