flat assembler
Message board for the users of flat assembler.

Index > Main > AT&T-to-FASM

Author
Thread Post new topic Reply to topic
zir_blazer



Joined: 05 Dec 2006
Posts: 66
zir_blazer
I'm messing around with both C and ASM. As I learned that the GCC compiler can translate C code directly to ASM, I decided to give it a try to see how some simple things done in C looks at the ASM side, like defining variables, structs, and the like. However, there is a problem: GCC outputs ASM in AT&T syntax, and I know nothing about it (Should be MASM, but doesn't seem to work properly even with the proper parameters, and even then I don't know about MASM and FASM syntaxs differences either).
Anyways, I would want to know if either a compiler that can output ASM in FASM syntax (Could be a GCC mod), or a dissambler that can reverse engineer also on FASM syntax exist, so I could use any type of compiler then check how the code looks later. Learning these languages is fairly hard already and having to deal with MULTIPLE syntaxs to get what you want makes things much more confusing that they should be. A not-too-complex reference guide of direct translation of C code to FASM would also work (For example, I suppose that when you're using the ++ or -- operands on C, on ASM you're simply using the add and sub instructions on a Register).
Post 07 Mar 2013, 04:33
View user's profile Send private message MSN Messenger Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Hopefully, this is still true - seems it would really help you:

http://stackoverflow.com/questions/972602/att-vs-intel-syntax-and-limitations
Quote:
GCC can do Intel syntax with -masm=intel

It looks like you can make GDB use Intel syntax with this:
set disassembly-flavor intel
Post 07 Mar 2013, 04:43
View user's profile Send private message Visit poster's website Reply with quote
zir_blazer



Joined: 05 Dec 2006
Posts: 66
zir_blazer
bitRAKE wrote:
Hopefully, this is still true - seems it would really help you:

http://stackoverflow.com/questions/972602/att-vs-intel-syntax-and-limitations
Quote:
GCC can do Intel syntax with -masm=intel

It looks like you can make GDB use Intel syntax with this:
set disassembly-flavor intel

Been there, done that. -masm=intel uses Intel syntax for instructions, but the rest is all of the AT&T data and metadata.

Example:

att.c C source

Code:
int a = 42;
unsigned char b = 21;

int main(int argc, char const *argv[])
{
        a = 99;
        b = 255;
        return 0;}    


gcc -S att.c (Default AT&T syntax)

att.s content

Code:
        .file   "att.c"
        .globl  _a
        .data
        .align 4
_a:
        .long   42
        .globl  _b
_b:
        .byte   21
        .def    ___main;        .scl    2;      .type   32;     .endef
        .text
        .globl  _main
        .def    _main;  .scl    2;      .type   32;     .endef
_main:
LFB0:
        .cfi_startproc
        pushl   %ebp
        .cfi_def_cfa_offset 8
        .cfi_offset 5, -8
        movl    %esp, %ebp
        .cfi_def_cfa_register 5
        andl    $-16, %esp
        call    ___main
        movl    $99, _a
        movb    $-1, _b
        movl    $0, %eax
        leave
        .cfi_restore 5
        .cfi_def_cfa 4, 4
        ret
        .cfi_endproc
LFE0:    


gcc -S -masm=intel att.c

att.s content

Code:
        .file   "att.c"
        .intel_syntax noprefix
        .globl  _a
        .data
        .align 4
_a:
        .long   42
        .globl  _b
_b:
        .byte   21
        .def    ___main;        .scl    2;      .type   32;     .endef
        .text
        .globl  _main
        .def    _main;  .scl    2;      .type   32;     .endef
_main:
LFB0:
        .cfi_startproc
        push    ebp
        .cfi_def_cfa_offset 8
        .cfi_offset 5, -8
        mov     ebp, esp
        .cfi_def_cfa_register 5
        and     esp, -16
        call    ___main
        mov     DWORD PTR _a, 99
        mov     BYTE PTR _b, -1
        mov     eax, 0
        leave
        .cfi_restore 5
        .cfi_def_cfa 4, 4
        ret
        .cfi_endproc
LFE0:    


As far that I know, in MASM, data is defined the same way that FASM, so that .long 42 should be dd 42, as .byte 21 should be db 21. So the output when using -masm=intel is a ugly mix of both Intel syntax and AT&T leftovers that makes reading it a pain.
Post 07 Mar 2013, 05:21
View user's profile Send private message MSN Messenger Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Yeah, that sucks. I don't know what all that .cfi_* crap is - maybe there is a way to turn that off, and then do something like:
Code:
.file fix ;
.intel_syntax fix ;
.globl fix extrn
.data fix segment data
.long fix dd
.byte fix db
.def fix label
.text fix segment code    
...to let the rest fly.

Best way to learn x86 is in a debugger, imho. But that's how I learned. Smile Debuggers will give you just the code without the overhead of the assembler flavor. It's like - when is the last time you really tasted a potato? Usually, there is so much stuff on it...

_________________
¯\(°_o)/¯ unlicense.org
Post 07 Mar 2013, 08:31
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
bitRAKE wrote:
It's like - when is the last time you really tasted a potato? Usually, there is so much stuff on it...


(Okay, I really can't resist here.) A baked potato is the blandest food on Earth! Apparently nobody "wants" to taste it all by itself! (Only thing worse is probably grits.)

EDIT: Just to be vaguely on-topic:

echo set disassembly-flavor intel > gdb.ini
objdump -d -M intel blah.o

All that .cfi stuff is new in GCC. Just use an older version to avoid it. (No, I can't remember why it's there either. Probably debugging or constructors or whatnot.)
Post 18 May 2013, 22:18
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17280
Location: In your JS exploiting you and your system
revolution
rugxulo wrote:
(Okay, I really can't resist here.) A baked potato is the blandest food on Earth! Apparently nobody "wants" to taste it all by itself!
I guess your taste buds are different from mine. I like a plain, unadorned, unseasoned, unspiced, undecorated, backed potato. [/offtopic]
Post 18 May 2013, 22:40
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 20:29; edited 1 time in total
Post 19 May 2013, 00:32
View user's profile Send private message Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall
http://gcc.godbolt.org/

This is a really good online tool for translating C to ASM.
Post 19 May 2013, 11:24
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 20:25; edited 1 time in total
Post 19 May 2013, 16:26
View user's profile Send private message Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall
HaHaAnonymous wrote:
Quote:

This is a really good online tool for translating C to ASM.

This brings another debate: When will software be written to do the opposed? (A human is capable to do it).


A human is capable of doing anything.
Post 19 May 2013, 18:20
View user's profile Send private message Visit poster's website Reply with quote
zir_blazer



Joined: 05 Dec 2006
Posts: 66
zir_blazer
randall wrote:
http://gcc.godbolt.org/

This is a really good online tool for translating C to ASM.

I saw that link when this Thread was new because it was mentioned in the Heap forum. It took that link two months to get posted here.


All the code that begins with a . seems to be the GCC linker metadata, so its not actual code. At least now I know where all those lines comes from. What I didn't recall if I ever found is a parameter to disable that linker metadata output. But I didn't needed it any longer considering I can just use that converter site that removes that by default.
Post 20 May 2013, 23:43
View user's profile Send private message MSN Messenger Reply with quote
Bob++



Joined: 12 Feb 2013
Posts: 92
Bob++
randall wrote:
HaHaAnonymous wrote:
Quote:

This is a really good online tool for translating C to ASM.

This brings another debate: When will software be written to do the opposed? (A human is capable to do it).


A human is capable of doing anything.


Including Skynet. Cool
Post 25 May 2013, 21:22
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.