Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

What can be realistically programmed in assembler today?

Tue Jan 09, 2018 7:30 pm

Hi guys and gals,
what project most complex for/in ASM/ARM etc. do you now? Can normal person program more complex applications (agenda, text editor, Office app...) possible without Java / C++ etc.?

And what do you think COULD be done in ASM?

M.
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

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

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 1:49 am

Silly question assembler is the actual language that all other higher level languages produce either directly or by bytecode so the answer is EVERYTHING THAT IS POSSIBLE. Higher languages just make the job faster and easier for us mere humans, if we were machines we would probably still program in assembler as it is the fastest least constrained language it is after all 1:1 with the opcode set of the CPU.

Almost everything you listed and can think of has been done with assembler. Your question has limited relevance to a baremetal forum and I wonder why you are asking? Baremetal is more about having no O/S or abstraction layers, higher level languages would still be more common than assembler.

https://www.techopedia.com/definition/3 ... rogramming

My personal largest assembler project is 1.28M lines of assembler code for a 5 axis CNC machining centre the development of which ran over 8 years. It was done because it was a custom designed CPU and there was no other compiler options. The CPU was over 80 times faster at matrix calcs than anything on the market and it made the machine 10 times faster than the nearest competitor which is the commercial reason why it was done.

Personally I would not use assembler for the PI there are so many compiler options but there are some that do because they want ultimate speed etc.

dwelch67
Posts: 955
Joined: Sat May 26, 2012 5:32 pm

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 3:36 am

While the everything that is possible is absolutely the answer, another interesting side effect is you can do MORE than you can with high level languages as you have no limitations other than the hardware/instruction set rules.

The real question is knowing that anything that is remotely possible to do with this processor can be done in assembly language, what CANT I do with other languages. That is the more interesting question...

Despite this though most folks dont, for many reasons, write projects in pure assembly language. When I started it out was still not uncommon to have asm developers as well as Pascal and this not new but becoming more widespread...C. Today and for a decade or two a lot of the assembly only projects are what i call "Because it was there" Why did you climb the mountain rather than go around "because it was there". There is also the misinformed thinking they can write a higher performance operating system or whatever, technically possible yes, but you have to be on your A game all the time to beat a pretty good C optimizer. it is easy to find missed optimization opportunities in a decent sized compiled project, but the optimizer doesnt get tired...The because it was there is the better answer, just like why did you write that whole thing in javascript or java or python or perl or C or C++ or .....cause I wanted to...

The fasm folks seemed to have found a happy balance. Want to play with that someday.

Microcontroller folks SHOULD be doing a lot more in assembly language for size mostly and performance second, but it is very disturbing how they actually code. If only their managers knew they spent two to three times per MCU what they could have spent per unit with a less lazy software developer. Flash is a big driver in the cost of those products. They could have hired a handful of contractors saved the few bucks per unit and still made more profit.

I happen to work somewhere where a lot of assembly is still done, it is lets say specialized processors, microengines (think microcode) not full blown general purpose processors. Still count instructions for performance, go over budget on clocks have to re-visit the code to remove enough instructions to save on those clocks. And because of this complexity folks are really wanting a compiler or replace the processors with something completely different and general purpose with a compiler (despite the doubling or tripling of the cost per chip, and or half/third/quarter of the performance).

