I'm trying to recreate the following piece of arm disassembly in c++:
00003188 ed910a06 flds s0, [r1, #24]
0000318c edd10a07 flds s1, [r1, #28]
00003190 ec800a02 fstmias r0, {s0-s1}
00003194 4770 bx lr
00003196 bf00 nop
Firstly, is s0 a single precession register? And what do 开发者_JAVA百科flsl and fstmias do. I tried the following code but it doesn't produce the same result:
float s0 = r1[6];
float s1 = r1[7];
What's wrong with what I tried?
Since it's a very trivial function, let's take it line by line. I am going to assume that you posted the complete function.
00003188 ed910a06 flds s0, [r1, #24]
The FLDS
is on this form: "FLD<precision>{cond} Fd, [Rn{, #offset}]", with precision as s (=single precision). As the documentation states this loads a single precision floating value located at r1 + 24
into s0
.
0000318c edd10a07 flds s1, [r1, #28]
And another load, this time from r1 + 28
(this corresponds to what you write with r1[7]
).
00003190 ec800a02 fstmias r0, {s0-s1}
FSTMIAS
lists "FSTM<addressmode><precision>{cond} Rn,{!} VFPregisters". Here you have addressmode = IA, which means "Increment address After each transfer" and precision = single . This instruction stores the specified registers to the address specified in r0
Incrementing the address after each store. In other words it stores s0
at [r0]
and s1
at [r0+4]
.
00003194 4770 bx lr
BX is branch (and optionally change back to ARM mode) to register value - the preferred way of returning from functions (see section 5.1 here). In this case the register is the link register which holds the return address.
00003196 bf00 nop
No OPeration. Does nothing, Usually inserted to align functions in memory.
The calling convention for ARM-THUMB (section 4.1) states that the first four arguments are passed in r0-r3 (== a1-a4) and we can see from the disassembly that r0 and r1 are used so the function takes 2 parameters. It is unclear whether the function returns a value (the same as the first input) or doesn't return a value. You will have to look at call sites to figure this out.
In C parlance we have a function that takes two pointer values as input, loads two float
s from offsets 24 and 28 from the second parameter and stores them at offsets 0 and 4 in the first. Without further knowledge of the program it is impossible to tell if the parameters are supposed to be arrays, structures or something else.
Assuming they are arrays a translation to C is trivial:
void mystery_function(float* dst, const float* src) {
dst[0] = src[6];
dst[1] = src[7];
}
精彩评论