Technically both are RISC based but probably they are way different in implementation. I’m thinking about buying a RISC-V SBC, and I just want to be sure about compatiblity with running ARM based software.
Technically both are RISC based but probably they are way different in implementation. I’m thinking about buying a RISC-V SBC, and I just want to be sure about compatiblity with running ARM based software.
No. This is like asking if a 6502 microprocessor can run a 6809’s code because they’re both 8-bit micros.
The family of instruction sets under the RISC-V banner is completely different from the family of instruction sets under the ARM banner. I’ll compile this program for RISC-V and ARM and show you the compiler outputs for an example:
#include int main(int argc, char** argv) { printf("Hello, world!"); }
First ARM (a fairly generic ARM32 processor core’s output):
Now RISC-V (again a fairly convention 32-bit RISC-V core):
Comparing the two you’re going to note several very major differences. One of the biggest and easiest to spot, however, is how ARM pushes
r7
andlr
onto the stack at the beginning, but popsr7
andpc
at the end. This is becauselr
contains the “return address” (it’s a bit more complicated than that, but close enough for jazz) on entry andpc
is the “program counter” which is where the processor will get its next instruction from. By popping what was thelr
value intopc
you’ve effectively done a transfer of control to the return address without an explicit branch.RISC-V, conversely, uses
ra
(their equivalent oflr
) pushed onto the stack (note how each value is pushed manually, not part of a combined instruction), then popped back from the stack and an explicitjr
branch instruction is used to set the next instruction to be executed. So even ignoring the different names of instructions (which could just be different naming conventions for the same thing), the very way the two systems operate is very different.So while ARM and RISC-V are both RISC processors, they are not even similar to each other in operations beyond both following the RISC philosophy of instruction set design.
Thank you for the detailed answer. I feel I learned something today.
No troubles.
If you really want to know what assembler looks like and how it relates to higher-level languages when compiled, you can’t really beat Godbolt. It’s amazing what you can learn from there, and changing options to include maximum optimization, for example, can show you just how much work compilers do for you under the covers these days.