Standing on my soap box the biggest problem we have is not enough folks care about how things work, not enough actual/real bare metal programmers (thank the gods for this forum) not enough assembly programmers not enough folks that can understand how a compiler works or how to manipulate it to change the output. Almost everything with an on/off switch today has a processor in it, a higher percentage every year, each of those processors have to be developed and tested, each needs or at least wants a compiler with someone competent to make the back end or better the peephole optimizer. Every one of those processors has to be booted to some state where the compiled code can take over (bare metal than then maybe spawns the operating system and applications). But the majority of the population including software developers dont understand just how many individual processors are in a laptop, one dozen? two dozen? more? Much less all they want to do is make it rich on some iphone app they wrote in a high level point and click programming language. fame and fortune with little to no real work. That or a long line of naysayers, you can never beat an optimizer (clearly a statement of someone who has no clue about what they are talking about), there is no value learning bare metal, or assembly language, etc. If you would like to continue to have phones that actually boot and work, development computers laptop or other, some percentage of us need to beat down the naysayers. And some percentage need to care about assembly language and be somewhat competent. The world will literally come to a screeching halt if the next generation doesnt pick up where the old timers left off. Including having strong assembly language and instruction set architecture knowledge to be able to write an application. (soapbox off).

Although statistically nobody programs whole applications/operating systems in assembly language. Just like it always has been it is very much possible, the tools are there with macros to ease the burden just like functions and apis ease the burden of programming C. And you can always do more in assembly language than you can in a high level language, or to say it another way anything you can do in a high level language (from a problem solving or functional working solution) you can do in assembly language. The smart? sane? ones compile first, then as needed take the compiled output, and hand tune it, rather than just hand write everything, just hand tune or hand write the problem areas not the whole project. If you dont have the experience/skills though can you really hand tune that function or are you making it worse not better (for example fewer instructions doesnt automatically mean faster, you can have several times more instructions and outperform, or lets say I can write some benchmarks where the much longer program runs faster, and you can do once you think about it).

I do a lot of disassembly and examine the compilers output or at work examine the program in a processor sim, against the disassembly of the program. My bootstrap stuff is small as possible, but my early days after BASIC became no fun and before I could afford a compiler or have a job that had one, all of my programming was in assembly language. x86 DOS/BIOS calls. Even better I used debug for a long time before I found out about BBSes and then found an actual assembler I could afford (free for non-commercial use). Used to write scripts that would shove the instructions into debug and save the .com file out. I did write a very much cheating udp stack in 8051 assembler, and just absolutely bare minimum enough of a TCP stack to get one tiny web page to load into a web browser before the stack crashed and burned (same 8051). Other than that no other personal large assembly only projects. I mostly stare at assembly language, or sometimes write a disassembler or instruction set simulator. Mostly let the C compiler create my assembly that becomes machine code. I do microcode at work, no I do not work for intel and it is not a cisc machine, but usually not more than a few dozen lines, I use it to beat up on something in the chip, dram, etc. So I have written a fair amount, but in a few dozen lines at a time.

David

User avatar
Ultibo
Posts: 158
Joined: Wed Sep 30, 2015 10:29 am
Location: Australia
Contact: Website

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 10:43 am

dwelch67 wrote:
Wed Jan 10, 2018 3:36 am
Standing on my soap box the biggest problem we have is not enough folks care about how things work, not enough actual/real bare metal programmers (thank the gods for this forum) not enough assembly programmers not enough folks that can understand how a compiler works or how to manipulate it to change the output.
...

The world will literally come to a screeching halt if the next generation doesnt pick up where the old timers left off. Including having strong assembly language and instruction set architecture knowledge to be able to write an application. (soapbox off).
+1

I couldn't agree more David.

Garry.
Ultibo.org | Make something amazing
https://ultibo.org

Threads, multi-core, OpenGL, Camera, FAT, NTFS, TCP/IP, USB and more in 3MB with 2 second boot!

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 12:58 pm

I of course ment biggest app DIRECTLY in ASM, I am aware of CPUs low level work and high langugages. :shock:

