I worked it out thanks to the site search function and the GCC docs.
Here's an example for anyone looking to get started, it's fairly easy once you get past the wierd syntax(To me it's wierd anyway)
Code: Select all
void AddTest()
{
int num1=5;
int num2=10;
int out=0;
asm __volatile__ ("\n\
mult %0,%1,%2\n\
":"=r"(out):"r"(num1),"r"(num2));
printf("Result:%d \n",out);
}
basically "=r" means the variable you specify next will be used as the output. "r" on it's own means the variable is an input. you then use %1/%2 etc to access the register (Which is indetermined) the varible was loaded into. and you direct your output to %0 to output a register/op into the variable.
Not sure if you can handle multiple outputs, I would expect so though.
One thing i'm not sure of though, is how do you directly access a register, is it similar asm like $0 for the all zero register, utpo $30 or can you use the mnemonic names? if so, do I have to format it in any special way?
----
Edit - Can anyone see why this returns the right value, 50 in output 1, yet returns 250 in output 2?
Code: Select all
void AddTest()
{
int num1=5;
int num2=10;
int out=0;
int out2=0;
asm __volatile__ ("\n\
mult %0,%2,%3\n\
mult %1,%2,%3\n\
":"=r"(out),"=r"(out2):"r"(num1),"r"(num2));
printf("R1:%d R2:%d \n",out,out2);
}
edit - hmm, even this code results in an output of 250 of a, and out2 which is not even passed is now 5. Why is altering other variables and multiplying in on it's self?
Any ideas why?
void AddTest()
{
int num1=5;
int num2=10;
int out=0;
int out2=0;
asm __volatile__ ("\n\
mult %0,%1,%2\n\
mult %0,%1,%2\n\
":"=r"(out):"r"(num1),"r"(num2));
printf("R1:%d R2:%d \n",out,out2);
}