Hello,
I came across these two inline assembly functions below that are not being compiled with the online compiler. Hence I tried to rewrite them as an s-File following this Cookbook answer.
But I am not quite experienced with assembly and sure about how to pass the parameters and if the result is returned correctly.
I'd appreciate it, if someone could have a look at it :)
Thank you very much in advance,
Moritz
Edit: Sorry, I just saw, that this question fits maybe better to the "Hello World!"-forum?!
static __inline__ int MULSHIFT32(int x, int y)
{
int zlow;
__asm__ volatile ("smull %0,%1,%2,%3" : "=&r" (zlow), "=r" (y) : "r" (x), "1" (y) : "cc");
return y;
}
AREA asm_func, CODE, READONLY
; Export my_asm function location so that C compiler can find it and link
EXPORT MULSHIFT32
MULSHIFT32
;
; ARM Assembly language function to describe the following inline assembly function:
;
; function call: extern "C" static int MULSHIFT32(int x, int y);
; --> R0 = x; R1 = y;
; smull RdLo, RdHi, Rn, Rm [:= RdHi, RdLo = Rn * Rm]
; return RdHi
;
; calculate Signed MULtiply Long
SMULL R1, R0, R0, R1
; Return to C using link register (Branch and change instruction set)
BX LR
END
typedef union _U64
{
long long w64;
struct{
unsigned int lo32;
signed int hi32;
} r;
} U64;
static __inline long long MADD64(long long sum64, int x, int y)
{
U64 u;
u.w64 = sum64;
__asm__ volatile ("smlal %0,%1,%2,%3" : "+&r" (u.r.lo32), "+&r" (u.r.hi32) : "r" (x), "r" (y) : "cc");
return u.w64;
}
AREA asm_func, CODE, READONLY
; Export my_asm function location so that C compiler can find it and link
EXPORT MADD64
MADD64
;
; ARM Assembly language function to describe the following inline assembly function:
;
; function call: extern "C" static long long MADD64(long long sum64, int x, int y)
; --> R0, R1 = sum64 (R0 = lo32, R1 = hi32); R2 = x, R3 = y;
; smlal RdLo, RdHi, Rn, Rm [:= RdHi,RdLo = signed(RdHi,RdLo + Rm * Rs)]
; return RdLo, RdHi
;
; calculate Signed MuLtiply and Accumulate Long
SMLAL R0, R1, R2, R3
; Return to C using link register (Branch and change instruction set)
BX LR
END
Hello,
I came across these two inline assembly functions below that are not being compiled with the online compiler. Hence I tried to rewrite them as an s-File following this Cookbook answer.
But I am not quite experienced with assembly and sure about how to pass the parameters and if the result is returned correctly.
I'd appreciate it, if someone could have a look at it :)
Thank you very much in advance,
Moritz
Edit: Sorry, I just saw, that this question fits maybe better to the "Hello World!"-forum?!