Is it possible to program Raspberry Pi in assembly?

You can talk about almost anything that you want to on this board.

Moderator: Moderators

Post Reply
DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Is it possible to program Raspberry Pi in assembly?

Post by DementedPurple » Wed Sep 20, 2017 2:17 pm

Well, my title may seem kind of stupid, of course it can, it's a computer, but the main question I have is if I have an assembled program on an SD card, plug it into the Raspberry Pi, will the bios load the assembly program into RAM and execute it as if it were a bios? If so, is there any documentation on the memory architecture and such anywhere online? I'm doing a school project with it and I don't feel like learning C or such. Of course, I don't know if it would be easier to use a language I already know but have to learn the hardware, or learn a new language and not have to learn about the hardware. I hope this topic isn't too off topic for this website, and if it is, feel free to call me out. Anyway, thanks for your help as always!

adam_smasher
Posts: 271
Joined: Sun Mar 27, 2011 10:49 am
Location: Seattle

Re: Is it possible to program Raspberry Pi in assembly?

Post by adam_smasher » Wed Sep 20, 2017 2:24 pm

if I have an assembled program on an SD card, plug it into the Raspberry Pi, will the bios load the assembly program into RAM and execute it as if it were a bios
Well, your terminology is slightly off, but sure, of course. What do you think the Pi does when it loads Linux or whatever other OS?

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: Is it possible to program Raspberry Pi in assembly?

Post by DementedPurple » Wed Sep 20, 2017 2:35 pm

That's great, is there any documentation though? Kind of like the TI-83 Plus developer guide? Which I'll link to here:https://education.ti.com/en/guidebook/d ... D14/83psdk

tepples
Posts: 22050
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Is it possible to program Raspberry Pi in assembly?

Post by tepples » Wed Sep 20, 2017 2:41 pm

The Raspberry Pi boot process looks like this, involving a couple files that run on the GPU before kernel.img (the ARM executable) is even loaded. It's a lot like the Wii, where the I/O processor does its thing (boot0, boot1, boot2, IOS80) before booting the main PowerPC CPU.

The GPU is heavily proprietary.

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: Is it possible to program Raspberry Pi in assembly?

Post by DementedPurple » Wed Sep 20, 2017 4:27 pm

I can't find any assemblers, only C++ and C compilers on the ARM developer website, I'll leave a link to it here: https://developer.arm.com/products/soft ... ent-studio It doesn't say anything about assembly language. Is it just that literally nobody uses assembly language anymore? I'm basically just using assembly language to avoid having to use any higher level languages because I personally find them way to complicated for my taste. :x

lidnariq
Posts: 9663
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Is it possible to program Raspberry Pi in assembly?

Post by lidnariq » Wed Sep 20, 2017 4:34 pm

I promise that it will be much easier to start off by writing assembly user-mode programs that run under linux, instead of supplanting the entire kernel.

