I`ve been doing some programming challenges and just discovered that I barely know the most basic things of asm... I mean I don`t know what the shr, and, or, xor, she, etc instructions do... The biggest problem I`ve been having is like converting a formula to ASM, like:

``Y=X^3-(X+Y)``

``Calc macro x, y ; Y=X^3-(X+Y)    mov edx, x ; (x+y) (at edx)    add edx, y ; ^       ; how do I do x^3?    sub ebx, edxendm``

I've been reading Iczelion's tutorial but it's actually an win32 API tutorial so it hasn't been helping me at these problems... I did search for these subjects but most of my results were either way to advanced and focused only in deeply optimizating your code, or way to superficial saying only things like "The and instrunction compares the registers' bits and keep the equal ones" *???*.
Posted on 2005-08-23 17:17:23 by Lenin
You'll have to give some more information... is the "Y=X^3-(X+Y)" in math or C notation?

In math notation, X^3 means X**3, or "x raised to the power of 3". In C notation, "X^3"  means "XOR x, 3".
Posted on 2005-08-23 17:54:47 by f0dder
C notation...

BTW do you have any good link for my problem?
Posted on 2005-08-23 17:57:48 by Lenin
try this...

``mov	eax, Xxor	eax, 3sub	eax, Xsub	eax, Y``

and for some explanation of assembly rather than just the API, Thomas "Madwizard" Bleeker has written an okay crash course, which you can find at http://www.madwizard.org/dl.php?file=tutors.win32asm (site up again, yay :)).

Other than that, perhaps look at Randall Hyde's Art Of Assembly (even though it's for 16bit assembly), and the intel/AMD processor manuals.
Posted on 2005-08-23 18:03:58 by f0dder
Watch your operator precedence f0dder. XOR has lower precedence that addition and subtraction.  I think the following would be closer to what C would create:

``mov eax, 3sub eax, Xsub eax, Yxor Y, eax``

Spara
Posted on 2005-08-23 18:11:29 by Sparafusile
Doh, ouch, *blush* et cetera :)

(no wonder I always add "superfluous" parenthesis and "logical whitespaces" :) )
Posted on 2005-08-23 18:15:17 by f0dder

and for some explanation of assembly rather than just the API, Thomas "Madwizard" Bleeker has written an okay crash course, which you can find at http://www.madwizard.org/dl.php?file=tutors.win32asm (site up again, yay :)).

Thanks, I'm reading it.
Posted on 2005-08-23 18:39:15 by Lenin
Oh, reading back the topic I think I didn't explain well...

By X^3 I meant x to the power of 3, not x xored with 3...

Sorry... I guess the code would look like this:

``start:	mov eax, 1 ; eax = x	mov ebx, 1 ; ebx = y	mov ecx, 999 ; this is just to make the loop run 1000 times		loopstart:		mov edx, eax ; X (just to remain eax original value)		mul edx, edx		mul edx, edx ; X^3				add ebx, eax ; X+Y		sub edx, ebx ; X^3-(X+Y)				mov ebx, edx ; y =		        inc eax	    dec ecx	jnz loopstart		invoke wsprintf, addr buff, addr format, ebx	invoke MessageBox, NULL, addr buff, addr MsgBoxCaption, MB_OK	invoke ExitProcess, 0end start``

Wheres the syntax error at mul edx, edx? Taken from the tutorial "mul destination, source".
Posted on 2005-08-23 21:26:49 by Lenin
MUL only takes one operand and multiplies that operand by EDX:EAX

``mov ebx, edx ; ebx = edxmov eax, edx ; eax = edxmul ebx ; eax = edx^2mul ebx ; eax = edx^3mov edx, eax``

Spara
Posted on 2005-08-23 22:19:27 by Sparafusile