Page 1 of 1

Running Loops

Posted: Thu Jul 27, 2006 2:28 am
by nineTENdo
Hello Everyone,
This is my first of many posts so hopefully i hope no one gets tierd of me. Ok now that thats over with, On With the Show!!
I have a Few questions about running loops.

1. When an index register has finshed its loop and goes on the next instruction, does the that index register ,pardon my french ," stay closed" when it branches back to continue the loop?

2. Do you have to clear out the index register everytime you want to load a new value, how long will the value stay in the register?

3. Up to how much data or routines can the accumulator contain at any given time?

Re: Running Loops

Posted: Thu Jul 27, 2006 4:40 am
by 8BIT
nineTENdo wrote:
1. When an index register has finshed its loop and goes on the next instruction, does the that index register ,pardon my french ," stay closed" when it branches back to continue the loop?
I'm not sure I understand your question, but hopefully this will help.

Code: Select all

Init    LDX  #$FF       ; initialize the index register to 255
Loop    LDA  $C000,X    ;  load some data values in Accum.
         ...
         ...     manipulate the data             
        DEX               ; dec index register
        BNE  Loop      ; if index <> 0, then do the loop again.
        ...      post loop code starts here
The value of x will remain unchanged during the execution of the loop as long as the "manipulate the data" code does not alter it. The DEX will decrement its value by one on each pass through the loop.
Quote:
2. Do you have to clear out the index register everytime you want to load a new value, how long will the value stay in the register?
No, you can just load the index with the new value. The old value will be discarded. the value will stay there indefinitely as long as you don't use opcodes that modify it.
Quote:
3. Up to how much data or routines can the accumulator contain at any given time?
The accumulator is a single 8 bit register. It can hold only one data byte at a time. IF you wish to hold many values at once, you can either use zero-page addressing mode variables, absolute addressing mode variables, or use the stack to push and pop values. The best choice depends on your specific application.

Daryl

Posted: Tue Aug 01, 2006 1:31 pm
by blargg
The point is that the 6502 doesn't work at the higher level of loops and structures. You get the nuts and bolts and have to construct these yourself. The index registers can be loaded with a new value, incremented/decremented, tested, etc. Each operation is minimal and self-contained.