在汇编

时间:2016-10-26 07:04:57

标签: assembly arm

写一个ARM函数(子程序)来计算整数数组中奇数的整数。功能签名是:

int numodd( int array[], int size ) ;

其中:     int array []作为指向整数数组的第一个元素的指针传递给ARM函数,     int size按值传递,是数组中元素的数量。

C语言源代码是:

#include <stdlib.h>
#include <stdio.h>

extern int numodd( int array[], int size ) ;

int main( int argc, char * argv[] )
{
    int numarray[] = { 2, 3, 1025, 3024, 4057, -3, -1025, -3578 } ;
    int size = sizeof(numarray) / sizeof( int ) ;
    int result ;

    result = numodd( numarray, size ) ;
    printf( "Number of odd numbers: %d\n", result ) ;

    exit( 0 ) ;

}

汇编代码(到目前为止):

        .global numodd
        .text
numodd: stmfd sp!,{v1-v6,lr}
        mov a3, #0
elop:   ldr a4, [a1], #4
        tst a4, #1
        beq odd
        subs a2, a2, #1
        bne elop
odd:    add a3, a3, #1
        bne elop
        mov a1, a3
        ldmfd sp!,{v1-v6,pc}
        .end

2 个答案:

答案 0 :(得分:3)

我不确定您是否忘记了额外的subs,或者您是否认为ARM有分支延迟时段,但您只是在&#34中递减a2 ;甚至&#34;情况下。

请注意,beq odd是不必要的,因为您可以使用条件执行,这样会更有效:

    tst a4, #1
    addne a3, a3, #1      @ if (a4 & 1) a3++ 
    subs a2, a2, #1
    bne elop
    mov a1, a3
    ldmfd sp!,{v1-v6,pc}

答案 1 :(得分:0)

供将来参考使用ARMv8宏来灌注泵。

// Local Media Stream, just as example for this question
// Local stream of current User B
MediaStream mediaStream = new MediaStream(...);

PeerConnection peerA = new PeerConnection(...);
PeerConnection peerC = new PeerConnection(...);

peerA.addStream(mediaStream);
peerB.addStream(mediaStream);

// Now this User (User B) can here User A and B
// Connection successful establish. 

// Here is question, how I can fetch remote 
// MediaStream object from PeerConnection A?