Discussion:
NASM to compile for 64bit AMD
(too old to reply)
Stian Karlsen
2006-03-02 14:06:16 UTC
Permalink
Hi.

I just got a new 64-bit computer and I'm working on moving my project
witch includes an Assembly library here. My previous PC were 32-bit..

When I try to compile the Assembly library with nasm everything is fine
(note that there is nothing 64-bit in the asm-code yet). However when I
link it to the rest of the project I get a warning:
"i386 arbitecture of input file 'asmlib.o' is incompatible with
i386:x86-64 output. "

I think I know what's wrong, but not how to fix it... I compile the
asmlib.asm as follows:
nasm -o asmlib.o -f elf asmlib.asm

If I've understood correct elf is a 32-bit thing. So, can I write
something else to get 64-bit? Or isn't Nasm compatible with 64-bit?

Is there some other Assembler for Linux witch I should use instead? I've
read that Yasm is a complete rewrite of Nasm and has AMD64 support,
witch sounds like a good sign for me. So, should I use Yasm? If so I'd
be glad if someone could give me an example of what I should write to
compile (for 64-bit Linux).

I'll start writing code for 64-bit soon, so if anyone has some good
startup-hints you're welcome to give me them as well :)


Best Regards,
Stian Karlsen
Frank Kotler
2006-03-02 21:53:37 UTC
Permalink
Post by Stian Karlsen
Hi.
I just got a new 64-bit computer and I'm working on moving my project
witch includes an Assembly library here. My previous PC were 32-bit..
When I try to compile the Assembly library with nasm everything is fine
(note that there is nothing 64-bit in the asm-code yet). However when I
"i386 arbitecture of input file 'asmlib.o' is incompatible with
i386:x86-64 output. "
I think I know what's wrong, but not how to fix it... I compile the
nasm -o asmlib.o -f elf asmlib.asm
If I've understood correct elf is a 32-bit thing.
I *think* ELF is flexible enough to do 64-bit, also, but it would be
different... There's a field in the ELF header...
Post by Stian Karlsen
So, can I write
something else to get 64-bit? Or isn't Nasm compatible with 64-bit?
No. Nasm's 16 or 32-bit only. There's a "nasm64developer" who has a
"private forked version", but not available to the public. Maybe someday...
Post by Stian Karlsen
Is there some other Assembler for Linux witch I should use instead? I've
read that Yasm is a complete rewrite of Nasm and has AMD64 support,
witch sounds like a good sign for me.
Yasm is a possibility. Fasm has 64-bit support. Gas has 64-bit support,
and that ".intel_syntax" switch, if you don't like AT&T syntax.
Post by Stian Karlsen
So, should I use Yasm?
Sure, give it a shot! Let us know how it works out. I meant to follow
along with Yasm's development, but I let it slide and have no idea how
it's coming along. Fasm also seems to be a very nice assembler. Gas has
improved a lot, since its rather bad reputation from the "good old days".
Post by Stian Karlsen
If so I'd
be glad if someone could give me an example of what I should write to
compile (for 64-bit Linux).
My understanding is that the 64-bit ABI is a *completely* different
thing. Maybe find some examples with your 64-bit assembler?
Post by Stian Karlsen
I'll start writing code for 64-bit soon, so if anyone has some good
startup-hints you're welcome to give me them as well :)
Much coffee. Courage!

Best,
Frank
Alex Buell
2006-03-03 10:06:05 UTC
Permalink
Post by Stian Karlsen
Is there some other Assembler for Linux witch I should use instead? I've
read that Yasm is a complete rewrite of Nasm and has AMD64 support,
witch sounds like a good sign for me. So, should I use Yasm? If so I'd
be glad if someone could give me an example of what I should write to
compile (for 64-bit Linux).
Yes, Yasm will support AMD64, go download it and have a play with it. It
will accept code written in gas or nasm format.

