GNU nano 2.0.7                                  File: hello.asm                                                                           

section .data
        hello: db 'Hello World!', 10
        helloLen: equ $-hello

section .bss

section .text
        global _start

_start:
        mov eax, 4
        mov ebx, 1
        mov ecx, hello
        mov edx, helloLen

        int 80h

        mov eax, 1
        mov ebx, 0
        int 80h

why does this compile in nasm but not in gas? using linux btw
and when i add rubbish inside the code the code compiles just fine as well, what gives?

Because they're different syntaxs and not even a little bit different...
NASM syntax is based on intel syntax while gas syntax is based on AT&T syntax.


If you write a simple hello world program in C and compile it using
gcc -S mycode.c

It'll leave you with a mycode.s that you can read and see what AT&T asm syntax looks like. You should of learned the difference when you were learning assembly as any good teacher/book should make you familiar with the concepts enough to show you different syntaxs so you can see that even if you don't know the syntax then you can still read the code.

yea but isnt there an option in gas to enable it to read intel syntax now? .intel_syntax or something like that, how do I enable it?

yea but isnt there an option in gas to enable it to read intel syntax now? .intel_syntax or something like that, how do I enable it?

Not that I know of but you could check the man pages. I'm about 4 months out of date :)
Alternatively there are programs out there to convert your code back and forth.

i c, but intel syntax is more portable am i correct to say that? since i read that many more assemblers support intel than at&t

another question is why is it that nasm compiles my code just fine even when i add rubbish inside like random "fsfgssdgvsdgsdf"?
i exprected errors and such

i c, but intel syntax is more portable am i correct to say that? since i read that many more assemblers support intel than at&t

another question is why is it that nasm compiles my code just fine even when i add rubbish inside like random "fsfgssdgvsdgsdf"?
i exprected errors and such

It depends, on unix systems and code from people who've used unix for eons(better to say in the unix world?) you'll find a lot of AT&T syntax. As well if you do inline asm in C you'll be doing AT&T. GDB also while letting you do lines of asm code directly only recognizes AT&T.
That's why when you're learning ASM you're not learning the 'language' per se but you're learning how things work. mnemonics and the differences between tasm/masm/nasm/gas and whatever else are easy to pick up on if you know how things work.

And it depends where you're throwing this 'rubbish' as nasm could potentially just optimize out pieces of 'code' that it finds 'useless'.

can intel syntax be inlined into c code too?

btw, which is better to pick up to learn about computer security, understanding exploits like buffer overflow, etc?

and thanks for the input so far

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.