ARM bit field extract?

瘦欲@ 提交于 2019-11-30 18:32:16

问题


Can someone explain what this instruction does and translate it to C?

ubfx.w          r3, r11, #0xE, #1

According to the ARM reference manual, it does a "signed and unsigned bit field extract" but I'm not good with all that bitwise stuff.


回答1:


UBFX just extracts a bitfield from the source register and puts it in the least significant bits of the destination register.

The general form is:

UBFX dest, src, lsb, width

which in C would be:

dest = (src >> lsb) & ((1 << width) - 1);

The C equivalent of the example you give would be:

r3 = (r11 >> 14) & 1;

i.e. r3 will be 1 if bit 14 of r11 is set, otherwise it will be 0.

See: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489c/Cjahjhee.html



来源:https://stackoverflow.com/questions/8366625/arm-bit-field-extract

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!