(Replacing the kernel isn't that hard of a second step, but it is a bigger step)

Hangin10
Posts: 37
Joined: Thu Jun 04, 2009 9:07 am

Re: Is it possible to program Raspberry Pi in assembly?

Post by Hangin10 » Wed Sep 20, 2017 4:35 pm

If it's just a gcc cross compiler, binutils (which has an assembler) will likely be in there somewhere as it has the linker.
You could also compile binutils yourself targeting arm.

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: Is it possible to program Raspberry Pi in assembly?

Post by DementedPurple » Wed Sep 20, 2017 4:49 pm

I can program basic kernels like a game engine for the NES, and that's really all I'm doing, I'm just programming an Atari 2600 emulator that runs off of real cartridges.

User avatar
rainwarrior
Posts: 7836
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Is it possible to program Raspberry Pi in assembly?

Post by rainwarrior » Wed Sep 20, 2017 5:07 pm

You can just look up the CPU to learn about the instruction set. All that stuff is well documented.
http://infocenter.arm.com/help/topic/co ... index.html

As far as whether people program in assembly "anymore", yes sometimes, but not a lot. The usual reason people used assembly in the past was for efficient performance, but the potential to hand optimize in assembly has diminished a lot. Compilers are better now than they were in the past, the CPU has design considerations that are suited to modern languages, and on top of it being able to optimize involves efficiently using 32 general purpose registers at once, while navigating deep pipeline issues and multi-level caching. A good compiler can handle this stuff pretty well already-- a careful human can always do better, but it takes a very slow and steady hand.

If you're expecting the experience of writing assembly for modern ARM processors to be anything like writing NES assembly, you're probably in for a rude awakening, but go for it if it interests you.

User avatar
Dwedit
Posts: 4351
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Is it possible to program Raspberry Pi in assembly?

Post by Dwedit » Wed Sep 20, 2017 5:09 pm

If you want to code assembly and have bare metal access to hardware, try the GBA or NDS.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: Is it possible to program Raspberry Pi in assembly?

Post by nicklausw » Wed Sep 20, 2017 7:45 pm

Dwedit wrote:If you want to code assembly and have bare metal access to hardware, try the GBA or NDS.
Somewhat simple example. I think it might actually use libnds so it doesn't exemplify hardware access very well, but it shows you the bare basics behind setting up an assembly project for DS.

User avatar
Bregalad
Posts: 7951
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Is it possible to program Raspberry Pi in assembly?

Post by Bregalad » Thu Sep 21, 2017 4:08 am

The usual reason people used assembly in the past was for efficient performance, but the potential to hand optimize in assembly has diminished a lot. Compilers are better now than they were in the past, the CPU has design considerations that are suited to modern languages, and on top of it being able to optimize involves efficiently using 32 general purpose registers at once, while navigating deep pipeline issues and multi-level caching.
You do not need to care about any of this when programming in assembly for the ARM (at least not the ARMs I have myself programmed in assembly - perhaps more modern ones are different ?). You can just ignore those issues unless you absolutely want maximum performance, which you typically do not care about 99% of the time.
rainwarrior wrote:A good compiler can handle [register allocation and deep pipeline optimisation] pretty well already-- a careful human can always do better, but it takes a very slow and steady hand.
I wonder wether gcc is one of those "good compilers", or if they just made it "just work" with minimal care about hardcore optimisation. I'd lean toward the second possibility, considering it's free.
I'm doing a school project with it and I don't feel like learning C or such
Then do yourself a favour and do not learn C. It's bad as a low level language (assembly is better), bad as a mid level language (Pascal is better) and bad as a high level language (Python is better). The more I think about it, the less I see any advantage of using C at all. The only reason it's used is because Unix, and later it's close Linux, used it.

User avatar
Dwedit
Posts: 4351
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Is it possible to program Raspberry Pi in assembly?

Post by Dwedit » Thu Sep 21, 2017 6:17 am

If you learn any of the curly brace languages (C, C++, C#, JavaScript, Java, etc...), you pretty much learn most of the other languages at the same time. Just that each of these languages has oddities that set it apart from the others.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Oziphantom
Posts: 913
Joined: Tue Feb 07, 2017 2:03 am

Re: Is it possible to program Raspberry Pi in assembly?

Post by Oziphantom » Thu Sep 21, 2017 7:50 am

You will probably need to make a few posts on this forum https://www.raspberrypi.org/forums/view ... e7bf70b603

While Atari 2600 people call the part of their game engines "the Kernel", that is a very specific naming thing only to them, and a Raspberry Pi Kernel is not a couple of things that change 3 registers to make X happen. A Pi Kernel is going to be a few hundred thousand lines of code, and well ARM asm is verbose. You will have to set up the CPU, create the vectors, stack, init all the registers, set up the timings, talk the peripherals, init RAM, make a SD card reader, a graphics driver, a USB host driver, and then be able to talk to what ever your input is, unless you are using GPIO and DB9 joystick to which you might be able to skip the USB code.

adam_smasher
Posts: 271
Joined: Sun Mar 27, 2011 10:49 am
Location: Seattle

Re: Is it possible to program Raspberry Pi in assembly?

Post by adam_smasher » Thu Sep 21, 2017 7:58 am

Bregalad wrote:I wonder wether gcc is one of those "good compilers", or if they just made it "just work" with minimal care about hardcore optimisation. I'd lean toward the second possibility, considering it's free.
GCC is a phenomenal compiler/optimizer. It's not quite as good as ICC, but is as good or better than pretty much everything else out there. It's industry standard for a reason. Per Wikipedia:
The exact set of GCC optimizations varies from release to release as it develops, but includes the standard algorithms, such as loop optimization, jump threading, common subexpression elimination, instruction scheduling, and so forth. The RTL optimizations are of less importance with the addition of global SSA-based optimizations on GIMPLE trees,[37] as RTL optimizations have a much more limited scope, and have less high-level information.

Some of these optimizations performed at this level include dead code elimination, partial redundancy elimination, global value numbering, sparse conditional constant propagation, and scalar replacement of aggregates. Array dependence based optimizations such as automatic vectorization and automatic parallelization are also performed. Profile-guided optimization is also possible.
I promise, tons and tons of work (often paid) has gone into optimization in GCC.
Bregalad wrote:Then do yourself a favour and do not learn C.
I mean, for this particular project maybe, but in general no: do yourself a favour and learn C. Regardless of its quality or lack thereof, it's one of the lingua francas of the programming world and there exists a huge ecosystem of tools/libraries around it. It's small and relatively simple (crazy corner cases excluded), so it's quick to learn; the ratio of benefits you get to the amount of time you put in is enormous.

Post Reply