当前位置:  技术问答>linux和unix

对leal何时加载有效地址,何时进行简单计算实在搞不清楚,大家帮帮忙!

    来源: 互联网  发布时间:2015-09-30

    本文导语:  从书上看到,leal除了加载有效地址,有时还可以利用它进行简单计算,下面是两个例子 加载有效地址 leal -4(%ebp), %edx load address to %edx movl (%edx), %eax          load value  简单计算,假设%eax存放一个变量x leal (...

从书上看到,leal除了加载有效地址,有时还可以利用它进行简单计算,下面是两个例子

加载有效地址
leal -4(%ebp), %edx load address to %edx
movl (%edx), %eax          load value 

简单计算,假设%eax存放一个变量x
leal (%eax, %eax, 4), %edx         5*x -> %edx

我不太明白的就是什么时候leal是在加载地址,什么时候是在简单计算?看不出来区别啊!

|
可能看例子更容易理解些.把你提到句子写到leal.s,然后用gdb查看.
.section .data

.section .text

.globl _start
_start:
pushl $2
call lea_test
addl $4,%esp
movl %eax,%ebxinfo

movl $1,%eax
int $0x80

.type lea_test,@function
lea_test:
pushl %ebp
movl %esp,%ebp
subl $4,%esp

movl 8(%ebp),%eax
movl %eax,-4(%ebp)

leal -4(%ebp),%edx
movl (%edx),%eax

leal (%eax,%eax,4),%edx
movl %edx,%eax

leave
ret

(gdb) run
Starting program: /root/asm/a/leal
 
Breakpoint 1, lea_test () at leal.s:21
21              movl 8(%ebp),%eax
Current language:  auto; currently asm
(gdb) info registers
eax            0x0      0
ecx            0x0      0
edx            0x0      0
ebx            0x0      0
esp            0xbfffef30       0xbfffef30
ebp            0xbfffef34       0xbfffef34
esi            0x0      0
edi            0x0      0
eip            0x804808d        0x804808d
eflags         0x286    646
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
es             0x2b     43
fs             0x0      0
gs             0x0      0
(gdb) nexti
22              movl %eax,-4(%ebp)
(gdb) info registers
eax            0x2      2
ecx            0x0      0
edx            0x0      0
ebx            0x0      0
esp            0xbfffef30       0xbfffef30
ebp            0xbfffef34       0xbfffef34
esi            0x0      0
edi            0x0      0
eip            0x8048090        0x8048090
eflags         0x386    902
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
es             0x2b     43
fs             0x0      0
gs             0x0      0
(gdb) nexti
24              leal -4(%ebp),%edx
(gdb) info frame
Stack level 0, frame at 0xbfffef34:
 eip = 0x8048093 in lea_test (leal.s:24); saved eip 0x804807b
 source language asm.
 Arglist at 0xbfffef34, args:
 Locals at 0xbfffef34, Previous frame's sp in esp
 Saved registers:
  ebp at 0xbfffef34, eip at 0xbfffef38
(gdb) nexti
25              movl (%edx),%eax
(gdb) info registers
eax            0x2      2
ecx            0x0      0
edx            0xbfffef30       -1073746128
ebx            0x0      0
esp            0xbfffef30       0xbfffef30
ebp            0xbfffef34       0xbfffef34
esi            0x0      0
edi            0x0      0
eip            0x8048096        0x8048096
eflags         0x386    902
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
es             0x2b     43
fs             0x0      0
gs             0x0      0
(gdb) nexti
27              leal (%eax,%eax,4),%edx
(gdb) info registers
eax            0x2      2
ecx            0x0      0
edx            0xbfffef30       -1073746128
ebx            0x0      0
esp            0xbfffef30       0xbfffef30
ebp            0xbfffef34       0xbfffef34
esi            0x0      0
edi            0x0      0
eip            0x8048098        0x8048098
eflags         0x386    902
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
es             0x2b     43
fs             0x0      0
gs             0x0      0
(gdb) nexti
28              movl %edx,%eax
(gdb) info registers
eax            0x2      2
ecx            0x0      0
edx            0xa      10
ebx            0x0      0
esp            0xbfffef30       0xbfffef30
ebp            0xbfffef34       0xbfffef34
esi            0x0      0
edi            0x0      0
eip            0x804809b        0x804809b
eflags         0x386    902
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
es             0x2b     43
fs             0x0      0
gs             0x0      0
(gdb)


    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3