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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 2:15 pm

@Musketeer: Hi, I won't quote all your questions, I hope it's not a prob.

About number of instructions on ARM: not 100 :-D :-D :-D Try over 1100! Here's a complete list.

About which version to learn: I'd suggest ARMv8, AArch64. Simply because by the time you'll master it, older versions will become long long time obsolete, and maybe not supported by newer hardware at all.

About inlined assembly in gcc: sure, there are plenty, see for example __builtin_memcpy() or __builtin_va_args(), or any other function that starts with "__builtin_".

About realistically implement in asm: I'd say small, low level hardware dependent or performance critical libraries. Compilers are very good at micro-optimisations (which registers are used, how to eliminate branches, optimize pre-fetch etc.), but they have absolutely no clue how to do macro-optimisations (algorithmic (asymptotic analysis) or procedural level (when to use procedures to generate data or use look-up tables instead for example)). Portability and performance are two, mutually exclusive goals (because architectures differ). In the old days CPUs were much slower, therefore performance was more important, meaning more assembly; nowadays portability seems to be the more important goal, therefore you only use assembly for things that cannot be expressed in higher languages (like "mrs" or "eret"), or very performance critical tasks. Assembly is also popular among embedded developers, where the code size is an issue, and the purpose of the program is specific and well defined. Although the shift towards higher languages can be spotted there too (see Arduino microcontroller's C like language for example).

All of the above does not stop people from using Assembly for crazy things of course :-) For example the original QNX and this OS was entirely written in asm! (For the records I wanted to link MenuetOS, but their site is unavailable).

Cheers,
bzt

Musketeer
Posts: 36
Joined: Fri Feb 12, 2016 1:23 pm

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 2:35 pm

Hmmm... Speaking of Free Pascal... Maybe I shuold incerease my skills in it instead - for R Pi is very nice IDE Lazarus... LOT fun too ;) 8-) :lol:

ARM with 1100 instructions is like CISC in this! :shock:

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 3:54 pm

bzt wrote:
Thu Jan 11, 2018 2:15 pm
About which version to learn: I'd suggest ARMv8, AArch64. Simply because by the time you'll master it, older versions will become long long time obsolete, and maybe not supported by newer hardware at all.
Yes, I think its simpler to write anyway. Its definitely more modern and more streamlined - and has tons of registers.
bzt wrote:
Thu Jan 11, 2018 2:15 pm
About inlined assembly in gcc: sure, there are plenty, see for example __builtin_memcpy() or __builtin_va_args(), or any other function that starts with "__builtin_".
They are not inlined assembly (more like intrinsics).
Inline assembler looks more like this:

asm( "msr fpsr,xzr" : );

which clears the floating point status register (clears all the exceptions).

Musketeer
Posts: 36
Joined: Fri Feb 12, 2016 1:23 pm

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 6:57 pm

Raspbian is still globally optimized only for v6, so v7 and v8 ASM are available only in user apps?

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 7:29 pm

Musketeer wrote:
Thu Jan 11, 2018 6:57 pm
Raspbian is still globally optimized only for v6, so v7 and v8 ASM are available only in user apps?
Yes. The published Rasbian works on all Pi models. You are obviously free to compile or assemble directly for ARMv8 for the best performance if you wish.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 19335
Joined: Sat Jul 30, 2011 7:41 pm

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 8:48 pm

Bit of a soap box of mine, but write in C or C++ for speed. Forget assembler unless you have a really pressing need (for example, getting the last iota of performance out of something like a video codec).

Assembler is difficult to write, will almost certainly be slower than the compiler version (unless you REALLY know the instruction set), difficult to document, and difficult to maintain.

And just for reference, I started on 6502 assembler, and was getting quite good at 8051 assembler when compilers got so good it seemed fairly pointless writing in anything but C or C+ (other languages are available)

Of course, a working knowledge of assembler is fairly useful when debugging, so I would not say that people should not know anything about it. Just don;t write any code in it unless you really need to.

/soapbox
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

LdB
Posts: 708
Joined: Wed Dec 07, 2016 2:29 pm

Re: What can be realistically programmed in assembler today?

Fri Jan 12, 2018 1:33 am

It's the truth not a soapbox Jamesh and you can see all the assembler code out of GCC anyhow if you want to play :-)

LdB
Posts: 708
Joined: Wed Dec 07, 2016 2:29 pm

Re: What can be realistically programmed in assembler today?

Fri Jan 12, 2018 1:39 am

