PDA

View Full Version : array problem



ro37bis
- 14th September 2006, 09:34
hello guys,
I need to make some like this:
---------------
array var word [5]
C var byte

for c = 0 to 5
if array[C].highbyte = 0 then ' <- Compiler message: This style array syntax not supported
gosub Compute
endif
next c

end

Compute:
'Do something
return
----------------------
but the compiler do not support my array style.
Some idea to solve it?
tnk in advance.
Roberto from Italy

Melanie
- 14th September 2006, 10:48
Most things are already somewhere here on the forum... you just need to SEARCH for them...

http://www.picbasic.co.uk/forum/showthread.php?t=544

ro37bis
- 14th September 2006, 11:32
Hi Melanie,
usefull!!
Tnk you very much!!!!!!!
Roberto

sayzer
- 14th September 2006, 11:47
Like this ?




array var word [5]
C var byte
Temp Var word


for c = 0 to 5

Temp = array[C]
if temp.highbyte = 0 then gosub Compute

next c

mister_e
- 14th September 2006, 14:10
Or maybe


array var word [5]
C var byte

for c = 0 to 5
if (array[C]>>8) = 0 then gosub Compute
next
end

Compute:
'Do something
return


another method...


array var word [5]
C var byte

for c = 0 to 5
if array[C]<=$00FF then gosub Compute
next
end

Compute:
'Do something
return

SteveB
- 14th September 2006, 21:55
Roberto, Sayzer and Steve

Me thinks you will avoid much trouble if the array has 6 elements, or the FOR...NEXT counts from 0 to 4. ;)

Steve B

mister_e
- 15th September 2006, 06:36
LMAO! ssshhhhhhut!

sayzer
- 15th September 2006, 08:10
I know that Steve sleeps only a few hrs from late morning to later morning.

Just like I do.


Don't know about Roberto's.

--------------------

ro37bis
- 16th September 2006, 09:51
Hi guys,
thank you for the support.

I tested all of your suggestion.
the Sayzer solution require 34 bytes,
the 1st Mister_e solution require 83 bytes,
the 2nd solution require 66 bytes.
the Melanie idea for solution:
---------------
array var word [5]
C var byte

for c = 1 to 9 step 2
if array.lowbyte(c) = 0 then gosub Compute
next
end

Compute:
'Do something
return
------------------
require 35 bytes.

The winner is:......... Sayzer.

bye
Roberto

Darrel Taylor
- 16th September 2006, 19:21
OH! A competition.

And as usual, I'm too late, oh well. Here's my entry.
<font color="#008000"><b>DEFINE </b></font><b>NO_CLRWDT 1 </b><font color="#0000FF"><b><i>; Saves 2 words :)

</i></b></font><b>array </b><font color="#008000"><b>VAR WORD </b></font>[<b>5</b>] <b>BANK0 SYSTEM

ArrayStart </b><font color="#008000"><b>CON </b></font><b>EXT
</b><font color="#000080">@ArrayStart = array + 1 </font><font color="#0000FF"><b><i>; Start at highbyte of element 0
</i></b></font><b>LastElement </b><font color="#008000"><b>CON </b></font><b>EXT
</b><font color="#000080">@LastElement = ArrayStart + (4 * 2) </font><font color="#0000FF"><b><i>; Stop at element 4

</i></b></font><b>FSR </b>= <b>ArrayStart
Loop1</b>:
<font color="#008000"><b>IF </b></font><b>INDF </b>= <b>0 </b><font color="#008000"><b>THEN GOSUB </b></font><b>Compute
FSR </b>= <b>FSR </b>+ <b>2
</b><font color="#008000"><b>IF </b></font><b>FSR </b>&lt; <b>LastElement </b><font color="#008000"><b>THEN </b></font><b>Loop1
</b><font color="#0000FF"><b><i>;----------------------------------

</i></b></font><b>Compute</b>:
<font color="#0000FF"><b><i>'Do something
</i></b></font><font color="#008000"><b>RETURN</b></font>21 words<hr>
Or going the ASM route
<font color="#000000"><b>array </b><font color="#008000"><b>VAR WORD </b></font>[<b>5</b>] <b>BANK0 SYSTEM

</b><font color="#008000"><b>ASM
</b></font><font color="#000080">ArrayStart = array + 1 </font><font color="#0000FF"><b><i>; Start at highbyte of element 0
</i></b></font><font color="#000080">LastElement = ArrayStart + (4 * 2) </font><font color="#0000FF"><b><i>; Stop at element 4
</i></b></font><font color="#000080">movlw ArrayStart
movwf FSR </font><font color="#0000FF"><b><i>; FSR = ArrayStart
</i></b></font><font color="#000080">Loop1
movf INDF, W
btfsc STATUS, Z
call _Compute </font><font color="#0000FF"><b><i>; if INDF = 0 then gosub Compute
</i></b></font><font color="#000080">movlw 2
addwf FSR, F </font><font color="#0000FF"><b><i>; FSR = FSR + 2
</i></b></font><font color="#000080">movlw LastElement
subwf FSR, W
btfss STATUS, C
goto Loop1 </font><font color="#0000FF"><b><i>; if FSR &lt; LastElement then Loop1
</i></b></font><font color="#008000"><b>ENDASM
</b></font><font color="#0000FF"><b><i>;----------------------------------

</i></b></font><b>Compute</b>:
<font color="#0000FF"><b><i>'Do something
</i></b></font><font color="#008000"><b>RETURN</b></font>13 words

mister_e
- 16th September 2006, 20:41
Neat!
I wasn't aware that we could access to FSR and INDF directly... thanks!

i just hope our friend don't use 18Fs or some 12 bit core ;)

Darrel Taylor
- 16th September 2006, 21:12
>> i just hope our friend don't use 18Fs or some 12 bit core

I had the same concerns, but after compiling the "Melanie idea for solution" example(post 9), I found that it was 35 words instead of bytes. So I knew he was using a 16F (or C).

And yup, you can directly access any register with PBP. They are all defined in the PIC14EXT.BAS file in the PBP folder.
<br>