Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

6502 Indirect acces mode

Tags:

6502

My question is about the 6502 Assembly language. I'm trying to learn it using this website https://skilldrick.github.io/easy6502/.

On the topic of addressing modes. I don't understand the indirect addressing mode. See the source code example below.

LDA #$01
STA $f0
LDA #$cc
STA $f1
JMP ($00f0) ;dereferences to $cc01

Why is the JMP ($00f0) dereferenced to $cc01 instead of $01cc.

My memory looks like this

00f0: 01 cc 00 00 00 00 00 00 00 00 00 00 00 00 84

Here you see 00f0 starts with 01 and then followed by cc so it looks more logical to me that the jump instruction would dereference to $01cc, but why is this somehow reversed?

like image 947
DB93 Avatar asked Dec 24 '22 12:12

DB93


1 Answers

6502 is little endian. That means for 16 bit values, which take two bytes, the lowest byte is stored at the lowest address. After the two STAs, you have:

00f0: 01 
00f1: cc

The JMP instruction loads the byte at f0 into the low byte of the destination address and the byte at f1 into the high byte of the destination address meaning you jump to cc01.

like image 187
JeremyP Avatar answered Mar 15 '23 12:03

JeremyP