indexing through variables in asm question
I have a bunch of things I am doing for each output on my I2C bus per channel.
This is a small example
how would I use djnz and an index to get the variables in order?
This is a small example
I2Coutput
cmp setting1, #1 wz
if_z mov sin, out1
if_z call #HalfSin
if_z mov out1, sin
cmp setting2, #1 wz
if_z mov sin, out2
if_z call #HalfSin
if_z mov out2, sin
jmp #I2Coutput
sin long 0
setting1 long 0
setting2 long 0
out1 long 0
out2 long 0
how would I use djnz and an index to get the variables in order?

Comments
movd theCmp, #setting1 ' initialize addresses movs theMov1, #out1 movd theMov2, #out1 mov count, #3 ' loop count theCmp cmp setting1, #1 wz theMov1 if_z mov sin, out1 if_z call #HalfSin theMov2 if_z mov out1, sin add theCmp, dest1 ' increment destination add theMov1, #1 add theMov2, dest1 djnz count, #theCmp dest1 long 1 << 9I am currently at 328 longs on just this asm code so I want to make some subs to save memory.
' basepntr = address of array/table ' idx = index of element to read ' value = value that is read read mov tmp1, basepntr add tmp1, idx movs rdval, tmp1 nop rdval mov value, 0-0 read_ret retYou could do something like this:
sendvalues mov basepntr, #out1 ' start of values mov idx, #0 ' start with first :loop call read ' get a value ' do something with value add idx, #1 ' update index cmp idx, #8 wz, wc ' done? if_b jmp #:loop' basepntr = address of array/table ' idx = index of element to write ' value = value to write write mov tmp1, basepntr add tmp1, idx movd wrval, tmp1 nop wrval mov 0-0, value write_ret retIn PASM code is data. Not only does code occupy the same RAM as "local variables", but there are instructions specifically for changing the source and destination registers (MOVS & MOVD). It is also possible to use ALU operations (i.e. ADD, SUB) on instructions to change the source and destination registers. Heck, just look at how JMPRET (the real instruction used for CALL & RET) works under the covers.
write mov tmp1, basepntr1 mov tmp2, basepntr2 mov tmp3, basepntr3 add tmp1, idx add tmp2, idx add tmp3, idx movs wrval1, tmp1 movs wrval2, tmp2 movs wrval3, tmp3 wrval1 mov Value1, 0-0 wrval2 mov Value2, 0-0 wrval3 mov Value3, 0-0 write_ret retEric, ya I am seeing this kind of code for the first time, I have always been a High Level programer. I started with GWBasic on an old TI back in the 80's but never got a chance to do Micro programing. Tolken ring style was wher I started and then when OOP came about I was all over that in Basic 6.0. I'm also a PLC programmer and I do some robotics in a java style language for ABB. Industrial Controls was always my interest untill someone showed me a PLC based off the Basic Stamp, and then I was all over Mico Programing. I find it fasinating to program at this level without needing much hardware.