Hacker News new | ask | show | jobs
by chadaustin 6067 days ago
Oh, I forgot about another huge case for writing assembly language... These days, we have tons of different languages talking to each other, all in the same program. In Mozilla, for example, JavaScript talks to C++ objects via XPCOM/XPIDL. Since the C++ objects expect data laid out on the C stack in a certain order and JavaScript has no notion of the C stack, there is a bit of platform-specific assembly code in the middle that takes the JavaScript values, places them on the stack, and jumps into the C++.

I'm guessing that most languages with built-in foreign function interfaces (like Python's ctypes) have similar thunking layers.

2 comments

Mozilla also use assembly for heavily used computationally expensive operations like image decoding. mmoy’s work is worth looking at:

https://bugzilla.mozilla.org/buglist.cgi?query_format=advanc...

Exactly for this reason I found myself writing assembly again: Invoke C functions from a scripting language. The last I wrote was probably 15 years back.