0

I bought the PI 4 B for a university project, as I have to make small 32-bit ARM assembly program. However I realized it too late, that it comes with an aarch64 architecture ARM processor.

  • I would like to know if it is possible to compile my source code using gcc and run it on my PI.
  • Can I install a 32-bit operating system on it, so I can run it like that maybe?
  • Is it possible to run a virtual machine, like VBox (as far as I know it is not available for ARM architecture)?
  • Compile your code on the Pi. It will run. I doubt that your professor cares too much about 32-bit vs 64-bit unless you're in a computer architecture class. – Bob Brown Mar 24 at 11:20
  • 2
    "However I realized it too late, that it comes with an aarch64 architecture ARM processor." -> Please clarify why you believe this. A Pi by default does not include any software, although they are commonly sold with a pre-imaged SD card. For what you say to be true, that card must have contained a 64-bit aarch OS, which does not include Raspbian. Hence, you just need to put Raspbian (32-bit armv6+) on a card and use that, or a 32-bit armv7 distro, of which there are plenty. But I don't see why you would bother. Just use Raspbian. – goldilocks Mar 24 at 11:24
  • 1
    @goldilocks I am very new to this I am probably talking nonsense which I do not realize. It did not come with any preloaded software, I installed Raspbian on it by myself. I just read, that Rasberry PI 4 B has a 64 bit ARM processor. But if I understand it right, do you say that it does not matter if the the processor is 32 or 64 bit because if I have a 32-bit OS running on it, 32 bit programs will run just fine on it? I am very confused, as I thought the processor architecture is what defines it, not the OS. – Balázs Börcsök Mar 24 at 11:37
  • @BobBrown unfortunately it is for assembly class, so it matters very much so. – Balázs Börcsök Mar 24 at 11:38
1

do you say that it does not matter if the the processor is 32 or 64 bit because if I have a 32-bit OS running on it, 32 bit programs will run just fine on it?

Yes; this is also true for x86-64: You can run 32-bit software on an ISA compatible 64-bit machine. If you've ever had to do that though, it was probably in the context of a 64-bit operating system. This introduces some complications with the 64-bit userspace libraries, which are not necessarily compatible (hence, you probably need two sets of system libs on a 64-bit OS to run 32-bit programs). Note that system libs are I think not a concern for ASM programmers (but I am not one, so I am not positive).

So notice there are sort of two things to consider, the processor ISA and the ISA of the operating system code. There can be a further distinction between the kernel code ISA and the userland system library ISA; you can run a 32-bit userland with a 64-bit kernel.1

The ARM ISA family is, as far as I am aware, intentionally backward compatible. The earliest Pi models have a BCM2835 SoC with an ARM1176JZF-S spec processor. "ARM1176JZF-S" is a microarchitecture: "the way a given instruction set architecture (ISA) is implemented in a particular processor". It implements the ARMv6 ISA. Later models of Pi have processors implementing ARMv7 and ARMv8, meaning they are backward compatible with ARMv6.

Rather than having multiple versions of Raspbian to match the three different ISAs, there's just one that runs on all models using ARMv6 code. Note there are other OS distributions in v7 and v8, but you should regard these as a bit experimental (there may be issues with the kernel) .

Anyway, point being, if you are using Raspbian, there will be a 32-bit ARM native compiler for just about everything. Probably a pretty ideal way to learn assembly!


  1. Note this backward compatibility between 64 and 32 bit is a trait of the x86 and ARM families, and is not necessary a more general truth.
| improve this answer | |
1

You can always run 32 bit programs/operating systems on a 64 bit architecture. That is downstream compatible. You cannot run 64 bit programs on a 32 bit architecture, of course. So it is no problem to compile 32 programs on a Raspberry Pi 4B in particular if you use the 32 bit operating system Raspbian (running on 64 bit architecture). Raspbian is a 32 bit system because it shall run on all Raspberry Pis, even the older one with 32 bit architecture.

| improve this answer | |
1

First of all to clear up ambiguities:


Answering my points:

  1. I would like to know if it is possible to compile my source code using gcc and run it on my PI.

It is very much possible. The Raspberry Pi 4B comes with an Armv8-A processor. Armv8-A supports both Aarch32 and Aarch64 instruction sets. Meaning I could write both 32- and 64-bit ARM assembly code, compile it, and run it.

  1. Can I install a 32-bit operating system on it, so I can run it like that maybe?

Yes of course, for the reason mentioned above. Raspbian default installation will work just fine, which you can get here, and if you are a Windows user help yourself by using the imager (there is one for Mac and Ubuntu).

  1. Is it possible to run a virtual machine, like VBox (as far as I know it is not available for ARM architecture)?

No it is not. However, you might try emulation using qemu (which quite frankly has a huge variety of support for several architectures) or Wine, if you prefer to run Windows applications. Please realize, that emulation is not equal to virtualization, so except huge performance loss, especially on a Pi.


Summary

If you bought a Raspberry Pi and have Raspbian on it, using GCC you will be able to run/debug your 32-bit ARM assembly programs. If you need a specific architecture, get into emulation, but except performance loss.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.