# converting c++ to assembly

can someone help me with this i am just learning and i dont know how to start it i dont know what does this two line z = power(x, g);
z = z > 0 ? z : -z; mean and how to write it in assembly i would really appreciate it if anyone help with this program ---->

main()
{
fn(1,3,2,4,8,6,5);
}

fn(int a, b, c, d, e, f, g)
{
register int x, y, z;
x = a + b*c
y = d - e / f;
z = power(x, g);
z = z > 0 ? z : -z;
return x + y + z;
}

• : can someone help me with this i am just learning and i dont know how
: to start it i dont know what does this two line z = power(x, g);
: z = z > 0 ? z : -z; mean and how to write it in assembly i would
: really appreciate it if anyone help with this program ---->
:
:
: main()
: {
: fn(1,3,2,4,8,6,5);
: }
:
: fn(int a, b, c, d, e, f, g)
: {
: register int x, y, z;
: x = a + b*c
: y = d - e / f;
: z = power(x, g);
: z = z > 0 ? z : -z;
: return x + y + z;
: }
:
:
:
[color=Blue]power(x,y) is an exponent. For example: power(5,3) is 5*5*5 = 125.

'?' is like an IF() statement in C.

This statement:
z = z > 0 ? z : -z;

Is the same as this one:
if (z > 0)
{
z = z;
}
else
{
z = -z;
}

If 'z' is positive, then do "z = z", else do "z = -z".
[/color]
• : : can someone help m
: :
: [color=Blue]power(x,y) is an exponent. For example: power(5,3) is
: 5*5*5 = 125.
:
: '?' is like an IF() statement in C.
:
: This statement:
: z = z > 0 ? z : -z;
:
: Is the same as this one:
: if (z > 0)
: {
: z = z;
: }
: else
: {
: z = -z;
: }
:
: If 'z' is positive, then do "z = z", else do "z = -z".
: [/color]
i got it all except how do u write the line "z = -z" in assembly

• : i got it all except how do u write the line "z = -z" in assembly
:
:

For the x86 there is a NEG instruction:
[code]
neg eax
[/code]
does eax = -eax

You can use relative addressing, so if you have the variable z:
[code]
neg dword [z]
[/code]

(using NASM syntax, but you should get the idea)
Best Regards,
Richard

The way I see it... Well, it's all pretty blurry