DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Assembly (http://www.daniweb.com/forums/forum125.html)
-   -   assembly language help (http://www.daniweb.com/forums/thread190090.html)

unregistered May 3rd, 2009 3:28 am
assembly language help
 
  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?

sysop_fb May 3rd, 2009 11:33 pm
Re: assembly language help
 
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.

unregistered May 4th, 2009 2:41 am
Re: assembly language help
 
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?

sysop_fb May 4th, 2009 2:46 am
Re: assembly language help
 
Quote:

Originally Posted by unregistered (Post 861294)
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.

unregistered May 4th, 2009 2:48 am
Re: assembly language help
 
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

sysop_fb May 4th, 2009 3:02 am
Re: assembly language help
 
Quote:

Originally Posted by unregistered (Post 861304)
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'.

unregistered May 4th, 2009 3:07 am
Re: assembly language help
 
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


All times are GMT -4. The time now is 4:49 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC