Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Using LibC in x86 Assembly Programs (swippet.com)
47 points by bearwithclaws on March 25, 2012 | hide | past | favorite | 12 comments


Using main and not _start is required by the gcc linker, any other symbol name will not work!.

Not really; while main is default, -e flag allows you to specify an arbitrary symbol as entry point.


AFAIK it's -e, not -E.


I should mention that. Thank you.


You can find more info on Linux (and System V) calling conventions, stack layout, etc. in this document: http://www.x86-64.org/documentation/abi.pdf


This covers only x8_64


True. This doc covers more targets: http://agner.org./optimize/calling_conventions.pdf

However, if I'm going to do low-level server work, I will not be doing it for 32-bit anymore. (There goes the 32-bit EC2 "small" machine, but so be it.)


Why would anyone do this? If you've accepted that you're going to pay the cost to link against libc, use C. If you need to do something that specifically requires assembly, write that function (and that function only) in assembly. GCC will handle all of this very cleanly for you. You don't have to write main() in assembly.


> Why would anyone do this?

Learning exercise? Curiosity? Fun?


If you already have a codebase in assembly, and now you could really use a glibc call or two.


... The point is to use assembly, and a lot of people program in assembly simply for fun.


As well intentioned as I imagine the author to be, there's really nothing here that you couldn't learn from older documentation, as several commentors have pointed out. A more interesting example would have been to calculate running time of some function vs. it's recursive version. Essentially, something besides an extended 'hello world'.


A lot of the stuff you read on here can be found in documentation.. Who the hell wants to go back and read all that nonsense?




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

Search: