flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Alternative to gcc

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 14 Mar 2010, 02:17
I'm looking for a (good) C compiler, that uses Fasm-ish asm in the _asm_{}.

Also, while I'm on the topic of C, I've got a question, would functions from the c std lib work for
os deving or do I have to make my own malloc and such.
Post 14 Mar 2010, 02:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 14 Mar 2010, 02:21
For the second question: the C standard lib requires an already existing OS to function. Each version of the C lib is OS specific. So, no, you can't write an OS with the C lib functions.
Post 14 Mar 2010, 02:21
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 14 Mar 2010, 05:54
Thanks. I guess it's also rather important to mention that the compiler needs to be available for linux.

On the topic of the C lib, most functions are straight forward, like printf(), I could do that in 30 minutes(after doing the real work like setting up a terminal), but, the one I mentioned above does not seem so easy. How would I go about allocating memory. What level does malloc effect, like when an app calls malloc, does the function call the kernel, which in turn would allocate the specified amount, which would effect the whole system, or is the memory allocated within the app's data segment, in which case malloc would only effect the specific segment? So far, in the function the kernel uses, I allocate byte by byte with an int variable to keep track of allocated bytes and an array to hold the actual locations of the allocated bytes. Is this an acceptable way?
Post 14 Mar 2010, 05:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 14 Mar 2010, 06:02
Memory allocation is always done by the OS. The C lib will just pass on the request to the OS.
Post 14 Mar 2010, 06:02
View user's profile Send private message Visit poster's website Reply with quote
rxantos



Joined: 19 Jul 2008
Posts: 41
rxantos 24 Apr 2010, 13:47
revolution wrote:
Memory allocation is always done by the OS. The C lib will just pass on the request to the OS.



Some OS'es only have calls to allocate memory in big chunks, and thus malloc/free have special code for doing smaller allocations.
Post 24 Apr 2010, 13:47
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 24 Apr 2010, 14:32
And perhaps even in Windows LocalAlloc and such are resolved by the OS (by OS I mean non user-mode code) ONLY when it is time to allocate more memory pages?
Post 24 Apr 2010, 14:32
View user's profile Send private message Reply with quote
peter



Joined: 09 May 2006
Posts: 63
peter 26 Apr 2010, 02:04
AFAIK, there is no C compiler with FASM-like inline assembly syntax, but check Pelles C, which is small, C99-compliant, with MASM syntax (as opposed to GCC's AT&T syntax). Just like MSVC, it has no support for x86-64 inline assembly, unfortunately Sad
Post 26 Apr 2010, 02:04
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 26 Apr 2010, 02:34
I was just hoping to avoid AT&T syntax. It doesn't look too hard, just looks like it'd be annoying to type all the %s and other seemingly unnecessary characters.
Pelles C's homepage wrote:

Support [...] Windows Mobile (ARM).

Shocked Cool. I wonder if revolution knows about this.
Post 26 Apr 2010, 02:34
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael 26 Apr 2010, 06:54
GNU assembler understands Intel syntax:
Code:
asm volatile(".intel_syntax noprefix\n" /* or pass -masm=intel to GCC and then */
"lea eax, dword ptr [esi + ebx * 4]\n"
".att_syntax prefix\n" /* these two lines won't be necessary */);    
So in order to avoid AT&T syntax, one doesn't have to avoid GCC.
Post 26 Apr 2010, 06:54
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 26 Apr 2010, 07:33
Are the "\n"s necessary?
Post 26 Apr 2010, 07:33
View user's profile Send private message Reply with quote
peter



Joined: 09 May 2006
Posts: 63
peter 26 Apr 2010, 12:46
Yes, it's necessary. GCC passes your assembly code to GNU assembler (use -S switch to view the generated assembly file, where your code is inserted). "\n" is used to separate lines; "\n\t" is also used to align them. See GCC manual.

Fanael, thanks, I did not know that it's possible to use Intel syntax with GCC. Much more readable than AT&T's percents and parentheses Smile

Code:
lea eax, dword ptr [esi + ebx * 4 - 0x10]
    


vs

Code:
leal -0x10(%esi, %ebx, 4), %eax
    
Post 26 Apr 2010, 12:46
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 26 Apr 2010, 20:55
So basically, I could use Intel syntax(*Fasm dialect*) with GAS? Not that I plan to defect, but the possibility to use headers in my assembly code would be nice at times, like when mixing asm and C. Either way, that's still good to know, thanks Fanael.
Post 26 Apr 2010, 20:55
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 26 Apr 2010, 21:15
Quote:
So basically, I could use Intel syntax(*Fasm dialect*) with GAS?

If you added code for that to gcc... which would be quite bothersome.

No, don't think of using FASM header directly in C source. Create a separate asm module, compile to proper object file format, create C header for it, and link it with C code.

But FASM kinda sucks for being mixed with other languages, because you cannot control it from command line, as you do with all other languages.
Post 26 Apr 2010, 21:15
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 27 Apr 2010, 08:01
vid,

Environment variable expansion in include and file directives' file name argument can be used to weaken SSSO principle.
Post 27 Apr 2010, 08:01
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Apr 2010, 08:19
Yeah, but you still need to generate fasm header from something else that applies project-wide (command line options, common inter-language config file, etc.)
Post 27 Apr 2010, 08:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael 27 Apr 2010, 11:29
Tyler wrote:
So basically, I could use Intel syntax(*Fasm dialect*) with GAS?
Unfortunately, the answer is no. GAS uses totally different dialect, which is somewhat similar to MASM.
Post 27 Apr 2010, 11:29
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 28 Apr 2010, 03:12
vid wrote:

No, don't think of using FASM header directly in C source. Create a separate asm module, compile to proper object file format, create C header for it, and link it with C code.

I know how tho mix fasm with C(your tut helped with that)but, I was saying that using C headers in my asm code would be useful. For example, being able to include "stdio.h" and then the assembler know what stdin and other variables defined in stdio are, would be great.
Post 28 Apr 2010, 03:12
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Apr 2010, 08:20
Quote:
I know how tho mix fasm with C(your tut helped with that)but, I was saying that using C headers in my asm code would be useful. For example, being able to include "stdio.h" and then the assembler know what stdin and other variables defined in stdio are, would be great.

That is not always possible. Some "variables" are in fact defined as macros, that call some internal libc function (errno is usually defined this way).
Post 28 Apr 2010, 08:20
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 28 Apr 2010, 08:28
Tyler wrote:
…being able to include "stdio.h" and then the assembler know what stdin and other variables defined in stdio are…
Do you really think FASM will eat (&__iob_func()[0]) as a replacement for stdin? Wink
Win32 headers with their occasional L suffixes in constants confuse FASM as much.
Post 28 Apr 2010, 08:28
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 22 Jun 2010, 04:19
GCC accepts a "#" as a replacement for "\n\t". It's like the ";" for asm. How do I reference this variable("cur_val")?
Code:
struct bigint_t init_bigint_t(unsigned long count, ...)
{
    struct bigint_t new_bigint;
    for(;count > 0;count--)
    {
        block cur_val asm("_cur_val");
        asm volatile
        (
        "pop word ptr [cur_val]#"
        );
    }
}
    

Right now, I'm getting an error saying cur_val is undefined. Do I need to use some mangled version?
Post 22 Jun 2010, 04:19
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.