FOR - NEXT question

vk6bgn

New Member
Hello All,

My 18X chip program uses the following code below many times through out the program. I'm wondering if I could some how use a For - Next loop to tidy this up and save a bit of code space. The contents of Eeprom 101 must go into B0, 102 must go into B1 etc. etc.

As an example, what happens if I needed to READ 12 consecutive Eeprom locations into B1 – B12. Certainly it can be done with out READing 12 separate times! But using one READ statement and looping and incrementing everything 12 times? And wouldn’t that save some code space too?

Here it is:

Read 101, B0
Read 102, B1
Read 103, B2
Read 104, B3
Read 105, B4
Read 106, B5

For b7 = 101 TO 106
Read b7, (B?)

How do I increment the variables B0 to B5? Or is it not possible?

I’m sure there is a simple solution, but I can’t seem to figure it out. Thanks.
 

mholguin

New Member
You can also put the repeatable code within a GOSUB .... RETURN so whenever you need the code eecuted, you just issue a

GOSUB My-subroutine

Marino
 

MBrej

Member
Hi,

This should work and only uses one line:

Code:
read 101, b0,b1,b2,b3,b4,b5
EDIT - I know its not increasing the variable like you wanted, but im not sure thats possible, (perhaps unless you poke the memory location where b0-b13 are actually stored, using a increasing pointer to select the B ? register)

Matt
 
Last edited:
Top