[LLVMdev] Hello World assembly without clib "puts"?

David Chisnall David.Chisnall at cl.cam.ac.uk
Sun Sep 30 00:26:43 PDT 2012

On 30 Sep 2012, at 01:05, Andrew Pennebaker wrote:

> Can Hello World be written in LLVM assembly without using a C library function like "puts"?

LLVM IR models a general-purpose unprivileged CPU instruction set and so lacks anything to do I/O.  If you want to interact with anything beyond the CPU and stack, you must either call a library function, issue a system call, or modify some of the target directly.  This basically means either calling a libc function (possibly indirectly) or writing some inline assembly.

For example, on UNIX-like platforms puts() is typically implemented by a call to strlen() to calculate the length and then a write system call with the standard output file descriptor (number 1, traditionally).  The details of a system call are implementation dependent, however you could write a small bit of inline assembly that would issue a write system call and then use this from LLVM IR.

The more important question is: why would you want to do that?  What problem are you trying to solve?


More information about the llvm-dev mailing list