this post was submitted on 27 Oct 2023
8 points (83.3% liked)
Single Board Computers
1233 readers
5 users here now
A community for the discussion of all single board computers. Raspberry Pi is ok, but there are so many other boards now that get looked over that deserve attention.
Post news, questions, your setups, guides, anything that has to do with SBCs. Server wide rules apply
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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:
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.