Tôi có C++ mã sau:Liên quan đến C++ và Assembly, ebp + 8 là gì?
#include <tuple>
std::tuple<int, bool> foo()
{
return std::make_tuple(128, true);
}
int main()
{
auto result = foo();
}
Sau đây là phiên bản tháo rời của foo()
chức năng:
push ebp
mov ebp, esp
sub esp, 24
mov BYTE PTR [ebp-13], 1 // second argument
mov DWORD PTR [ebp-12], 128 // first argument
mov eax, DWORD PTR [ebp+8] // what is this? why we need this here?
sub esp, 4
lea edx, [ebp-13]
push edx // second
lea edx, [ebp-12]
push edx // first
push eax // same as "ebp+8", what is this?
call std::tuple<std::__decay_and_strip<int>::__type, std::__decay_and_strip<bool>::__type> std::make_tuple<int, bool>(int&&, bool&&)
add esp, 12
mov eax, DWORD PTR [ebp+8]
leave
ret 4
Như tôi biết ebp+X
là cho các đối số chức năng truy cập, nhưng không có gì là như thế này cho foo
, vậy tại sao trình biên dịch sử dụng nó? Có vẻ như đây là thông số đầu tiên cho std::make_tuple()
.
EDIT:
tôi không sử dụng tối ưu hóa, tôi chỉ muốn tìm hiểu RE.
Một phần của chính trong hội:
lea eax, [ebp-16] // loaction of local variable
sub esp, 12
push eax // as hidden argument for foo
call foo()
add esp, 12
Mức tối ưu hóa, phiên bản trình biên dịch, tùy chọn trình biên dịch và các cài đặt khác? –
@NickC mà không có bất kỳ tối ưu hóa nào. gcc -m32 c.cpp –
https://www.cs.uaf.edu/2005/fall/cs301/support/x86/index.html –