Hey all,
I recently came across a book called professional Assembly language programming by Richard Blum which teaches Assembly coding for the x86 platform from the ground up in linux. I dont object to installing linux so that doesnt bother me however is it possible that say once I code in GAS using AT&T Syntax, will my code work on windows or will it be Linux specific?
Any help is appreciated.
Posted on 2010-08-15 09:35:57 by v0rtex
If you find a version of GNU toolchain (GCC, GAS, etc...) that is compiled for Windows, then you'll be find.

Typical options are MinGW or Cygwin. Dev-C++ is a development package with a pretty decent IDE and MinGW all packaged as one. wxDev-C++ is a continuation of Dev-C++ as a different project. IMHO, grab wxDev-C++ and go at it.

As for Linux, if you don't want to install it on a machine, you can download Virtual Box and install it (probably Ubuntu?) on there. There's also the option of something like coLinux/andLinux to run Windows and Linux side-by-side, so to speak. andLinux is based on coLinux and Ubuntu, so that might just be your most ideal option.
Posted on 2010-08-15 10:04:18 by SpooK
The syntax is only related to a particular assembler - the binary code it produces is the same.
The answer is yes, you can find Windows-based assemblers that use this syntax.
Posted on 2010-08-15 10:05:23 by Homer

Of course, any Linux system calls you make within your code will have to be modified if you want that same code to port to Windows. You have quite a few options for writing portable code - Mingw, Cygnus, GTK, APR, NSPR, etc...
Posted on 2010-08-15 10:11:59 by p1ranha

The syntax is only related to a particular assembler - the binary code it produces is the same.
The answer is yes, you can find Windows-based assemblers that use this syntax.


Of course, any Linux system calls you make within your code will have to be modified if you want that same code to port to Windows.


Okay so linux will be fine for everything except I would have to port system calls made in linux to be windows compatible (guessing using the user32.dll etc for windows), I believe that linux is the best option for me at the moment as this book seems rather informative and simplifies the process of learning assembly. I will dual-boot linux and windows so I can change between operating systems if needed, also just a side question: C++/ Java (with linux compatible IDE's) Im guessing will still function the same? is this correct or not?
Posted on 2010-08-15 10:34:49 by v0rtex
You'll probably want to shoot for using the Standard C Library, even in assembly language, so that way your programs will (mostly) work in Windows and Linux.

Java is platform-independent, so you should be good with that. C++ is implementation-dependent, so keep using GCC/GPP on both platforms and stick to cross-platform libraries and you'll be fine.
Posted on 2010-08-15 10:42:10 by SpooK
I wouldn't recommend learning at&t syntax to anyone (unless you are a masochist).
And no it's not just reverse order and 1-8(?) more keystrokes per line...
Posted on 2010-08-15 16:02:50 by drizz
Instead of dual-booting, run linux in a virtual machine from windwos - much less hassle.
Posted on 2010-08-15 16:10:57 by f0dder

I wouldn't recommend learning at&t syntax to anyone (unless you are a masochist).
And no it's not just reverse order and 1-8(?) more keystrokes per line...


I would recommend learning anything that allows you to grow as a programmer, even if it isn't your cup of tea.
Posted on 2010-08-15 17:45:44 by SpooK
I would recommend learning anything that allows you to grow as a programmer,...


Right. I'm writing assembly language applications since 25 years. I've seen Zilog, Intel, Motorolla and SPARC machines and of course I could read and write programs for the IBM main frames. The AT&T syntax isn't so bad and in some points it's more clear as the Intel or MS syntax. For example, you don't have to use the dword ptr, qword ptr etc. By the way, since gcc 3.3 the Intel syntax is also possible by using GAS.

Gunther
Posted on 2010-08-15 19:12:44 by Gunther
... and now the epilogue :)

And no it's not just reverse order and 1-8(?) more keystrokes per line...

... It's type checking, I would recommend an assembler that has type checking.

Reverse order - HLA has it, no problem if you get used to it.
More keystrokes per line - I see it as a some kind of intermediate format to intel syntax.
l % $ is there to help the compiler not you.

you don't have to use the dword ptr, qword ptr etc.
is directly related to type checking.  in masm/jwasm you can write code that uses "assume" and never write a single "type ptr" as it is used when type is unknown or  to override a type - type casting. Never used type casting in c++?  ;)

My personal favorite is jwasm. And IMHO there wasn't as powerful assembler as jwasm for linux before.
I will stop here and not go further into how powerful macro language also makes a difference.

To conclude, if need you things done you'll use what ever tool you have available. If you have a choice to learn it never hurts to hear other peoples opinions.

p.s. I agree with everything else said here, have tried andLinux and I think every win-to-lin user should too.


EDIT: If you need an alternative book look up: Sivarama P. Dandamudi - Guide to Assembly Language
Programming in Linux.
Posted on 2010-08-15 22:25:15 by drizz
is directly related to type checking.  in masm/jwasm you can write code that uses "assume" and never write a single "type ptr" as it is used when type is unknown or  to override a type - type casting. Never used type casting in c++?


Yes, type checking. Look: movl means, you're loading a long value into the full register width, while movw loads a word and movb loads a byte. The same with FPU code: flds loads a float, while fldl loads a double. Is that type checking, too?

All together: which assembly language syntax to use has to do with the personal habit and it's a matter of taste, because the generated machine code is exactly the same. Moreover, it has some advanteges to be at home in both worlds.

Gunther
Posted on 2010-08-16 07:00:46 by Gunther
I know what it means and I accept gas for what it is a compiler that crunches code produced by other tools. There's really no reason to use GAS if you have NASM available for programming by a human. Years back you probably didn't have a choice as you now have.

