インラインアセンブリ:ポインターを関数に渡し、アセンブリのその関数でそれを使用する

StackOverflow https://stackoverflow.com/questions/3678452

質問

私は使用しています ARM/Cortex-A8プロセッサ プラットホーム。

2つのポインターを関数に渡す必要がある単純な関数があります。これらのポインターは、私のインラインアセンブリコードのみを備えたその関数で後に使用されます。この計画はパフォーマンスを達成するためだけです。

function(unsigned char *input, unsigned char *output)
{
     // What are the assembly instructions to use these two pointers here?
     // I will inline the assembly instructions here
}

main()
{
    unsigned char input[1000], output[1000];

    function(input, output);
}

ありがとう

役に立ちましたか?

解決

通常のアームABIを使用していると仮定すると、これらの2つのパラメーターが渡されます R0R1. 。以下は、からバイトをコピーする方法を示す簡単な例です。 input バッファーへ output バッファー(GCC構文):

.text
.globl _function

_function:
   mov  r2, #0        // initialize loop counter
loop:
   ldrb r3, [r0, r2]  // load r3 with input[r2]
   strb r3, [r1, r2]  // store r3 to output[r2]
   add  r2, r2, #1    // increment loop counter
   cmp  r2, #1000     // test loop counter
   bne  loop
   mov  pc, lr
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top