64bit and 32bit elf together

Peter Johnson peter at tortall.net
Sun Feb 5 18:14:23 PST 2006


On Sun, 5 Feb 2006, Vikas Kumar wrote:
> 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 !?

Just like NASM, yasm is smart enough to insert the prefix automatically, 
if the instruction is not going to be the same operand/address size as the 
current BITS setting.  There may be cases where you want to override the 
default, and this can be done with "a16" or "o16".

E.g. in bits 64 mode,

mov rax, rbx   ; implicitly 64-bit, yasm generates 0x48 prefix
mov eax, rbx   ; implicitly 32-bit, yasm doesn't generate any prefix (none 
is needed)
mov ax, 5      ; implicitly 16-bit, yasm inserts o16 (0x67 or 0x66, can't 
remember) prefix
push ds        ; implicitly 64-bit
o16 push ds    ; tell yasm to add operand-size prefix.

etc.

Generally yasm will do the "right thing" for a particular 
instruction/operands combination.  Only in unusual cases should you need 
to add the prefix (using o16/a16/etc) yourself.

-- 
Peter


More information about the yasm-devel mailing list