Is it possible to program Raspberry Pi in assembly?
Moderator: Moderators
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
Is it possible to program Raspberry Pi in assembly?
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!
-
- Posts: 271
- Joined: Sun Mar 27, 2011 10:49 am
- Location: Victoria, BC
Re: Is it possible to program Raspberry Pi in assembly?
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?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
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
Re: Is it possible to program Raspberry Pi in assembly?
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
Re: Is it possible to program Raspberry Pi in assembly?
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.
The GPU is heavily proprietary.
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
Re: Is it possible to program Raspberry Pi in assembly?
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.
Re: Is it possible to program Raspberry Pi in assembly?
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)
(Replacing the kernel isn't that hard of a second step, but it is a bigger step)
Re: Is it possible to program Raspberry Pi in assembly?
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.
You could also compile binutils yourself targeting arm.
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
Re: Is it possible to program Raspberry Pi in assembly?
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.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Is it possible to program Raspberry Pi in assembly?
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.
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.
Re: Is it possible to program Raspberry Pi in assembly?
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!
Re: Is it possible to program Raspberry Pi in assembly?
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.Dwedit wrote:If you want to code assembly and have bare metal access to hardware, try the GBA or NDS.
Re: Is it possible to program Raspberry Pi in assembly?
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.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.
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.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.
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.I'm doing a school project with it and I don't feel like learning C or such
Re: Is it possible to program Raspberry Pi in assembly?
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!
-
- Posts: 1565
- Joined: Tue Feb 07, 2017 2:03 am
Re: Is it possible to program Raspberry Pi in assembly?
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.
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.
-
- Posts: 271
- Joined: Sun Mar 27, 2011 10:49 am
- Location: Victoria, BC
Re: Is it possible to program Raspberry Pi in assembly?
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: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.
I promise, tons and tons of work (often paid) has gone into optimization in GCC.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 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.Bregalad wrote:Then do yourself a favour and do not learn C.