05.02.2013 Views

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ARM</strong> Instruction Set Encoding<br />

Carry out<br />

A logical instruction with rotation == 0b0000 does not affect APSR.C. Otherwise, a logical instruction that<br />

sets the flags sets APSR.C to the value of bit [31] of the modified immediate constant.<br />

Constants with multiple encodings<br />

Some constant values have multiple possible encodings. In this case, a UAL assembler must select the<br />

encoding with the lowest unsigned value of the rotation field. This is the encoding that appears first in<br />

Table A5-6 on page A5-9. For example, the constant #3 must be encoded with (rotation, abcdefgh) ==<br />

(0b0000, 0b00000011), not (0b0001, 0b00001100), (0b0010, 0b00110000), or (0b0011, 0b11000000).<br />

In particular, this means that all constants in the range 0-255 are encoded with rotation == 0b0000, <strong>and</strong><br />

permitted constants outside that range are encoded with rotation != 0b0000. A flag-setting logical instruction<br />

with a modified immediate constant therefore leaves APSR.C unchanged if the constant is in the range 0-255<br />

<strong>and</strong> sets it to the most significant bit of the constant otherwise. This matches the behavior of Thumb<br />

modified immediate constants for all constants that are permitted in both the <strong>ARM</strong> <strong>and</strong> Thumb instruction<br />

sets.<br />

An alternative syntax is available for a modified immediate constant that permits the programmer to specify<br />

the encoding directly. In this syntax, # is instead written as #,#, where:<br />

is the numeric value of abcdefgh, in the range 0-255<br />

is twice the numeric value of rotation, an even number in the range 0-30.<br />

This syntax permits all <strong>ARM</strong> data-processing instructions with modified immediate constants to be<br />

disassembled to assembler syntax that will assemble to the original instruction.<br />

This syntax also makes it possible to write variants of some flag-setting logical instructions that have<br />

different effects on APSR.C to those obtained with the normal # syntax. For example,<br />

ANDS R1,R2,#12,#2 has the same behavior as ANDS R1,R2,#3 except that it sets APSR.C to 0 instead of leaving<br />

it unchanged. Such variants of flag-setting logical instructions do not have equivalents in the Thumb<br />

instruction set, <strong>and</strong> their use is deprecated.<br />

Operation<br />

// <strong>ARM</strong>Exp<strong>and</strong>Imm()<br />

// ==============<br />

bits(32) <strong>ARM</strong>Exp<strong>and</strong>Imm(bits(12) imm12)<br />

// APSR.C argument to following function call does not affect the imm32 result.<br />

(imm32, -) = <strong>ARM</strong>Exp<strong>and</strong>Imm_C(imm12, APSR.C);<br />

return imm32;<br />

// <strong>ARM</strong>Exp<strong>and</strong>Imm_C()<br />

// ================<br />

(bits(32), bit) <strong>ARM</strong>Exp<strong>and</strong>Imm_C(bits(12) imm12, bit carry_in)<br />

A5-10 Copyright © 1996-1998, 2000, 2004-2008 <strong>ARM</strong> Limited. All rights reserved. <strong>ARM</strong> DDI 0406B

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!