Re: Decreasing order of address within main



Nobody <nobody@xxxxxxxxxxx> writes:
On Fri, 25 Sep 2009 12:40:01 +0000, Dik T. Winter wrote:
In article <ln4oqs1gf8.fsf@xxxxxxxxxxxxxxx> Keith Thompson
<kst-u@xxxxxxx> writes: ...
> Imagine a system where addresses are treated as signed. You could
> even have an object covering a range of addresses from, say, -10
> to +10. (A null pointer would have to have a representation other
> than all-bits-zero.)

Isn't the ARM a machine where some addresses were thought to be negative?

At the CPU level, data is neither signed nor unsigned. It's typically the
operations which treat their operands as signed or unsigned.

With two's complement, addition, subtraction and multiplication (but not
division) behave identically for signed or unsigned values. The main
difference is in comparisons.

A signed comparison subtracts two values then checks whether the overlow
flag is set, while an unsigned comparison would check the carry flag
instead.

Apart from division, the only common instruction which has signed and
unsigned variants is a right shift. An arithmetic (signed) right shift
duplicates the topmost bit (i.e. the sign bit) while a logical (unsigned)
shift fills with zeros.

Ok, but the issue is addresses.

Suppose a machine has, say, an auto-increment addressing mode (an
idea that goes back at least to the PDP-11), which is useful for
stepping through arrays. Thus something like:

*ptr++ = 0;

might be a single instruction. Assuming for concreteness and
simplicitly that addresses are 16 bits, what happens on the machine
level when ptr==0x7FFF?? What happens when ptr==0xFFFF? Can a
single object cover a range of addresses that includes 0x7FFF and
0x8000? What about 0xFFFF and 0x0000 (or, equivalently, -1 and 0)?
What instructions are used to compare addresses?

I don't know the answers to any of those questions for any specific
architecture, but certain sets of answers would imply that addresses
are signed, and certain other sets of answers would imply that
they're unsigned.

And yet other sets of answers might imply that the answer is
indeterminate; either signed or unsigned comparison could work
equally well if no object can span certain address boundaries.

This is approaching the edge of clc topicality, if it hasn't
already crossed it.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Arithmetic shift right
    ... Command LSR (Logical Shift Right) shifts all the bits by one to the ... This instruction is called ... The most significant bit becomes the value of the Carry Flag. ...
    (alt.lang.asm)
  • Re: Arithmetic shift right
    ... Command LSR (Logical Shift Right) shifts all the bits by one to the ... This instruction is called ... The most significant bit becomes the value of the Carry Flag. ... is nor arithmetic interpretation for this type of shift. ...
    (alt.lang.asm)
  • Re: typdefing from sig_atomic_t valid?
    ... One either uses a single instruction that is read-modify-write ... uninterruptable instruction, there is no meaning to, or protection ... Client task reads sig_atomic_t flag and starts to clear that flag. ...
    (comp.lang.c)
  • Re: [PATCH 1/2] fb: add support for foreign endianness
    ... This is done via FBINFO_FOREIGN_ENDIAN flag that will ... Depending on the host endianness this flag ... int left, right; ... if (!shift) { ...
    (Linux-Kernel)
  • Re: [PATCH 1/2] fb: add support for foreign endianness
    ... This is done via FBINFO_FOREIGN_ENDIAN flag that will ... Depending on the host endianness this flag ... int left, right; ... if (!shift) { ...
    (Linux-Kernel)