nesdev.com
http://forums.nesdev.com/

Is it possible to program Raspberry Pi in assembly?
http://forums.nesdev.com/viewtopic.php?f=5&t=16516
Page 1 of 7

Author:  DementedPurple [ Wed Sep 20, 2017 2:17 pm ]
Post subject:  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!

Author:  adam_smasher [ Wed Sep 20, 2017 2:24 pm ]
Post subject:  Re: Is it possible to program Raspberry Pi in assembly?

Quote:
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?

Author:  DementedPurple [ Wed Sep 20, 2017 2:35 pm ]
Post subject:  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/details/en/830D08FF31804AEAA2F03B8F5E89AD14/83psdk

Author:  tepples [ Wed Sep 20, 2017 2:41 pm ]
Post subject:  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.

Author:  DementedPurple [ Wed Sep 20, 2017 4:27 pm ]
Post subject:  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/software-development-tools/ds-5-development-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

Author:  lidnariq [ Wed Sep 20, 2017 4:34 pm ]
Post subject:  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)

Author:  Hangin10 [ Wed Sep 20, 2017 4:35 pm ]
Post subject:  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.

Author:  DementedPurple [ Wed Sep 20, 2017 4:49 pm ]
Post subject:  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.

Author:  rainwarrior [ Wed Sep 20, 2017 5:07 pm ]
Post subject:  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/com.arm.doc.den0024a/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.

Author:  Dwedit [ Wed Sep 20, 2017 5:09 pm ]
Post subject:  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.

Author:  nicklausw [ Wed Sep 20, 2017 7:45 pm ]
Post subject:  Re: Is it possible to program Raspberry Pi in assembly?

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.

Author:  Bregalad [ Thu Sep 21, 2017 4:08 am ]
Post subject:  Re: Is it possible to program Raspberry Pi in assembly?

Quote:
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.

Quote:
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.

Author:  Dwedit [ Thu Sep 21, 2017 6:17 am ]
Post subject:  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.

Author:  Oziphantom [ Thu Sep 21, 2017 7:50 am ]
Post subject:  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.

Author:  adam_smasher [ Thu Sep 21, 2017 7:58 am ]
Post subject:  Re: Is it possible to program Raspberry Pi in assembly?

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:

Quote:
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.

Page 1 of 7 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/