Re: Decreasing order of address within main
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 25 Sep 2009 14:01:54 -0700
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"
.
- Follow-Ups:
- Re: Decreasing order of address within main
- From: Nobody
- Re: Decreasing order of address within main
- References:
- Re: Decreasing order of address within main
- From: Dik T. Winter
- Re: Decreasing order of address within main
- From: Kenneth Brody
- Re: Decreasing order of address within main
- From: Keith Thompson
- Re: Decreasing order of address within main
- From: Dik T. Winter
- Re: Decreasing order of address within main
- From: Nobody
- Re: Decreasing order of address within main
- Prev by Date: [OT] Re: Plz explain me the following code
- Next by Date: Re: Plz explain me the following code
- Previous by thread: Re: Decreasing order of address within main
- Next by thread: Re: Decreasing order of address within main
- Index(es):
Relevant Pages
|