flat assembler
Message board for the users of flat assembler.
Index
> Linux > brainfuck compiler |
Author |
|
vid 26 Mar 2011, 18:16
1. Linux kernel doesn't have heap manager (common memory allocation mechanism for applications) built in. Instead, it expects every application to link to libc. Best way is to link your asm source with libc and use libc for I/O.
2. Again, use libc if you can. You will save yourself many problems. |
|||
26 Mar 2011, 18:16 |
|
klavs.pr 26 Mar 2011, 19:17
So... I have to use malloc() and free() to manage memory. But another question - can I use getchar() or fgetc(FILE*) is more suitable for asm? It is written, that in c stdin is already initialized (when program starts), so I guess stdin is not initialized in asm and I can't use getchar() directly. Or can I?
|
|||
26 Mar 2011, 19:17 |
|
vid 26 Mar 2011, 21:39
Your program definitively should invoke libc startup code to initialize stdin. However I have to admit I don't know how dynamic linking works in Linux (I assume you are linking to glibc dynamically).
|
|||
26 Mar 2011, 21:39 |
|
klavs.pr 27 Mar 2011, 06:08
Ok, thanks vid.
I did it just like libcdemo example does it.(i guess it is not really dinamic linking) Now i have memory allocated and freed, and getchar() works without any manual initialization. But the problem remains - this function does not read single char AND then stop reading. |
|||
27 Mar 2011, 06:08 |
|
vid 27 Mar 2011, 11:20
If you *really* only want to read char from stdin, you could use handle I/O instead of stream I/O (read() from handle 1, instead of fgetc() from FILE* stdin). But I would suggest to rather look into proper linux libc usage than workarounding problems.
|
|||
27 Mar 2011, 11:20 |
|
Tyler 27 Mar 2011, 16:19
You could link your program with crtbegin.o and crtend.o. These can be found in /usr/lib/gcc/?/?/.
|
|||
27 Mar 2011, 16:19 |
|
rugxulo 28 Apr 2011, 02:17
Dumb answer, but hey, what'd you expect from me?
Code: db 30000 dup(0) Or preferably even in .bss or wherever. |
|||
28 Apr 2011, 02:17 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.