# inline assembly in ARM

## Recommended Posts

cebugdev    635
guys can someone show me how to do inline assembly in arm that communicates back the result back to the application for example;
int multiply( int x,int y )
{
int result=0;
_asm(....); //i d0nt knw how to do this operation in asm

return result;
}
[/source ]
can you guys show me on how to add,sub,mult and div in arm assembly?



##### Share on other sites
dave    2187
Hey bud,

I did ARM assembler at uni for a bit, but i can't remember much of it. However i did manage to find this seemingly excellent PDF of the language, including an instruction set.

Hope it helps,

Dave

##### Share on other sites
Guest Anonymous Poster
If (as I suspect) you're asking in relation to implementing a fixed-point math library, you shouldn't need to do this. Here's a straightforward implementation of s15.16 fixed point:

#define fxsub(a,b) ((a)-(b))
#define fxmul(a,b) ((int)((long long)(a)*(b)>>16))
#define fxdiv(a,b) ...
#define fxsqrt(a,b) ...

If you're using a halfway decent optimizing compiler, the above will give you decent results (really - the mul solution surprised me greatly when I ran across it, but it actually compiles through to the expected "smull .../ lsr #16/etc)). fxdiv and fxsqrt are actually functions, because ARM doesn't supply a div or sqrt instruction. Implement them entirely in C or assembly or a mixture as it suits you. Try Google for that, there are a number of ARM-specific treatments for both of those problems just sitting out there.

And as mentioned above and elsewhere, you really need to understand the problem you're trying to solve before slapping someone else's solution on it. Fixed-point math doesn't replace floating-point math; it provides a significantly less flexible and more range-limited (though much faster) approximation of R.