News for hackers. Stuff that matters.
Re:A forum engine written in Assembly by jacquesm on Sunday August 27, 2023 @03:13PM (#37285703)
Imagine what you could do with a smartphone if it were programmed entirely in assembly.
Re:A forum engine written in Assembly by cultofmetatron on Sunday August 27, 2023 @03:34PM (#37285874)
assembly? the current standard is kotlin or swift which while reasonably performant, leave a lot on the table. i'd love to have first class support for writing android and ios applications in rust. plenty fast enough for me. my day job is elixir but the memory requirements are a bit high for mobile apps (though I'm sure the guys at nerves would disagree)
Re:A forum engine written in Assembly by simulosius on Sunday August 27, 2023 @03:19PM (#37285761)
Why would anyone want to program a smartphone entirely in assembly?

There is a reason (well actually there are many) that the vast majority of software development these days is done using more advanced languages.

Re:A forum engine written in Assembly by jacquesm on Sunday August 27, 2023 @03:27PM (#37285814)
Cost. Convenience. In that order.
Re:A forum engine written in Assembly by simulosius on Sunday August 27, 2023 @03:39PM (#37285913)
Cost? Please explain why writing programs in assembly is supposed to be *cheaper* than writing programs in a higher level language? The same goes for convenience: Since when is writing an application in assemlby more convenient than writing an application in a modern language?
Re:A forum engine written in Assembly by jacquesm on Sunday August 27, 2023 @03:44PM (#37285949)
No, it is more expensive. And less convenient. For some reason you interpreted both of these the wrong way around. I wasn't answering the question, I was giving examples of those reasons. Which are pretty obvious.
Re:A forum engine written in Assembly by simulosius on Sunday August 27, 2023 @03:50PM (#37286009)
Ah sorry, my bad! Makes a lot more sense this way ;-)
Re:A forum engine written in Assembly by jacquesm on Sunday August 27, 2023 @04:16PM (#37286255)
It certainly does :) I should have quoted that bit though to make it clearer.
Re:A forum engine written in Assembly by squeaky-clean on Sunday August 27, 2023 @09:34PM (#37288633)
How about security? I would never want an app written entirely in assembly to be allowed to take in arbitrary user input from the public internet.

Cross-platform support, which you might argue just falls under convenience, but if you're writing for a different CPU architecture, you've basically written 2 separate programs now and not one.

Re:A forum engine written in Assembly by rep_lodsb on Monday August 28, 2023 @07:54AM (#37292669)
>How about security? I would never want an app written entirely in assembly to be allowed to take in arbitrary user input from the public internet.

As opposed to one written in C, or a scripting language?

When you are coding every arithmetic operation by hand, it is trivial to detect e.g. integer overflows. And even produce the mathematically correct result for operations that temporarily overflow a 32/64 bit register.

(The exception is RISC-V, which seems designed exclusively as a target for C compilers and makes these operations more costly, thus guaranteeing that they won't be used even by compilers for safer languages)

Assemblers also won't remove any instruction you write because of reasoning about "undefined behavior". They won't change constant-time code into something that isn't.

There is a "soft limit" on the complexity of hand-written code, which encourages thinking more carefully about the design, and using data representations that are a good fit to both the problem and the machine.

Yes, all of that is more work, and requires specialized knowledge. But what I don't understand is why most programmers today think that is a bad thing?

Re:A forum engine written in Assembly by johnnyworker on Monday August 28, 2023 @09:12AM (#37293391)
> Yes, all of that is more work, and requires specialized knowledge. But what I don't understand is why most programmers today think that is a bad thing?

Gotta love how when someone makes an wrapper around one feature of ffmpeg weighing over 100 MB, some say that's making great tools more accessible, and is saving the original dev so much time (and the gazillion people who will maintain it forever, because that's not the vanishingly small exception but the norm, The Thing That Must Be Planned For).

But when someone says the think making really tiny and bloat-free things by hand, and with 10x times the effort, the sky is falling, and people put more energy into denouncing what a human can achieve, vs. what modern compilers can do, than it would take to code the thing in brainfuck.

I think it's the corporate focus. Some people think doing something for money, and to multiply money, is intrinsically more "serious" than doing it for the love of it, or just for fun, and with no more of a goal in mind than skipping stones. And I think trauma plays a role, too: Someone mentions making a vanilla whatever (and it doesn't get more vanilla than assembly... it's the opposite of using a framework to be able to make 5 apps in 3 days), and people instantly come swarming to talk about the nightmare of inheriting that "code base".

Re:A forum engine written in Assembly by squeaky-clean on Saturday September 02, 2023 @05:06PM (#37365527)
> But what I don't understand is why most programmers today think that is a bad thing?

I think it's a bad thing because I disagree with you that you'll write fewer bugs because you're coding everything by hand. In my experience how much manual work you need to do correlates 100% with how many bugs the software will have.

Re:A forum engine written in Assembly by kwhitefoot on Sunday August 27, 2023 @03:20PM (#37285773)
Why would you be able to do more, or indeed less, with it programmed in assembly rather than a higher level language?

There isn't anything about assembly language that makes it inherently more effective or efficient than a high level language.

Re:A forum engine written in Assembly by jacquesm on Sunday August 27, 2023 @03:26PM (#37285812)
Your executables will be a small fraction of the size that you expect, you will likely be able to fit the whole thing in cache and you will consume less power because you will be happy with a smaller cycles budget so you can run the cpu much slower.

Of course this all comes at a price: decreased programmer efficiency.

Re:A forum engine written in Assembly by rafram on Sunday August 27, 2023 @03:36PM (#37285891)
I don’t think that’s actually true. Compilers write machine code that’s often much more efficient than anything you could think up by hand, and the bulk of the disk space/memory used by a modern executable is for resources/strings, not instructions. Stereotypical assembly code - extremely lean routines that accept minimal user input and don’t create human-readable output - is indeed smaller than a stereotypical compiled executable, but you’d have trouble beating the compiler 1:1 on the same problem.
Re:A forum engine written in Assembly by jacquesm on Sunday August 27, 2023 @04:27PM (#37286330)
But you won't be writing the same code as the code that you would write in a high level language, and that is sort of the point. You're going to do your utmost not to write such code because then you might as well break out the C compiler.
Re:A forum engine written in Assembly by djur on Sunday August 27, 2023 @11:52PM (#37289536)
Assuming that such code is suitable or even feasible for the problem you're attempting to solve. High-level languages were created specifically for the purpose of writing large, complex software systems. We don't see assembly being used for those systems. Isn't there an argument that high-level languages are simply more fit for that purpose?
Re:A forum engine written in Assembly by rahen on Sunday August 27, 2023 @06:45PM (#37287367)
I don't think so, modern high level languages tend to be linked to huge runtimes that are usually load entirely in memory. Assembly programs don't.
Re:A forum engine written in Assembly by djur on Sunday August 27, 2023 @11:50PM (#37289512)
If you're not linking to those runtimes and system libraries you're reimplementing them. The functionality has to come from somewhere.
Re:A forum engine written in Assembly by rahen on Monday August 28, 2023 @08:52AM (#37293190)
That's what assembly programmers do, they re-use code. They just don't need to ship huge runtimes to be then loaded into memory.
Re:A forum engine written in Assembly by kwhitefoot on Sunday August 27, 2023 @03:50PM (#37286000)
> Your executables will be a small fraction of the size that you expect,

No they won't. There is no way that you can write more compact code than a modern optimizing compiler for anything except the most extreme edge cases.

Re:A forum engine written in Assembly by jacquesm on Sunday August 27, 2023 @04:21PM (#37286291)
Yes you will. Because you can't afford to write code like a modern optimizing compiler. You're going to have the same kind of linecount that you have in your high level language projects and those lines will compile down to a few bytes each at most.

Assembly language binaries tend to be extremely small compared to equivalent code written using a high level language. But: you'll easily spend 10x the time on them. The 'modern optimizing compiler' argument is at the function level: where you write a function using assembly and then write a similar function using a high level language (but still a compiled one, obviously). Yes, the compiler will probably win that race. But an assembly language programmer isn't going to write their code like that at all.

They will reduce the task to the point where it is manageable and that alone will save far more code than the compiler can ever remove. Assembly is (and assembly language based applications are) utterly bloat free, you do what you have to do and nothing more. You can use registers in ways that a compiler would never even think of because you can globally optimize.

No stack frames if you don't need them. No memory accesses if you don't need them.

But code that is hard to maintain and that likely will not be easy to work on with multiple people. 100 KLOC (including comments) -> 16Kb output. No high level language would even begin to approach that.

Re:A forum engine written in Assembly by kaba0 on Monday August 28, 2023 @02:02AM (#37290348)
> They will reduce the task to the point where it is manageable

If they don’t even solve the problem, then it is no competition.

Re:A forum engine written in Assembly by charsii on Sunday August 27, 2023 @04:05PM (#37286137)
It's trivially easy.

One low hanging fruit: Compilers are handicapped by ABIs and language semantics, they must adhere to calling conventions, alignments, paddings, exceptions/stack unwinding, etc.

If you don't have to care about any of that you can save a lot of useless instructions.

And secondly when it comes to size optimizations, compilers are pretty bad (or they tend to still value some speed over pure size). Wont find any modern compiler emitting lodsb/stosb (the non-rep kind) on x86 for example.

Re:A forum engine written in Assembly by kaba0 on Monday August 28, 2023 @02:05AM (#37290389)
> Compilers are handicapped by ABIs and language semantics, they must adhere to calling conventions, alignments, paddings, exceptions/stack unwinding, etc.

I believe most of these are only at potential “extern C” points. Usually these conventions are upheld because they don’t have a huge cost, but to give you a trivial example: inlining is literally about dropping all that in favor of optimizing at a larger scope.

Re:A forum engine written in Assembly by mjan22640 on Sunday August 27, 2023 @05:37PM (#37286858)
I remember claims that compilers are going to emit better machine code than humans when pipelined and speculative execution was first implemented in intel processors. It turned out to not be true. It is still not true as of today. Humans are still better at this, and still by humongous margin. LLMs are going to change that soon however.
Re:A forum engine written in Assembly by kaba0 on Monday August 28, 2023 @02:06AM (#37290394)
Lol at both of these claims.

Humans are better at tiny hot loops. Not at all at anything larger than that.

And call me back once LLMs successfully solve a Sudoku first, before they attempt at spewing out code.

Re:A forum engine written in Assembly by shrubble on Sunday August 27, 2023 @07:25PM (#37287659)
Rather than argue about it, why don't you find an equivalent demo bit of code in both ASM and any other language you choose, and compile both into a static (no linking of libraries) binary?

You should be able to use the Rosetta Code web site to find equivalents written in ASM and say, Rust or C++... then you can easily demonstrate that what you say is factually correct.

Re:A forum engine written in Assembly by kwhitefoot on Wednesday August 30, 2023 @08:19AM (#37320907)
Surely we are talking about real applications not toy educational snippets. Or are you claiming that what works for the dozen or so lines in a typical Rosetta code example works just as well for million line, multi-user, multithreaded, object oriented simulators and optimizers of electrical machines?

At risk of moving the goal posts, I suspect that actually writing such a program in assembler might well be impossible simply because it would probably take too long to write and debug.

If assembler tooling were improved perhaps this could change but who will do it. There have been assemblers with object oriented extensions, perhaps other developer aids could be created. But who will expend the effort?

Re:A forum engine written in Assembly by kaba0 on Monday August 28, 2023 @01:59AM (#37290335)
Many instructions in assembly is simply “logistics” of where should this or that byte go. Machines are eons better at it at large scopes than humans, you surely don’t have enough hair to sit through and carefully examine every register. Also, will you decide on a case by case basis to “inline” a function’s body? What if the function’s body changes? Will you go back to every “inlined” part? What if that makes a more efficient register allocation possible, rewrite the whole function where the inline happened?
Re:A forum engine written in Assembly by rahen on Sunday August 27, 2023 @06:41PM (#37287334)
In principle, this amounts to giving a gift to society: the programmer spends more time on their work so that society as a whole consumes fewer resources. Often, the opposite happens: the programmer transfers their productivity gain into an additional cost for society (usually by contributing to e-waste and added resource requirements).

It's easy to extrapolate this to other domains. Imagine that in order to enhance their productivity, aerospace engineers start buying off-the-shelf generic components and get them assembled as quickly as possible without seeking optimization because you know. The airplanes will consume more fuel and require more maintenance, but it doesn't matter much as the manufacturer can now hire fewer engineers to design a plane, and it's other people's fuel you're wasting anyway.

I understand that seeking immediate profit is the norm, but I'm always a little disillusioned when I see selfless initiatives ridiculed.

Re:A forum engine written in Assembly by djur on Sunday August 27, 2023 @11:49PM (#37289506)
I'm not sure how to make sense of this analogy without assuming that assembly language programming self-evidently produces superior programs than programming in high-level languages, and it's exactly that claim that the comment you're replying to is challenging.
Re:A forum engine written in Assembly by HeckFeck on Sunday August 27, 2023 @03:56PM (#37286052)
Didn't we have something similar to that with the early DOS-based palmtop PCs?
Re:A forum engine written in Assembly by jodrellblank on Sunday August 27, 2023 @05:07PM (#37286662)
You could make a device that was slower than Window CE and go bankrupt! https://news.ycombinator.com/item?id=36570062
Re:A forum engine written in Assembly by jacquesm on Sunday August 27, 2023 @06:45PM (#37287373)
Yes, you could do that too. But you wouldn't have to.
Re:A forum engine written in Assembly by epcoa on Sunday August 27, 2023 @08:24PM (#37288140)
Why not? How do you avoid the same failure mentioned in the linked comment and associated post?
Re:A forum engine written in Assembly by wyldfire on Sunday August 27, 2023 @05:17PM (#37286730)
Weird. I just tried it and it seems to be bootlooping now.

Hmm. maybe there's a bug in one of the lines of someone's code.

Guess I better get started investigating it. 'Cause once I'm done I've got to start porting it to RISC-V.

Re:A forum engine written in Assembly by xigency on Sunday August 27, 2023 @06:33PM (#37287274)
I’m sure it would be very fast at booting and fast at crashing as well. However, on the Android side it’s probably what’s needed to compete with Apple hardware and software.
Re:A forum engine written in Assembly by petabytes on Sunday August 27, 2023 @06:39PM (#37287321)
Kolibri OS was written entirely in Assembly. I think the performance was pretty poor compared to C operating systems. Much easier to write optimized algorithms in high level languages. https://kolibrios.org/en/
Re:A forum engine written in Assembly by ReactiveJelly on Sunday August 27, 2023 @08:21PM (#37288119)
The real problem is that I don't control all the code.

If I had millions of person-hours to RE all the apps I hate, I'd just write them in Rust or something.

Re:A forum engine written in Assembly by kaba0 on Monday August 28, 2023 @01:54AM (#37290288)
Yeah, let’s leave it up to people to allocate registers, they are surely consistently good at it throughout whole code bases /s

In general, writing something in assembly won’t be faster. Some expert can in certain cases come up with a better hot loop in asm, but for larger scopes we can’t be as diligent as a machine can be.