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.

Pseudocode Definition<br />

If x is a bitstring <strong>and</strong> i is an integer, then SignExtend(x,i) is x extended to a length of i bits, by adding<br />

sufficient copies of its leftmost bit to its left. That is, if i == Len(x), then SignExtend(x,i) = x, <strong>and</strong> if i ><br />

Len(x), then:<br />

SignExtend(x,i) = Replicate(TopBit(x), i-Len(x)) : x<br />

It is a pseudocode error to use either ZeroExtend(x,i) or SignExtend(x,i) in a context where it is possible<br />

that i < Len(x).<br />

Converting bitstrings to integers<br />

If x is a bitstring, SInt(x) is the integer whose two’s complement representation is x:<br />

// SInt()<br />

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

integer SInt(bits(N) x)<br />

result = 0;<br />

for i = 0 to N-1<br />

if x == ‘1’ then result = result + 2^i;<br />

if x == ‘1’ then result = result - 2^N;<br />

return result;<br />

UInt(x) is the integer whose unsigned representation is x:<br />

// UInt()<br />

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

integer UInt(bits(N) x)<br />

result = 0;<br />

for i = 0 to N-1<br />

if x == ‘1’ then result = result + 2^i;<br />

return result;<br />

Int(x, unsigned) returns either SInt(x) or UInt(x) depending on the value of its second argument:<br />

// Int()<br />

// =====<br />

integer Int(bits(N) x, boolean unsigned)<br />

result = if unsigned then UInt(x) else SInt(x);<br />

return result;<br />

I.5.4 Arithmetic<br />

Most pseudocode arithmetic is performed on integer or real values, with oper<strong>and</strong>s being obtained by<br />

conversions from bitstrings <strong>and</strong> results converted back to bitstrings afterwards. As these data types are the<br />

unbounded mathematical types, no issues arise about overflow or similar errors.<br />

AppxI-14 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!