64bit and 32bit elf together
Vikas Kumar
walburn at gmail.com
Sun Feb 5 17:21:56 PST 2006
Thanks Peter. I will rephrase my doubt.
If I want to use an instruction in 32 bit mode or 16 bit mode, then I
have to use a Legacy mode prefix like 66h or 67h (Chapter 3, page
88, AMD 64 Architecture Programmer's Manual Volume 1: Application
Programming). So do I specify the prefix before the instruction myself
(using a line like "db 67h" before the instruction), or is yasm
capable enough to decipher that I am trying to use the instruction in
legacy mode, or is there some assembler directive that I can use to
tell yasm that I am trying to use a particular instruction or set of
instructions in Legacy mode. I hope I have made my doubt clear !?
Regards,
Vikas
On 2/5/06, Peter Johnson <peter at tortall.net> wrote:
> 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