Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370765
  • 博文数量: 66
  • 博客积分: 3201
  • 博客等级: 中校
  • 技术积分: 695
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-04 11:17
文章分类

全部博文(66)

文章存档

2016年(1)

2014年(1)

2012年(1)

2011年(2)

2010年(18)

2009年(42)

2008年(1)

分类: LINUX

2009-02-10 19:03:56

堆栈
    堆栈是由为程序分配的内存的末尾处保留的内存位置构成.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.
阅读(792) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~