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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Unary plus, minus <strong>and</strong> absolute value<br />

Pseudocode Definition<br />

If x is an integer or real, then +x is x unchanged, -x is x with its sign reversed, <strong>and</strong> Abs(x) is the absolute value<br />

of x. All three are of the same type as x.<br />

Addition <strong>and</strong> subtraction<br />

If x <strong>and</strong> y are integers or reals, x+y <strong>and</strong> x-y are their sum <strong>and</strong> difference. Both are of type integer if x <strong>and</strong> y<br />

are both of type integer, <strong>and</strong> real otherwise.<br />

Addition <strong>and</strong> subtraction are particularly common arithmetic operations in pseudocode, <strong>and</strong> so it is also<br />

convenient to have definitions of addition <strong>and</strong> subtraction acting directly on bitstring oper<strong>and</strong>s.<br />

If x <strong>and</strong> y are bitstrings of the same length N = Len(x) = Len(y), then x+y <strong>and</strong> x-y are the least significant N<br />

bits of the results of converting them to integers <strong>and</strong> adding or subtracting them. Signed <strong>and</strong> unsigned<br />

conversions produce the same result:<br />

x+y = (SInt(x) + SInt(y))<br />

= (UInt(x) + UInt(y))<br />

x-y = (SInt(x) - SInt(y))<br />

= (UInt(x) - UInt(y))<br />

If x is a bitstring of length N <strong>and</strong> y is an integer, x+y <strong>and</strong> x-y are the bitstrings of length N defined by x+y = x<br />

+ y <strong>and</strong> x-y = x - y. Similarly, if x is an integer <strong>and</strong> y is a bitstring of length M, x+y <strong>and</strong> x-y<br />

are the bitstrings of length M defined by x+y = x + y <strong>and</strong> x-y = x - y.<br />

Comparisons<br />

If x <strong>and</strong> y are integers or reals, then x == y, x != y, x < y, x y, <strong>and</strong> x >= y are equal, not equal,<br />

less than, less than or equal, greater than, <strong>and</strong> greater than or equal comparisons between them, producing<br />

boolean results. In the case of == <strong>and</strong> !=, this extends the generic definition applying to any two values of<br />

the same type to also act between integers <strong>and</strong> reals.<br />

Multiplication<br />

If x <strong>and</strong> y are integers or reals, then x * y is the product of x <strong>and</strong> y, of type integer if both x <strong>and</strong> y are of type<br />

integer <strong>and</strong> otherwise of type real.<br />

Division <strong>and</strong> modulo<br />

If x <strong>and</strong> y are integers or reals, then x / y is the result of dividing x by y, <strong>and</strong> is always of type real.<br />

If x <strong>and</strong> y are integers, then x DIV y <strong>and</strong> x MOD y are defined by:<br />

x DIV y = RoundDown(x / y)<br />

x MOD y = x - y * (x DIV y)<br />

It is a pseudocode error to use any x / y, x MOD y, or x DIV y in any context where y can be zero.<br />

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

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

Saved successfully!

Ooh no, something went wrong!