Sign in to follow this  

inline assembly in ARM

Recommended Posts

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 this post

Link to post
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 fxadd(a,b) ((a)+(b))
#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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this