Fastest way to count number of 1s in a register, ARM assembly

后端 未结 6 1780
不思量自难忘°
不思量自难忘° 2020-12-05 11:44

So I had an interview question before regarding bit manipulation. The company is a well known GPU company. I had very little background in assembly language (weird despite b

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 12:03

        LDR r0, = 0x000000FF;
        MOV r1, #0;
        MOV r3, #0; this will always be zero
        MOV r2,r0;
    rep MOVS r2, r2, LSR #1;
        ADC r1,r1, r3;  this adds r1 with zero plus the carry bit
        CMP r2, #0;
        BNE rep
    

    This will do it, r3 is just a dummy register with 0 to make ADC work properly.

提交回复
热议问题