64bit and 32bit elf together
Peter Johnson
peter at tortall.net
Sun Feb 5 14:56:37 PST 2006
On Sun, 5 Feb 2006, Vikas Kumar wrote:
> If I write an assembly program for an AMD64 processor system, where I
> want to use both 64-bit and 32-bit compatible instructions, is there a
> special way I need to build it.
>
> For example, the instruction "pusha" works in 32-bit mode and not in
> 64-bit mode.
> If I use the instruction directly in my program I get an invalid instruction.
> I am compiling with yasm using "yasm -f elf file.asm". So how do I
> use the REX prefix 66h before this instruction to change the bit mode
> to 32 instead of 64 dynamically ?
> Is there some directive or do I have to actually use the instruction
> value directly ?
>
> I am a newbie to 64-bit assembly programming and I am having some
> difficulty porting my IA-32 programs to AMD64, for the reason that I
> want to use 32-bit compatible instructions in some places of the code
> and 64-bit compatible instructions in the rest of the code.
Vikas,
I'm a little confused on what you're asking, but if you want yasm to
generate a 64-bit object file, you need to use "-f elf64" or "-f elf -m
amd64". In later snapshots (what you should be using in any case), these
will automatically set BITS 64 for correct 64-bit instruction generation.
The BITS 64 setting will generate correct code for both 64-bit and 32-bit
instructions that are intended to run in 64-bit mode.
--
Peter
More information about the yasm-devel
mailing list