CODE: SELECT ALL
CODE: SELECT ALL
LDA foobar ; Examine variable "foobar."
BEQ label1 ; If it's 0, skip the next two lines and go down to label1.
<do_stuff> ; These two lines will get executed only if "foobar" was not 0.
label1: <continue_here> ; This part gets executed regardless.
label2: LDA array1,X
(Tokumaru mentioned indexing earlier.) In this case, it copies eight bytes from array1 to array2. The first byte of each array is the array's base address plus 0, and the last byte is array plus 7. However we can start at the end instead of the beginning, and go backwards to take advantage of the automatic compare-to-0 built into DEX to decide whether to branch back up to the top of the loop for another go-around. It will execute for X=7, then 6, [...] and finally 0; but after the DEX DEcrements X from 0 to $FF, the N flag will be set, so BPL will drop through to the next instruction instead of branching back up to the top of the loop. There was no need for a CPX #0 instruction.
I don't understand at first sight.
LDA foobar - Load number into A Register from "foobar" label.
BEQ label1 - If Zero Flag is on, go to "label1".
[ ANY CODE ]
[ ANY CODE ]
label1: [ ANY CODE]
LDX #7 - Load number 7 into X Register.
LDA array1, X - Load numbers from "array1" label to Register A, and copy the "array1" number into Register X.
DEX - Decrement X Register
BPL label2 - If destination reached here while the Negative Flag is off, go to "label2"
You need to go through a programming manual. There are quite a few good ones.
I think the best may be Programming the 65816-Including the 6502, 65C02 and 65802, by David Eyes and Ron Lichty. It has a thorough tutorial, writing applications, then very detailed and diagrammed information on all the addressing modes, at least a page of very detailed description for each instruction, with info on every addressing mode available for that instruction, then instruction lists, tables, and groups, of all the op codes, plus more. It will tell you exactly how every single instruction affects or uses the flags, and a lot more too, as you wold expect from a well laid-out 469-page book.
"Programming the 6502" by Rodnay Zaks has a good reputation if you only intend to stay with the NMOS 6502 instruction set (which is what the NES uses). Another ones is "6502 Assembly Language Programming" by Lance A. Leventhal.
I have the book by David Eyes and Ron Lichty. But I don't have Rodnay Zaks nor Lance A. Leventhal version.
Sadly, I also do not understand or read well with the books from it either. So I'm going to try pick something from Chapter 2 and read it:
The 6502 registers are:
· The accumulator, or A register, is the primary user register and generally holds one of the operands, as well
as the result, of any of the basic data-manipulation instructions.
· The X and Y index registers are used chiefly in forming effective addresses for memory accesses and as loop
· The processor status, or P, register contains bit-fields to indicate various conditions, modes, and results
within the processor.
· The stack pointer, or S register, is a pointer to the next available location on the system stack, a special area
of memory for temporary data storage. In addition to being available to the user, the stack pointer and stack
are also used automatically every time a subroutine is called or an interrupt occurs to store return information.
· Finally, the program counter, or PC, is a pointer to the memory location of the instruction to be executed
I don't know if Processor status is used in NES, and program counter in NES. But I do know Stack Pointer is in NES in anyway. So it's a Temporary Data Storage, and the way to use it is...???