Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

lea instruction in 64-bit

728 views
Skip to first unread message

bilsch01

unread,
Oct 23, 2015, 7:14:54 AM10/23/15
to
In 16-bit I have the line: lea si,cvec
I'm assembling ELF64 with NASM. It gives the following error:

invalid combination of opcode and operands.

No wonder, the addresses are 64-bit, so I need a 64-bit register.
So I try: lea rsi,cvec - but it gives the same error.
What is the valid combination of opcode and operands? It would seem
there is none.

TIA. Bill S.

asetof...@nospicedham.gmail.com

unread,
Oct 23, 2015, 8:45:09 AM10/23/15
to
Perhaps:
lea esi, [variable]
lea si, [variable]
lea rsi, [variable]

Bartc

unread,
Oct 23, 2015, 8:45:10 AM10/23/15
to
Try lea rsi,[cvec]. The right-hand-side needs to look like a memory
access. I'm surprised lea si,cvec worked.

--
Bartc

bilsch01

unread,
Oct 23, 2015, 6:01:56 PM10/23/15
to
I neglected to say that the lea si, cvec line is in a 16-bit MASM
program I am converting to 64-bit NASM.

I don't understand both answers here to my question: you say enclose
the variable name in brackets - but in NASM the brackets mean use the
'contents' of the memory address represented by the variable name. To
me that means the cvec represents the address and that [cvec] is not the
address but some value stored at the address. I need someone to
straighten me out about this.

Bartc

unread,
Oct 23, 2015, 6:16:59 PM10/23/15
to
This is what LEA means: to load the effective address of what is a
memory operand. It doesn't mean load immediate.

mov rax, [LAB] ; loads the 8-byte value at LAB to rax
lea rax, [LAB] ; whatever address would have been used
; to load the contents at LAB, instead
; load that address to rax
LAB: dq 0

Of course, in this simple example, mov rax,LAB would also work (if
64-bit immediates are allowed). But an address can also be
[rbp+rsi*4+offset]. That's harder to represent without the square brackets:

lea rax, [rbp+rsi*4+offset]

--
Bartc

bilsch01

unread,
Oct 23, 2015, 6:47:04 PM10/23/15
to
OK, I get it. Thanks.
0 new messages