免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1335 | 回复: 0
打印 上一主题 下一主题

Professional Assembly Language [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-02-10 19:03 |只看该作者 |倒序浏览
堆栈
   堆栈是由为程序分配的内存的末尾处保留的内存位置构成.ESP寄存器用于指向内存中堆栈的顶部.




    注意在调用之前和发出call指令调用的不同:
         调用前:主程序把函数所需要的输入参数存放到堆栈的顶部.
         call后:它把发出调用的程序的返回地址存放到堆栈的顶部.
    存放顺序如下:


The stack pointer (ESP) points to the top of the stack, where the return address is located. All of the input
parameters for the function are located “underneath”(因为返回值是顶部) the return address on the stack. Popping values off
of the stack to retrieve the input parameters would cause a problem, as the return address might be lost
in the process. Instead, a different method is used to retrieve the input parameters from the stack.

常识
While using a label references the data value contained in the memory location, you can get the memory
location address of the data value by placing a dollar sign ($) in front of the label in the instruction. Thus the instruction
movl $values, %edi
is used to move the memory address the values label references to the EDI register.
Remember that in a flat memory model, all memory addresses are represented by 32-bit numbers.
If you have read Chapter 4, “A Sample Assembly Language Program,” you already saw indirect
addressing in action. The cpuid.s program used the following instruction:
movl $output, %edi
This instruction moves the memory address of the output label to the EDI register. The dollar sign ($)
before the label name instructs the assembler to use the memory address, and not the data value located
at the address.
The next instruction in the cpuid.s program:
movl %ebx, (%edi)
is the other half of the indirect addressing mode. Without the parentheses around the EDI register, the
instruction would just load the value in the EBX register to the EDI register. With the parentheses around
the EDI register, the instruction instead moves the value in the EBX register to the memory location contained
in the EDI register.


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/42908/showart_1822749.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP