NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: legionary on December 05, 2013, 08:41:04 AM

Title: Lea Command
Post by: legionary on December 05, 2013, 08:41:04 AM
How do i use the Lea command in NASM. Im familair with it on Amiga. "Lea data,a0" on Amiga how would i use this to read something to esi register in Linux Mint 15 KDE using NASM?
Title: Re: Lea Command
Post by: encryptor256 on December 05, 2013, 08:56:11 AM
Hi!

Quote
How do i use the Lea command in NASM.

My recent, top most, used lea instruction is like this:
x64:
Code: [Select]
lea rsp,[rsp-8*5]
x32, would be like this:
Code: [Select]
lea esp,[esp-8*5]
1. Example, C/C++:
struct POINT
{
  int x;
  int y;
};
...
POINT ptArray[10]
...
Get pointer to ptArray[7] into eax.

NASM:
Code: [Select]
mov ebx,ptArray       ; C/C++: ebx = &ptArray
mov edx,8               ; C/C++: sizeof(POINT)
lea eax,[ebx+edx*7]

2. Other example, Column's and Rows
Code: [Select]
; ebx is base address
lea eax,[ebx+y*ROW_LEN + x]

Bye, Encryptor256.