News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Is this right?

Started by why06, January 22, 2010, 07:09:55 PM

Previous topic - Next topic

why06

I'm just not gonna toss source code at you. don't get scared :lol

This is an exerpt from a tutorial I'm reading, Exagone's Tutorial:
Quote
testproc PROTO STDCALL :DWORD, :DWORD, :DWORD

.code

testproc proc param1:DWORD, param2:DWORD, param3:DWORD

mov ecx, param1
mov edx, param2
mov eax, param3
add edx, eax
mul eax, ecx

ret
testproc endp

Now, the procedure does the following calculation. testproc(param1, param2, param3) = param1 * (param2 + param3). The result, the return value, is stored in eax. Local variables are defined like this:

Reason I'm asking is I think this is wrong. It's adding eax to edx, but it only multiplies eax times ecx. So assuming the result of the multiplication is stored in eax the actual equation would be this testproc(param1, param2, param3) = param1 * param3.

Correct?

joemc

I am new myself but i read it as doing

edx = edx + eax  (edx = param2 + param3)
eax = eax * ecx (eax = param3 * param1)

so i agree with you (but i dont know much)

i would rewrite it as
add eax,edx
mul eax,ecx


which i read as:
eax = eax + edx ( eax = param3 + param2)
eax = eax * ecx ( eax = (param3 + param2) * param1

dedndave

you are correct
to achieve the desired result, it should be

        add     eax,edx

most tutorials have bugs here and there - lol
i sometimes wonder if they put them there intentionally to make you debug it   :P
finding bugs is an important part of learning assembler