Posted on 2010-08-16 08:10:05 by drizz
Not sure if this bit has been cleared up by the previous posts yet, but:
Most assemblers have their own syntax, and as such, they are incompatible with other assemblers.
There are assemblers that are only available for one or two platforms... For example, MASM and TASM only work under DOS or Windows.
If you want to have a cross-platform solution, you should avoid those.

There are however also assemblers which are available on a wide variety of platforms. The GNU Assembler was mentioned, part of GCC, which is available for Windows, linux and tons of other OSes. This however uses the rather unique AT&T syntax (although an intel syntax mode has been under development for a while now, so you could try that).
There are other options, with a more MASM/TASM-like syntax, such as FASM or NASM, which maintain the advantage that they work on both Windows and linux (and various other OSes).

So, pick your assembler carefully :)
Posted on 2010-08-16 08:12:59 by Scali
The GNU Assembler was mentioned, part of GCC, which is available for Windows, linux and tons of other OSes. This however uses the rather unique AT&T syntax (although an intel syntax mode has been under development for a while now, so you could try that).


Since gcc 3.3 and above, GAS "understands" the intel syntax. Here is a small example:



#include <iostream>
#include <iomanip>

using namespace std;

int round_to_near(double v);

int main(int argc, char *argv[])
{
  double x = 84.723; //value to round
  int a,b; //integer results
 
  //execution starts here
 
  a = round_to_near(x); //round to nearest or even
  b = (int)x; //cast with truncation
  cout << "Double value x        = " << x << endl
      << "Nearest int value a  = " << a << endl
      << "Truncated int value b = " << b << endl << endl;

  return 0; //back to OS
}

/*
round_to_nearest
Task: Round a float value to the nearest integer value.
Input: = float value
Output: nearest integer value
*/
int round_to_near(double v)
{
  __asm__ __volatile__(
    ".intel_syntax noprefix \n\t" //enable Intel syntax
    "sub esp,4 \n\t" //data transfer
    "fld qword ptr \n\t" //load v
    "fistp dword ptr \n\t" //store with round to nearest
    "pop eax \n\t" //load function result
    ".att_syntax prefix \n\t" //switch back to AT&T syntax for the rest
    :
    :"g"(v)
    :
    );
}



You can compile it under 32 bit Linux, BSD or Windows (with mingw) and the application will run on every old 386/387 tandem. But it doesn't compile under x86 based MacOS X. What's the reason for that? MacOS X is a BSD patch and Apple patched also the gcc by "de-optimizing" the intel syntax switch. Bad luck. One has to use AT&T syntax under MacOS X and nothing else.

Gunther
Posted on 2010-08-16 14:15:39 by Gunther

One has to use AT&T syntax under MacOS X and nothing else.


Is this true when using LLVM, the eventual replacement for the GNU toolchain on Mac OS X?
Posted on 2010-08-16 14:35:11 by SpooK
Is this true when using LLVM, the eventual replacement for the GNU toolchain on Mac OS X?


I haven't used LLVM on MacOS X until now. It's definitely true for the Apple based GCC. By the migration of some applications to MacOS X, I had to re-write the inline assembly parts in AT&T syntax.

Gunther
Posted on 2010-08-16 17:14:25 by Gunther
Stringified inline assembly .att_syntax for extra pleasure :twisted:

Seriously, inline assembly be it icc, gcc, ms c++, delphi basm does not matter. For 1-10% asm within a project it does not matter what syntax it is. For 100% asm it does - IMHO.

This being an assembly board I guess 100% asm is not a foreign term.

What I would like to see in c++ is a powerful macro engine that most assemblers have. Text substitution  FTW - NOT.

But what do I know. Alles ist relativ.
Posted on 2010-08-17 10:07:05 by drizz
Stringified inline assembly .att_syntax for extra pleasure


That has to do with the GCC design. It compiles always via assembly; so in any case GAS is involved as back end in the GNU tool chain. The inline code is simply passed into the foo.s file for GAS; you can check that with the -S switch. Do you know a better way to solve that problem?

What I would like to see in c++ is a powerful macro engine that most assemblers have.


That depends. I know, with macro features you can do magic things. There are a lot of ardent macro entusiasts. In most cases, these macro constructs are a bit like high level languages. So, why not use the more powerful high level language for that purposes? On the other hand, you can DEFINE your macros in C/C++ and the compiler will do the rest.

But again, that's only my personal point of view.

Alles ist relativ.


Yes and a matter of taste. All roads lead to Rome.

Gunther
Posted on 2010-08-17 11:51:50 by Gunther
That has to do with the GCC design. It compiles always via assembly; so in any case GAS is involved as back end in the GNU tool chain. The inline code is simply passed into the foo.s file for GAS; you can check that with the -S switch.
I know I know :)

Do you know a better way to solve that problem?
External asm module? What assemblers are there for MacOSX? Nasm, yes?

That depends. I know, with macro features you can do magic things. There are a lot of ardent macro entusiasts. In most cases, these macro constructs are a bit like high level languages. So, why not use the more powerful high level language for that purposes? On the other hand, you can DEFINE your macros in C/C++ and the compiler will do the rest.
I'm glad you didn't suggest template meta programming :)

So, why not use the more powerful high level language for that purposes?

Do you know of any that can do this :
; This generates static data in compile time
; jwasm/masm
.data
align 16
CRC32Table label dword
i = 0
crc = i
WHILE i LT 256
crc = i
REPT 8
   crc = (crc shr 1) xor (0EDB88320h * (crc and 1))
ENDM
DD crc
i = i + 1
ENDM
Please do not suggest external scripting it's not the same.

Posted on 2010-08-17 12:38:41 by drizz