This is specifically for the NES console which uses a slightly modified 8-bit 6502 microprocessor. Below follows the code with my comments explaining what each line does as far as my basic understanding goes (please let me know if I misunderstood any lines):
lda #$00 ; Load the accumulator (A register) with the immediate value 0x00
sta $02 ; Store the value in the accumulator into memory address $02
lda #$03 ; Load the accumulator with the immediate value 0x03
sta $03 ; Store the value in the accumulator into memory address $03
lda #$14 ; Load the accumulator with the immediate value 0x14
sta $0302 ; Store the value in the accumulator into memory address $0302
clc ; Clear the carry flag (CLC instruction)
lda #$10 ; Load the accumulator with the immediate value 0x10
ldy #$02 ; Load the Y register with the immediate value 0x02
adc ($02),y
It seems like, before the final line adc ($02)
, the status of memory addresses and registers is as follows:
$02
=0x00
$03
=0x03
$0302
=0x14
A
=0x10
Y
=0x02
Therefore, the final line to me seems to indicate the following:
$02
+Y
0x00
+0x02
0x02
with the value stored at this address being0x00
- Now we add
0x00
to A register which is simply0x10
but apparently the results should be is follows, thus I am a bit confused where I made a mistake:
A=$24 X=$00 Y=$02
Some additional notes, supposedly the following is true:
The value in memory locations $02 and $03 was previously set to specify the address $0300.
When does this happen? I specifically struggle to understand this line. Are they both specified to address $0300
?
adc ($02),y
is an example of indirect indexed addressing. The parenthesis around$02
means that$02
does not contain the operand but$02
and$03
together contain a 16 bit address that, when added toy
contains the operand.This is the sequence of what happens with
adc ($02),y
$02
which is$00
.$03
which is$03
.$0300
. This is sometimes called the base addressy
to the base address to get$0302
. This new number is used as the address in which to find the operand.$0302
which is$14
and adds it to the accumulator.