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?
Doubt about STA absolute instruction
Moderator: Moderators
Re: Doubt about STA absolute instruction
6502 is little endian.
8d 00 20
STA $2000
I prefer bit shifting over multiplication.
first byte + (second byte << 8)
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
Re: Doubt about STA absolute instruction
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.
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!
https://www.patreon.com/bitinkstudios <- Support me on Patreon!