التجميع المضمّن: تمرير مؤشرات إلى وظيفة واستخدامها في هذه الوظيفة في التجميع

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

سؤال

أنا استخدم معالج ARM/Cortex-A8 برنامج.

لديّ وظيفة بسيطة حيث يجب أن أقوم بتمرير مؤشرين إلى وظيفة. يتم استخدام هذه المؤشرات لاحقًا في هذه الوظيفة التي تحتوي فقط على رمز التجميع المضمّن الخاص بي ، هذه الخطة هي فقط لتحقيق الأداء.

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 العادي ، سيتم تمرير هاتين المعلمتين R0 و R1. فيما يلي مثال سريع يوضح كيفية نسخ البايتات من 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