堆栈
堆栈是由为程序分配的内存的末尾处保留的内存位置构成.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.
阅读(791) | 评论(0) | 转发(0) |