Ser Arthur Vayne
Posts: 1
Joined: Thu Apr 18, 2019 1:18 pm

Low level RPI programming

Thu Apr 18, 2019 1:24 pm

I don't know much about raspberry pi, but I have an interest in low level assembly programming. I realise a raspberry pi is not the best thing for this, but I basically want a single board comuter, that can potentially be used for a variety of different things.
So my question is this: is there a way to program a raspberry pi with assembler without installing an OS? Every tutorial I have seen requires you to install an OS, and I would like to avoid that. How would one go about this, and what IDE would he use?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11737
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Low level RPI programming

Thu Apr 18, 2019 2:36 pm

Moved to bare metal, and assembly language programming.

bzt
Posts: 343
Joined: Sat Oct 14, 2017 9:57 pm

Re: Low level RPI programming

Fri Apr 19, 2019 10:39 am

Welcome to the bare metal programming forum!
Ser Arthur Vayne wrote:
Thu Apr 18, 2019 1:24 pm
So my question is this: is there a way to program a raspberry pi with assembler without installing an OS?
Yes, that's exactly what this forum is about :-) You can find plenty of Assembly here, without any OS requirement. (I'd suggest to use the keywords "bare metal" when goggling for other OS-less Assembly sources).
Ser Arthur Vayne wrote:
Thu Apr 18, 2019 1:24 pm
How would one go about this, and what IDE would he use?
It doesn't matter what IDE you use. You compile your code and copy it over an SD card as "kernel.img", "kernel7.img" or "kernel8.img" (depending what ARM version your Assembly code is written for) and boot that SD card on the Raspberry Pi. That's all.

I for example use gcc cross compiler and Clang (both capable of interpreting Assembly), and an SD card-USB converter so that I can insert the card into my PC just as any USB stick. Then I can copy the compiled kernel image with any common utility (Explorer, Finder, mc, the cp or copy commands etc.).

For a small and very fast assembler, I'd recommend fasm-arm. It uses a slightly different syntax, as it has an extremely powerful macro language common for all architectures. On windows, it ships with it's own IDE.

Cheers,
bzt

jahboater
Posts: 4187
Joined: Wed Feb 04, 2015 6:38 pm

Re: Low level RPI programming

Fri Apr 19, 2019 10:53 am

There is also plain "as" the gnu assembler that comes with the Pi.
The compiler outputs assembler and uses as to assemble it (so it is fast and extremely well tested!).
It supports just about everything and has great diagnostics.

The compiler has a flag "-ffree-standing" that might be useful.

hippy
Posts: 5128
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Low level RPI programming

Fri Apr 19, 2019 2:30 pm

Ser Arthur Vayne wrote:
Thu Apr 18, 2019 1:24 pm
So my question is this: is there a way to program a raspberry pi with assembler without installing an OS? Every tutorial I have seen requires you to install an OS, and I would like to avoid that. How would one go about this, and what IDE would he use?
You can write an assembler program which runs on a Pi without an OS, but you would commonly use another Pi, PC or other computer with an OS and the software tools to create and compile that assembler program. Once done you would move the executable to your Pi and boot the Pi to run that.

This process is generally called 'cross-compiling' or 'cross-assembling'. Which tools and IDE you would use will depend on what platform you were developing on and your own personal preferences. Anything that's available for that platform can be used.

User avatar
Burngate
Posts: 5868
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Low level RPI programming

Fri Apr 19, 2019 5:49 pm

Ser Arthur Vayne wrote:
Thu Apr 18, 2019 1:24 pm
I don't know much about raspberry pi, but I have an interest in low level assembly programming. I realise a raspberry pi is not the best thing for this ...
Wrong! It's perfect for this! For a start, it's a lot less difficult to get out of the mess you'll inevitably create on a Pi than on your expensive Windows laptop.
So my question is this: is there a way to program a raspberry pi with assembler without installing an OS?
That's all an OS is, a series of instructions that someone wrote to get things started.

In the good old days (70 years ago) all you needed was a large number of switches set up correctly, so that it knew how to read punched cards.
These days the Pi has a built-in SD card (or USB device) reader with just enough intelligence to read the rest of the stuff on it.

That means you have put your OS in a fat partition on that card, so no amount of dexterity with knitting needles and cardboard will help you, and you'll need a computer to do that.

But you can use your Pi, running Raspbian, to write your OS onto another card, then swap cards. Away you go!

leiradel
Posts: 31
Joined: Wed Feb 13, 2019 10:38 pm

Re: Low level RPI programming

Tue Apr 23, 2019 8:33 pm

I've blogged about writing bare-bones code for the RPi in C here, it should have everything you need to get started.

Return to “Bare metal, Assembly language”