$> yasm -m help
Available machines for architecture `x86':
x86 IA-32 and derivatives
amd64 AMD64
--
http://www.munted.org.uk

"Honestly, what can I possibly say to get you into my bed?" - Anon.
jason woodvine
2006-03-03 18:30:25 UTC
Permalink
Post by Stian Karlsen
Hi.
I just got a new 64-bit computer and I'm working on moving my project
witch includes an Assembly library here. My previous PC were 32-bit..
When I try to compile the Assembly library with nasm everything is fine
(note that there is nothing 64-bit in the asm-code yet). However when I
"i386 arbitecture of input file 'asmlib.o' is incompatible with
i386:x86-64 output. "
I think I know what's wrong, but not how to fix it... I compile the
nasm -o asmlib.o -f elf asmlib.asm
If I've understood correct elf is a 32-bit thing. So, can I write
something else to get 64-bit? Or isn't Nasm compatible with 64-bit?
Is there some other Assembler for Linux witch I should use instead? I've
read that Yasm is a complete rewrite of Nasm and has AMD64 support,
witch sounds like a good sign for me. So, should I use Yasm? If so I'd
be glad if someone could give me an example of what I should write to
compile (for 64-bit Linux).
I'll start writing code for 64-bit soon, so if anyone has some good
startup-hints you're welcome to give me them as well :)
Best Regards,
Stian Karlsen
Hi
Ever thought about using fasm (http://flatassembler.net/download.php)
it compile amd x64 assembler
Hope this helps.
Jason Woodvine
Stian Karlsen
2006-03-07 09:50:45 UTC
Permalink
Post by jason woodvine
...
Hi
Ever thought about using fasm (http://flatassembler.net/download.php)
it compile amd x64 assembler
Hope this helps.
Jason Woodvine
Thanks for all replies! Actually I haven't heard about fasm. The problem
is that I'm working on a machine at school where I'm not allowed to
install new programs myself. So I kind of have to use what's available,
and fasm isn't.. But I'll ask the people in charge to install it. Is
it better than yasm in any way?

It turns out that the yasm version installed actually is 0.4.0, and not
0.5.0 witch is the latest. So, I think this gives me some problems. At
least I get some problems when I try to use yasm to compile.

If I compile using :
yasm -m amd64 -o file.o file.asm

I get a warning that "binary object format does not support global
varibles". I'm using my asm-code as library for a c++ project, so the
functions are declared as global in the asm, and this is what yasm
complains about.

So, I thought that it had to be elf to be used this way, and compiled
like this:
yasm -m amd64 -f elf -o file.o file.asm

But I don't know if this leaves me with a 32- or 64bit file. When I run
my program I get "Segmentation fault" instantly. My guess is that it is
because one of the files is 32 bit, and the rest 64bit - witch is what
the machine wants to run. Sounds reasonable?

Anyway, yasm speaks about a fileformat "elf64" witch sounds more like
what I want. This however doesn't seem to exist in yasm 0.4.0. I assume
this is where the problem is.

Does anybody have a clue? Is it possible to compile 64bit files to link
with in a c++ project in yasm 0.4.0??


Best Regards,
Stian Karlsen
s***@crayne.org
2006-03-09 01:57:51 UTC
Permalink
Post by Stian Karlsen
Post by jason woodvine
...
Hi
Ever thought about using fasm (http://flatassembler.net/download.php)
it compile amd x64 assembler
Hope this helps.
Jason Woodvine
Thanks for all replies! Actually I haven't heard about fasm. The problem
is that I'm working on a machine at school where I'm not allowed to
install new programs myself. So I kind of have to use what's available,
and fasm isn't.. But I'll ask the people in charge to install it. Is
it better than yasm in any way?
Hi Stian,

If you're on a *nix based system, just extract the tar.gz into your
home directory. Then update your path environment variable to include
the fasm directory... or just run the fasm executable directly from the
fasm folder...

eg > ~/fasm/fasm my_asm.asm my_app

--
Darran (aka Chewy509) brought to you by Google Groups!
BRG
2006-03-08 10:47:25 UTC
Permalink
Post by Stian Karlsen
Is there some other Assembler for Linux witch I should use instead? I've
read that Yasm is a complete rewrite of Nasm and has AMD64 support,
witch sounds like a good sign for me. So, should I use Yasm? If so I'd
be glad if someone could give me an example of what I should write to
compile (for 64-bit Linux).
I find that YASM works very well for both 32 and 64 bit assembly. It is
pretty compatible with NASM for 32-bit assembly code but adds a 64-bit
capability and can now handle AT&T instruction syntax as well as Intel.

You will, however, need to use a recent version to obtain many of these
features.
Post by Stian Karlsen
I'll start writing code for 64-bit soon, so if anyone has some good
startup-hints you're welcome to give me them as well :)
You will need to learn a lot of new conventions for register usage and
for parameter passing since these are all different for 64-bit code.

Brian Gladman
Stian Karlsen
2006-03-10 12:26:07 UTC
Permalink
Post by BRG
Post by Stian Karlsen
Is there some other Assembler for Linux witch I should use instead? I've
read that Yasm is a complete rewrite of Nasm and has AMD64 support,
witch sounds like a good sign for me. So, should I use Yasm? If so I'd
be glad if someone could give me an example of what I should write to
compile (for 64-bit Linux).
I find that YASM works very well for both 32 and 64 bit assembly. It is
pretty compatible with NASM for 32-bit assembly code but adds a 64-bit
capability and can now handle AT&T instruction syntax as well as Intel.
You will, however, need to use a recent version to obtain many of these
features.
Post by Stian Karlsen
I'll start writing code for 64-bit soon, so if anyone has some good
startup-hints you're welcome to give me them as well :)
You will need to learn a lot of new conventions for register usage and
for parameter passing since these are all different for 64-bit code.
Brian Gladman
Thanks. I ended up using YASM 0.5.0rc1, and for me it seems to work great.

I understood that the parameter passing were rather different -
something witch stalled me for some days. But eventually I found the
answers I needed here:
http://www.x86-64.org/documentation/abi-0.96.pdf

For my use I don't find the register usage very different except that
there is of course an extended version for all registers.

Anyway; by rewriting my code - witch is mostly multiple precision
arithmetic - for 64bit I boosted the speed by around 3 times :)

Thanks for all help!
-Stian

Loading...