Musketeer wrote:
Thu Jan 11, 2018 6:57 pm
Raspbian is still globally optimized only for v6, so v7 and v8 ASM are available only in user apps?
Again you are in a Baremetal section we don't really know about Raspbian but I guess it would be like
inlining 386 or 486 code we used to do back in Intel DOS x86 days which was fine.

You won't be able to get to some of the protected registers your APP will be running level EL0

Someone like Jamesh may know more conclusively.

LdB
Posts: 708
Joined: Wed Dec 07, 2016 2:29 pm

Re: What can be realistically programmed in assembler today?

Fri Jan 12, 2018 1:45 am

Musketeer wrote:
Thu Jan 11, 2018 2:35 pm
Hmmm... Speaking of Free Pascal... Maybe I shuold incerease my skills in it instead - for R Pi is very nice IDE Lazarus... LOT fun too ;) 8-) :lol:

ARM with 1100 instructions is like CISC in this! :shock:
You might as well just start with Ultibo it's all in Pascal and has the most complete operation of peripherals up outside an O/S.

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

Re: What can be realistically programmed in assembler today?

Fri Jan 12, 2018 8:50 am

jamesh wrote:
Thu Jan 11, 2018 8:48 pm
Assembler is difficult to write, will almost certainly be slower than the compiler version (unless you REALLY know the instruction set), difficult to document, and difficult to maintain.
Looking at the code produced by recent GCC (7.2) I would change that from "unless you REALLY know the instruction set" to "even if you REALLY know the instruction set" - compilers have moved on since the 6502 and have many intrinsic advantages compared to humans.

Its not just knowing the instruction set, its about understanding how to simplify code and take short cuts while keeping it provably correct.

The compiler produces code for that instant in time, and for that one single platform, it doesn't care about the future, or portability, or readability, or coding standards, or anything else humans worry about, and it doesn't get tired.

For example a human will decompose a large program into small manageable functions, many of which are only called once. The compiler immediately inlines most of them back into one single huge blob of code - unlike a human it doesn't have any issues with large unreadable functions and can globally optimize things.
jamesh wrote:
Thu Jan 11, 2018 8:48 pm
Of course, a working knowledge of assembler is fairly useful when debugging, so I would not say that people should not know anything about it. Just don;t write any code in it unless you really need to.
Well never professionally of course, but purely for fun at home, maybe, with no expectations of beating the compiler (as the OP said FOR FUNZIES).

Musketeer
Posts: 36
Joined: Fri Feb 12, 2016 1:23 pm

Re: What can be realistically programmed in assembler today?

Fri Jan 12, 2018 9:36 am

Browisng web, Ultibo looks great!

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

Re: What can be realistically programmed in assembler today?

Fri Jan 12, 2018 11:15 am

jahboater wrote:
Thu Jan 11, 2018 3:54 pm
bzt wrote:
Thu Jan 11, 2018 2:15 pm
About inlined assembly in gcc: sure, there are plenty, see for example __builtin_memcpy() or __builtin_va_args(), or any other function that starts with "__builtin_".
They are not inlined assembly (more like intrinsics).
Of course you're right. But I did not meant the source referring to them. What I should have made clear, those are implemented as inlined Assembly in the C compiler's source. So the answer is yes, the C compiler is not entirely written in C. It must have tiny bits of inlined Assembly, and intristics (like __builtin_memcpy and __builtin_va_args) are good examples of that.

Cheers,
bzt

Roken
Posts: 127
Joined: Sun Dec 31, 2017 4:35 pm

Re: What can be realistically programmed in assembler today?

Sat Jan 13, 2018 8:33 am

Writing in assembly, especially for someone just learning, is an exercise in futility, these days. The last time I used assembly was back on my Spectrum 48K, where I needed a fast routine to swap out sprite banks, giving me as many sprites as memory would allow, rather than the hardware limit.

Before that, it was at college. Now, before assembly, we had to write programs in pure binary. My, what fun that was.
Headless PI. OMG, someone cut it's head off. Oh, hang on. it didn't have one to start with.

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

Re: What can be realistically programmed in assembler today?

Sat Jan 13, 2018 9:28 am

Assembler is useful if one wants to run bare metal in the GPU, wants to use the SoC as a super-duper micro without even enabling the ARM cores.

Not that many people would want to but it's fun none the less.

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

Re: What can be realistically programmed in assembler today?

Sat Jan 13, 2018 9:33 am

From an earlier post, here is an example of something in normal user space math programming you just cant do in C.
Turn off denormals (set FTZ):

asm( "vmsr fpscr,%0" :: "r" (1 << 24) );

Return to “Bare metal”

Who is online

Users browsing this forum: No registered users and 1 guest