Pretend like its a game. Haha... :lol
It's not MASM, that's for sure.
PUBLIC @MyFunction@8
_TEXT SEGMENT
_y$ = -8 ; size = 4
_x$ = -4 ; size = 4
@MyFunction@8 PROC NEAR
; _x$ = ecx
; _y$ = edx
; Line 4
push ebp
mov ebp, esp
sub esp, 8
mov DWORD PTR _y$[ebp], edx
mov DWORD PTR _x$[ebp], ecx
; Line 5
mov eax, DWORD PTR _y$[ebp]
imul eax, 3
mov ecx, DWORD PTR _x$[ebp]
lea eax, DWORD PTR [eax+ecx*2]
; Line 6
mov esp, ebp
pop ebp
ret 0
@MyFunction@8 ENDP
_TEXT ENDS
END
I don't know what syntax it is. My wikibook Im using to learn disassembly,which I really am more interested in the assembly (don't hate me), uses this syntax. I think its from cl.exe, but I haven't compiled a programmed from command line in my life, unless u want to count a makefile. plus I just wanted to come back here again, to not become a stranger.
EDIT: Hmmmm just occured to me I might have posted this in the wrong place... =/
Quote from: why06 on February 02, 2010, 11:10:54 PM
It's not MASM, that's for sure.
it is!
however, didn't know before, that masm accept such things like: DWORD PTR _y$[ebp]
Quote from: qWord on February 02, 2010, 11:22:22 PM
Quote from: why06 on February 02, 2010, 11:10:54 PM
It's not MASM, that's for sure.
it is!
however, didn't know before, that masm accept such things like: DWORD PTR _y$[ebp]
Really?! Well I'll say. o_O Shows how much I know. haha :lol
well do you know what the little $ things mean? I don't get it.
in this context it is nothing more than a character of constant name. The '$' get only a special meaning if it stands alone: then it the location counter in current segment (code,data...).
Quote from: qWord on February 02, 2010, 11:35:36 PM
in this context it is nothing more than a character of constant name. The '$' get only a special meaning if it stands alone: then it the location counter in current segment (code,data...).
Hmmmmm? So its like an offset from the ebp?
BTW: nice fractal! Couldn't resist. Im also a fan of fractal art. :thumbu
Quote from: why06 on February 02, 2010, 11:42:32 PMHmmmmm? So its like an offset from the ebp?
no, it is part of the constants name - you can delete it and there will be no difference.
Quote from: why06 on February 02, 2010, 11:42:32 PMBTW: nice fractal! Couldn't resist. Im also a fan of fractal art. :thumbu
:bg I've used a program called Fractalizer (http://www.fractalizer.de/en/)
Quote from: qWord on February 02, 2010, 11:59:42 PM
no, it is part of the constants name - you can delete it and there will be no difference.
Ok. I guess its just a style thing. How bout this
mov DWORD PTR _y$[ebp], edx
Quote from: qWord on February 02, 2010, 11:59:42 PM
:bg I've used a program called Fractalizer (http://www.fractalizer.de/en/)
Cool. I will check that out :wink
well - "DWORD PTR" isn't necessary in that case, but it doesn't hurt anything
it just tells the assembler the size of the data item at _y$[ebp] is a dword
because the source operand is a register, it already knows the size
if it were an immediate constant, the DWORD PTR would be needed
mov _y$[ebp],6
the assembler doesn't know whether the destination operand is a byte, a word, or a dword, so you have to tell it
mov dword ptr _y$[ebp],6
Hmmmm.. well yes that is important too I suppose. Though Im not sure, if it is specified specifically when you say view the same line in a debugger. I think it is, but may its not necessary in that case either... idk. In anycase though that wasn't what I need help on. =/
_y$[ebp]
Im not sure what that means. That's what I really need to know.
Quote from: why06 on February 03, 2010, 01:30:57 AM_y$[ebp]
this results in:
_y$ = -8
...
mov DWORD ptr [ebp+(-8)],edx
you will get the same by writing
mov DWORD ptr [ebp+_y$],edx
or
mov DWORD ptr ebp[_y$],edx
mov [ebp-8],edx
that means the value in the ebp register is an address
in this case, it is an address on the stack
push ebp ;save EBP
mov ebp,esp ;set EBP to the current stack pointer (called the base pointer)
sub esp,8 ;make room on the stack (under ebp) for 2 dwords
now, you have space reserved on the stack for 2 temporary local dword variables, one at address [ebp-4], and one at [ebp-8]
they use these 2 names to reference them
_y$ = -8 ; size = 4
_x$ = -4 ; size = 4
the routine calculates 3*y+2*x and returns the result in EAX
a little sloppy - lol - i wouldn't use a subroutine for that - maybe a macro
Thank you both, really appreciate the help.
Quote from: dedndave on February 03, 2010, 02:07:29 AM
the routine calculates 3*y+2*x and returns the result in EAX
a little sloppy - lol - i wouldn't use a subroutine for that - maybe a macro
And yeh I see what you mean, but it was just meant to be an example.
offtopic: man that fractal program gets slow, when you start increasing the finesteps! nearly killed my video driver o_O
why,
Its just a CL.exe assembler output that has been cleaned up a bit. Take the start values like,
_y$ = -8 ; size = 4
_x$ = -4 ; size = 4
and replace each instance of _y$ with -8 etc .... then go back to each replacement and put the code inside the brackets "-8[reg] becomes [reg-8]" and it will both build in MASM and be readable.
Very nice explanation hutch. That was simple and I understood it perfectly :)
FWIW the C source would look something like this:
int __fastcall MyFunction ( int x, int y )
{
return x*2+y*3;
}
The posted code would be the result of compiling with no optimizations. Using /O2 /G6 the compiler would reduce the procedure to just three instructions:
lea eax, DWORD PTR [edx+edx*2]
lea eax, DWORD PTR [eax+ecx*2]
ret 0
Quote from: MichaelW on February 03, 2010, 04:57:45 AM
FWIW the C source would look something like this:
int __fastcall MyFunction ( int x, int y )
{
return x*2+y*3;
}
The posted code would be the result of compiling with no optimizations. Using /O2 /G6 the compiler would reduce the procedure to just three instructions:
lea eax, DWORD PTR [edx+edx*2]
lea eax, DWORD PTR [eax+ecx*2]
ret 0
Not bad ^_^
int MyFunction(int x, int y)
{
return (x * 2) + (y * 3);
}
http://en.wikibooks.org/wiki/X86_Disassembly/Calling_Convention_Examples