Andrew Pennebaker
2012-Sep-30 00:05 UTC
[LLVMdev] Hello World assembly without clib "puts"?
Can Hello World be written in LLVM assembly without using a C library function like "puts"? Cheers, Andrew Pennebaker www.yellosoft.us -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120929/ed2e5f2f/attachment.html>
The low level details of sending text to the terminal are very OS and target specific. It generally requires putting the values into specific registers and triggering an interrupt. The only way to represent this behavior in LLVM IR would by adding new target specific intrinsics that can be converted during instruction selection to the right machine instructions. On Sat, Sep 29, 2012 at 5:05 PM, Andrew Pennebaker < andrew.pennebaker at gmail.com> wrote:> Can Hello World be written in LLVM assembly without using a C library > function like "puts"? > > Cheers, > > Andrew Pennebaker > www.yellosoft.us > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- ~Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120929/1e041751/attachment.html>
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? David
Andrew Pennebaker
2012-Sep-30 17:30 UTC
[LLVMdev] Hello World assembly without clib "puts"?
> > The more important question is: why would you want to do that? What > problem are you trying to solve?As weird as it sounds, I'm looking for multiplatform assembly languages. I want to learn assembly, but I want my knowledge and code to carry over no matter which operating system I'm using. I regularly use Windows, Mac, and Linux, and I don't want to have to rewrite my codebase every time I boot into another operating system. I can do this by writing assembly code that calls C functions, but I get the distinct feeling: *Why am I doing it this way? Why not just write in C?*And there's only so much assembly you can learn by calling C functions, instead of writing lower level code. I understand that OS's have different conventions for I/O, but what I don't understand is why multiplatform assembly languages like LLVM, NASM, YASM, FASM, and Gas don't give coders an macro or instruction set that gets expanded to the actual, per-OS instructions during assembly. I guess it lowers development efforts to reuse libc rather than add multiplatform I/O assembly macros. Smaller, non-libc dependent binaries don't matter in a world with hefty hard drives. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120930/e0783d32/attachment.html>
Reasonably Related Threads
- [LLVMdev] Hello World assembly without clib "puts"?
- [LLVMdev] Hello World assembly without clib "puts"?
- [LLVMdev] win32 assemblers and linkers for llvm
- [LLVMdev] Native Static Compilers Compatible with LLVM
- [LLVMdev] how to compile asm output for x86 with Micorsoft's ML