Reputation:
This is the ASM code:
__declspec(naked) void foo(something* t)
{
__asm {
push ebp
mov ebp, esp
mov eax, dword ptr [t]
mov dword ptr [eax], 0
mov dword ptr [eax+4], 0
mov esp, ebp
pop ebp
}
This would be the C version of the code:
struct something {
_int64 a;
_int64 b;
_int64 c;
};
void foo(struct* something) {
something->a = 0;
}
Now, I am wonder if I could do the same thing without storing t in eax. And just use ebp instead. But I am not sure where "a" would be (ebp+28 or ebp), and if it is even possible. This doesn't seem to work. Does anyone if this is possible, and how?
mov dword ptr [ebp+28], 0
mov dword ptr [ebp+24], 0
Upvotes: 0
Views: 46
Reputation: 61351
Arbitrary nesting of expressions is not possible in assembly. That's what high level languages were invented for. In other words, yes, you have to load the value of t
into a register if you want to dereference it. Assembly does not support constructs like
mov dword ptr [[ebp+28]], 0
which is what you're aiming for. ebp+28
is not the address of t->a
; it's the address of t
, which is the address of t->a
.
Also, the assembly snippet zeros out both t->a
and t->b
while the C one only does a
. They're not equivalent.
Upvotes: 2