indexed addressing modes - signed?

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
raejae
Posts: 4
Joined: 20 Sep 2008

indexed addressing modes - signed?

Post by raejae »

Hello all,

I'm looking for a piece of information that I can't seem to find anywhere, therefore must be blatantly obvious and I'm missing it.

When using indexed addressing modes, is the index interpreted as signed or unsigned? (ie if I have the address $2000 and the index in the X register is $80, will the affected address be $2080 or $1F80?

Documentation specifically mentions the offset in the relative addressing mode as being signed, but says nothing about the index in an indexed mode.

Thanks,
-Nick
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Post by 8BIT »

for 6502 and 65C02 architecture

The absolute indexed address modes are unsigned.

$2000, x where x is $90 = $2090
$20F0, x where x = $90 = $2180

The zero page indexed modes are also unsigned, but will be truncated into zero page even if the sum exceeds $FF.

$F0, x where x is $20 = $10 ($F0+$20=$110, then AND with $0FF for result)

Zero page indirect indexed will also be unsigned and truncated to zero page for the pointer value.

Daryl
Last edited by 8BIT on Sat Sep 20, 2008 10:59 pm, edited 1 time in total.
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

Quote:
Zero page indirect indexed will also be unsigned and truncated to zero page for the pointer value.
This definitely is true for the 6502.

However, the 65816 in native-mode behaves differently, if memory serves me correctly. Since direct-page can now float freely anywhere in bank 0, I believe that if X=$F0 and you access $F0,X, you will actually access location (D+$1E0) & 0xFFFF, where D is the current address stored in the direct page register.

So, for the benefit of folks reading this forum, particularly those new to the "Terbium" architecture, it would be most helpful to qualify which CPUs you're asking about.
raejae
Posts: 4
Joined: 20 Sep 2008

Post by raejae »

That's exactly what I needed--thanks!
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Post by 8BIT »

kc5tja wrote:
So, for the benefit of folks reading this forum, particularly those new to the "Terbium" architecture, it would be most helpful to qualify which CPUs you're asking about.
My original response has been corrected.
bogax
Posts: 250
Joined: 18 Nov 2003

you can fake it

Post by bogax »

Perhaps it's obvious (although, I didn't think of it) but it may be worth
noting that since subtaction is just addition you can negate your
base/index and structure your table accordingly to achieve a
similar result, as is done in the fast quarter-square multiply.
(attributed to George Taylor)
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

The other method that I've used in the past is called "bias-128." What this means is that I map zero to $80, one to $81, and negative one to $7F. You'll sometimes see this in DACs, for example.
Post Reply