Doubt about STA absolute instruction

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
colt
Posts: 13
Joined: Sat Nov 02, 2019 2:53 pm

Doubt about STA absolute instruction

Post by colt »

Hello. From what I understood when I see one of these, it means that the next two bytes following it will be the address in which the data will be written in memory. However, since they occupy two bytes and not a single, how I determine the address? I mean how they merge together? I mean I found a STA absolute instruction, and the byte following it is "00" and the one after it is "20". How they shall be concatenated? And how I use it to access the memory. I mean, assuming the memory is a char array, I use this somehow concatenated address converted into a int value to access the array ?

Thanks for any explanation.


EDITED: Would be to pick the first value and add it to the a multiplied version of the second byte (by 256) a correct procedure?
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Doubt about STA absolute instruction

Post by dougeff »

6502 is little endian.
8d 00 20

STA $2000

I prefer bit shifting over multiplication.

first byte + (second byte << 8)
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
nesrocks
Posts: 563
Joined: Thu Aug 13, 2015 4:40 pm
Location: Rio de Janeiro - Brazil
Contact:

Re: Doubt about STA absolute instruction

Post by nesrocks »

Also, obviously, you can differentiate which addressing mode the STA uses because each variation uses a different opcode. Sometimes STA uses only 1 following byte, for example on opcode $85.

85 00 20 is STA $00. and 20 is part of the next instruction, so a JSR.
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!
https://www.patreon.com/bitinkstudios <- Support me on Patreon!
Post Reply