Modern CPUs are definitely more complex: when I played with Atari 800 it got 64 kB RAM and poking a lot of adress did something useful - , today you got 1 GB + tens of registers etc. on RPi2+ and lot of new inctructions (56 on 6502 - https://en.wikipedia.org/wiki/MOS_Technology_6502), so programming in assm today seems to me MUCH more hardcore than old days... Even if we got better tools - doesnt ARM on Pi3 have above 100 instructions?

Question is - is it even realistic to learn ASM today when most jobs are for C/C++ and Java/some SQL clone. Beside for fun of course?
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

User avatar
RaTTuS
Posts: 10415
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 3:06 pm

if you have a small team [1-4ish] , then building in assembler can be fine, you make libraries & macros ...
but you have to know what your doing together....
if you loose people then you have to train up new people to get up to speed with your system... so you may as well go for c/ c++ etcc
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

gkaiseril
Posts: 636
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 3:51 pm

Everyone should realize that languages like C are created using assembler to create the compiler an linker. Because of this approach it is possible to easily move the C language for one type of CPU to another type of CPU by editing the assembler code to create the compiler and linker to a basic level of the C language and then using the basic C language to code the more powerful versions of C or using a cross assembler to compile the C language for a targeted CPU and then just move the new executable code in the new machine code to the targeted CPU. . Since C also includes in line assembler, ARM GCC Inline Assembler Cookbook, one can mix both C code and assembler within the same source code as needed.
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.

User avatar
PeterO
Posts: 4942
Joined: Sun Jul 22, 2012 4:14 pm

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 4:04 pm

gkaiseril wrote:
Wed Jan 10, 2018 3:51 pm
Everyone should realize that languages like C are created using assembler to create the compiler an linker.
Last time I checked, gcc is written in C. I doubt ANY high level language compilers have ANY assembler in them as it would tie them to that archetecture. AFAIK they are mostly written in C for good performance and maximum portability.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

gkaiseril
Posts: 636
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 6:36 pm

The all started out from assembly code. Once the basic compiler was up and running, then that compiler was used to build newer versions of the compilers in the higher level language with more features like optimization and pre-compilers.
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.

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

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 7:09 pm

From a compiler bootstrapping point of view, the very wide availability of decent C compilers on most platforms, means you can start in C and omit the assembler phase. As PeterO says, GCC and others are of course written in C, though I bet there are very tiny bits of inline assembler (-march=native perhaps?).

Considerable pieces of the C library are written in assembler, but there are of course pure C alternatives included (look in the sysdeps tree).

User avatar
PeterO
Posts: 4942
Joined: Sun Jul 22, 2012 4:14 pm

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 7:13 pm

gkaiseril wrote:
Wed Jan 10, 2018 6:36 pm
The all started out from assembly code. Once the basic compiler was up and running, then that compiler was used to build newer versions of the compilers in the higher level language with more features like optimization and pre-compilers.
Thread title is "What can be realistically programmed in assembler today?" History lessons are not really what we are talking about..

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 7:29 pm

How much of a hassle is a backward compatibvbilit between v6/v7/v8 in Pi1/2/3 ?

I know only Java, Free Pascal and pondering about dive into ASM pool... FOR FUNZIES, mostly, on PI of course.
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

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

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 8:11 pm

Musketeer wrote:
Wed Jan 10, 2018 7:29 pm
How much of a hassle is a backward compatibvbilit between v6/v7/v8 in Pi1/2/3 ?
Nil if you write your program in a HLL. In assembler, write it for the v6 and it should mostly work on a v8, obviously ARMv8 has new instructions that the older CPU's don't have. I prefer 64-bit mode which provides a decent baseline, for example NEON is guaranteed always present (and its a much better version), as of course are basic things like integer division and 31 registers. Aarch64 is more similar to other modern processors, so what you learn will carry over.
I know only Java, Free Pascal and pondering about dive into ASM pool... FOR FUNZIES, mostly, on PI of course.
Christopher Strachey (NATO) once famously said "you can push a pea up a mountain with your nose, but ...". Writing a large program in assembler is a bit like that nowadays I think.
You definitely have the right attitude (FOR FUNZIES) in which case go for it and enjoy!

Don't expect to be able to beat the C compiler for day to day code (SIMD possibly), use GCC 7+ and look at the assembler produced - its a great way to learn how to do things.

You should be able to learn C easily enough which will give you real speed if you want that.

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: What can be realistically programmed in assembler today?

Wed Jan 10, 2018 8:16 pm

Lot of food for thought.... Thx everyone for time.
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 3:51 am

PeterO wrote:
Wed Jan 10, 2018 4:04 pm
Last time I checked, gcc is written in C. I doubt ANY high level language compilers have ANY assembler in them as it would tie them to that archetecture. AFAIK they are mostly written in C for good performance and maximum portability.
PeterO
GCC is in C/C++ but Microsoft compiler was in assembler up until Visual Studio 2015 it was covered in a writeup
https://blogs.msdn.microsoft.com/vcblog ... -compiler/

As per the article some of the compiler dated back to 1982 and your exact reason Visual Studio could only run on Intel architecture and had no portability.
Last edited by LdB on Thu Jan 11, 2018 4:07 am, edited 1 time in total.

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 4:01 am

Musketeer wrote:
Wed Jan 10, 2018 7:29 pm
How much of a hassle is a backward compatibvbilit between v6/v7/v8 in Pi1/2/3 ?
There is actually very little problem with backward compatibility it takes a handful of macros and function pointers, it's dead simple to detect the Pi model and adjust memory pools for it. My boot code has been doing it since I first started working with the Pi.

The harder one is actually getting older code like V6 to run on V7/V8 when you are doing some thing because you have to teach it about registers that a v6 compiler doesn't know about. So you have to embed opcode as byte data where you need it a trick I learned from Ultibo.

For example to get V6 code (Pi1) to drop a Pi/Pi3 out of hypervisor mode

Code: Select all

/* I borrowed this trick from Ultibo because ARM6 code running on an ARM7/8 needs this opcode  */
/* The ARM6 compiler does not know these instructions so it is a way to get needed opcode here */
/* So our ARM6 code can drop an arm7 or arm8 out of HYP mode and run on an ARM7/8.             */
/* Native ARM7/8 compilers already understand the OPCODE but do not mind it this way either	   */        
	.long 0xE12EF30E						;@ "msr ELR_hyp, lr" Set the address to ELR_hyp
	.long 0xE160006E						;@ "eret" Elevated return which will exit at .NotInHypMode in SVC_MODE

User avatar
PeterO
Posts: 4942
Joined: Sun Jul 22, 2012 4:14 pm

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 9:16 am

LdB wrote:
Thu Jan 11, 2018 3:51 am
GCC is in C/C++ but Microsoft compiler was in assembler up until Visual Studio 2015 it was covered in a writeup
https://blogs.msdn.microsoft.com/vcblog ... -compiler/
I can't see any explicit mention of when it stopped being written in assembler in that article.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 9:55 am

I couldn't see any mention of it being written in assembler at all.

Imagine trying to keep up with all the changes in modern C++ with code written in assembler - doesn't bear thinking about :)

User avatar
PeterO
Posts: 4942
Joined: Sun Jul 22, 2012 4:14 pm

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 10:01 am

jahboater wrote:
Thu Jan 11, 2018 9:55 am
I couldn't see any mention of it being written in assembler at all.
:roll: Good point ! But the early versions probably were in assembler, unless they cross compiled from a UNIX compiler of some sort onto x86.
We're rather heading "off topic".
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 11:02 am

PeterO wrote:
Wed Jan 10, 2018 7:13 pm
Thread title is "What can be realistically programmed in assembler today?" History lessons are not really what we are talking about..
That everything could be written in assembler doesn't mean it's realistic or practical to do so. Likewise that most compilers generate assembler code is neither here nor there; those compilers are used because they make it easier to create code and applications.

I spent twenty years writing assembler for embedded systems. At the time that made sense; we squeezed every last drop out of what was available. We wiped the floor with our competition who just couldn't match what we were doing.

But I would never consider writing in assembly now other than where maximum speed were required. I have used C as an advanced assembler, have carefully coded to generate no worse than hand written assembler but we all know the real advantage of any HLL is to express, represent and manipulate data structures with ease, some of which may be large and complex.

The effort of writing and debugging code in assembler outweighs any disadvantages of using a HLL in all but a very few cases, even for small programs. Why would anyone waste days writing an assembly language program when that can be written in Python in ten minutes, requires minimal debugging, basically just works, and runs on almost any platform it can be thrown at ? There would have to be a very compelling argument to use assembler for that.

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 11:08 am

Which ARM you consider most newbie user friendly? :?: :idea:
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 11:22 am

hippy wrote:
Thu Jan 11, 2018 11:02 am
But I would never consider writing in assembly now other than where maximum speed were required. I have used C as an advanced assembler, have carefully coded to generate no worse than hand written assembler
Even then I would use C. With your experience and considerable effort, you might possibly match GCC for a small program, but the compiler will never get tired or bored and will continue generating efficient code for millions and millions of lines - no human can do that.
There would have to be a very compelling argument to use assembler for that.
Purely for fun and education perhaps.

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 11:29 am

Musketeer wrote:
Thu Jan 11, 2018 11:08 am
Which ARM you consider most newbie user friendly? :?: :idea:
ARMv8 (Pi3 and new Pi2) is the latest and is current (and can do A64 which is great).
I know some people here say 8-bit micros are the easiest things to start with, but I don't agree. In general the more capable the instruction set is, the more likely you will find an instruction to do what you want, easily, in one go, rather than having to hand code it all. The older Pi's don't have integer division for example, so instead of just using "sdiv", you have to write, or find, a complete function to do it.

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 1:11 pm

jahboater wrote:
Thu Jan 11, 2018 9:55 am
I couldn't see any mention of it being written in assembler at all.

Imagine trying to keep up with all the changes in modern C++ with code written in assembler - doesn't bear thinking about :)
Your over thinking it GCC is effectively the same you take the high level language spit assembler macro blocks and then run it thru the assembler which microsoft called MASM
https://en.wikipedia.org/wiki/Microsoft_Macro_Assembler

As you can read MASM was a stand alone product and had an optional visual interface it was actually more advanced than any C compiler
With the 6.15 release in 2000, Microsoft discontinued support for MASM as a separate product, instead subsuming it into the Visual Studio toolset.
So the history of it was built around assembler NOT C/C++ or any other language

You may also care to look at many of the windows programming at the time which was done directly via assembler
http://win32assembly.programminghorizon ... rials.html

MASM was a funny beast it wasn't quite a normal assembler but perhaps a look historically at the myths about it may help
http://www.masm32.com/myths.htm

It's the same as DOS itself which was written in assembler and the Early MS code was recently released for learning but the copyright remains in force to Microsoft.
http://www.computerhistory.org/atchm/mi ... urce-code/

FreePascal was much the same .. Florian, Matt Spiegel, myself and many of other wrote massive blocks of assembler until after a couple of years it could compile it's own source and we could finally do away with the stand alone assembler and Borland Turbo Pascal. It was actually at that point it actually become what we know today as FreePascal. The history is correctly described in wikipedia and all us old farts are listed in the FreePacal credits
https://en.wikipedia.org/wiki/Free_Pascal
Originally, the compiler was a 16-bit DOS executable compiled by Turbo Pascal. After two years, the compiler was able to compile itself and became a 32-bit executable.

So assembler project development was quite commonplace, It was fun times and very different to today :-)

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

Re: What can be realistically programmed in assembler today?

Thu Jan 11, 2018 1:54 pm

LdB wrote:
Thu Jan 11, 2018 1:11 pm
So assembler project development was quite commonplace, It was fun times and very different to today :-)
Yes indeed.
35 years ago or so, I wrote every real program on IBM mainframes in assembler.

Return to “Bare metal, Assembly language”