简体   繁体   中英

How does leal instruction work?

I'm given these leal instructions and I have to fill in what they mean. I've been trying to study how the leal instruction acts, but I've been having difficulty finding relevant material around the web. What I found is

leal (src1, src2), dst  //dst = src2 + src1

This info doesn't give enough information, because the leal instruction is far more complex than that.

How is this looking?

Assume %eax holds the value x and %ecx holds the value y. Fill in the table.

%edx =  x + 6___________leal 6(%eax),%edx
%edx =  x + y___________leal (%eax,%ecx),%edx
%edx =  x * 5y___________leal (%eax,%ecx,4),%edx
%edx =  9x + 7___________leal 7(%eax,%eax,8),%edx
%edx =  4y + 10___________leal 0xA(,%ecx,4),%edx
%edx =  x + 3y + 9___________leal 9(%eax,%ecx,2),%edx

What I would do is translate the above att syntax over to intel syntax as a first step since that is much more intuitive to analyze.

lea edx, [eax + 6]            
lea edx, [eax + ecx]          
lea edx, [eax + ecx * 4]      
lea edx, [eax + eax * 8 + 7]  
lea edx, [ecx * 4 + 10]       
lea edx, [eax + ecx * 2 + 9]  

Even if you know nothing about the assembly syntax you can look at the above can kind of figure out what they mean. You can mentally map this as an assignment statement in your favor programming language: the thing you are assigning to is on the left-hand side and the value being assigned is on the right-hand side. Now it's just a matter of substituting in the registers with your x and y values:

edx = x + 6
edx = x + y
edx = x + y*4
edx = x + x*8 + 7 => x*9 + 7
edx = y*4 + 10
edx = x + y*2 + 9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM