Zero page indirect addressing question

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
petej
Posts: 7
Joined: 18 Oct 2004

Zero page indirect addressing question

Post by petej »

Please can you explain how the following 65C02 opcode works:

Code: Select all

LDA ($FF)
My understanding is that the effective address (EA) low-byte will come from $00FF and the EA high-byte from $0000. All the software simulators I've tested indicate that the EA high-byte comes from $0100. Are the simulators wrong?
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Post by 8BIT »

Pete,

I looked into the WDC tech notes and the W65C02 should read from $00FF if I understand it correctly. I'll test it on my actual SBC tonight if I have time.

I checked the code to my 65c02 Simulator and I have it set to read from $0100! Oops. If the actual processor reads from $00FF, I'll update my Simulator accordingly.

I also have an older 65c02 made by VLI, I'll try it too if there's time.

Daryl
leeeeee
In Memoriam
Posts: 347
Joined: 30 Aug 2002
Location: UK
Contact:

Re: Zero page indirect addressing question

Post by leeeeee »

Quote:
All the software simulators I've tested indicate that the EA high-byte comes from $0100. Are the simulators wrong?
Michal Kowalski's 6502 simulator gets the high byte from $0000

http://home.pacbell.net/michal_k/6502.html

Lee.
petej
Posts: 7
Joined: 18 Oct 2004

Re: Zero page indirect addressing question

Post by petej »

Quote:
Michal Kowalski's 6502 simulator gets the high byte from $0000
It looks like it does when you watch the 'Arg' field in the 'uP Registers and Stack' window. However, have a look at the value of the accumulator after the operation is performed.

Here's my test code:

Code: Select all

	.ORG	$00
	.DB	$20
	.ORG	$ff
	.DB	$30
	.ORG	$2030
	.DB	$05
	
	.ORG	$F000
	.START	main
main:	LDA	($FF)
	NOP
	NOP
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Post by 8BIT »

As expected, my W65C02 pulled the high address byte from zero page $00, not $0100. I'll have to go and update the code on my simulator. Its a simple one-line edit, so will not be hard.

Thanks for pointing it out!

Daryl
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

8BIT wrote:
As expected, my W65C02 pulled the high address byte from zero page $00, not $0100. I'll have to go and update the code on my simulator. Its a simple one-line edit, so will not be hard.

Thanks for pointing it out!

Daryl
I seem to recall that the 65C02/65C816 programming book I have (from WDC) in storage stated that this kind of page wrap-around was a bug, and that it has been "fixed". That is to say, that reading from $00FF/$0100 is "correct."

Can anyone confirm this verbiage? Otherwise, I'll have to spend a whole day to get my book out from storage.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

If Daryl's WDC 65c02 pulled the high byte from 0000 in his experiment, I'd say it wasn't changed. It is my understanding that it was an intentional part of the design to improve performance and keep the die size smaller by leaving the high address byte alone instead of looking to see if another clock would be necessary to increment it after incrementing the low byte. Since less than 0.4% of possible ZP starting locations would result in this incrementing, it makes sense.
User avatar
dclxvi
Posts: 362
Joined: 11 Mar 2004

Post by dclxvi »

I tested this on a GTE 65C02 and a GTE 65C816. LDA ($FF) uses $FF and $00 on the 65C02. With the memory contents:

$0000 $00
$00FF $00
$0100 $01

LDA ($FF) puts $00 in the accumulator.

When e=1 (emulation mode), LDA ($FF) uses $FF and $00, just like the 65C02. When e=0 (native mode), LDA ($FF) uses $00FF and $0100. When e=0 and m=1, with the above memory contents, LDA ($FF) puts $01 in the accumulator. When e=0 and m=0, with the following memory contents:

$0000 $00
$0001 $FF
$00FF $00
$0100 $01
$0101 $FE

LDA ($FF) puts $FE01 in the accumulator. (D, the direct register, was $0000 for these tests.)
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Post by 8BIT »

8BIT wrote:
As expected, my W65C02 pulled the high address byte from zero page $00, not $0100. I'll have to go and update the code on my simulator. Its a simple one-line edit, so will not be hard.

Thanks for pointing it out!

Daryl
I've fixed my simulator code to correctly use $0000 for the high byte in the Indirect Zero Page addressing mode. This change was made to version 2.1 and is available from my web site.

Daryl

http://users.softcom.net/darylr
Post Reply