Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Well.. to be fair as a tutorial on assembly language the linked article (which does nothing but make a C-linkage function (main) to call another function (printf)) is going to be a better choice.

Things like system calls and program startup are more advanced topics you'd introduce later, even if they make for shorter code.

And to nit even further: your example is "lower level" but still relies on a metric ton of magic being executed by the linker. If you're allowed to "just invoke ld" the OP's "just call and return from main" trick doesn't sound so bad.



There is no magic in what the linker is doing. It just needs to create an ELF file with two sections and set the start address.

Check this out http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...


Sigh... "just". Find me 100 programmers capable of writing a C function to call another and tell me how many of them understand the ELF format, or even know that it exists. It's a subject worthy of its own tutorial (which you conveniently linked to), and specifically it's a subject that is rather more complicated than how to write an two x86 Linux system calls.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: