PDA

View Full Version : Array error in Hserin



Ioannis
- 27th January 2020, 20:34
It seems that Hserin cannot accept a word array in this expression:



hserin 100,noreceived,[wait("#"),str word_array\2]


Gives this error:
PICBASIC PRO(TM) Compiler 3.1.2.4, (c) 1997, 2019 ME Labs, Inc.
All Rights Reserved.
ERROR: Macro HSERINSTR?WL not found in macro file.

If array is byte size then is just fine. Is that correct? I could not find something in the manual.

Ioannis

Ioannis
- 27th January 2020, 20:46
Got it. It is bytes and it is referenced, somewhat cryptic, on page 47, 3rd line from the bottom in the parenthesis.

Ioannis

richard
- 27th January 2020, 21:44
ext modifier to the rescue


word_array var word[2]
word_array_asbyte var byte ext


@word_array_asbyte=word_array












hserin 100,noreceived,[wait("#"),str word_array_asbyte\4]

pedja089
- 28th January 2020, 00:08
You need _ before PBP name, when used in ASM.

Ioannis
- 28th January 2020, 14:12
Aha! Thanks Richard.

pedja089, you mean instead of

@word_array_asbyte=word_array

be:

@ _word_array_asbyte= _word_array

right?

Ioannis

richard
- 28th January 2020, 20:04
@ word_array_asbyte= _word_array

Ioannis
- 28th January 2020, 22:22
I am facing a problem with arrays.

The task is to grab 10bits of ADC result into array elements.

This works OK:

word_temp.byte0=adresl
word_temp.byte1=adresh
array[i]=word_temp

But this does not:

array.highbyte[i]=adresh
array.lowbyte[i]=adresl

Is something wrong with the above syntax?

Ioannis

richard
- 28th January 2020, 22:46
array[i]=(adresh<<8)|adresl


or
using ext modifier
array_asbyte[i*2]=adresl
array_asbyte[i*2+1]=adresh

Ioannis
- 28th January 2020, 22:52
Thanks Richard.

Comparing the

array[i]=(adresh<<8)|adresl

takes about 10 words more on compilation than

word_temp.byte0=adresl
word_temp.byte1=adresh
array[i]=word_temp

Have not tested the EXT version yet.

Ioannis

Ioannis
- 28th January 2020, 22:58
And the EXT version... 30 words more!!!

I think is too much.

Ioannis

richard
- 28th January 2020, 23:08
this way makes ext method 18 words less


array var word[2]
array_asbyte var byte ext
@array_asbyte=_array
inx var byte
i var byte
ADRESLO VAR BYTE
ADRESHi VAR BYTE


i=0
for inx=0 to 3
'array[inx]=(adreshi<<8)| adreslo
array_asbyte[i]=ADRESLO
i=1+1
array_asbyte[i]=ADRESHi
i=1+1


next


stop

Ioannis
- 28th January 2020, 23:36
Did you tested on 18F or 16F?

I did on 16F887. Maybe this is why I get more memory usage?

Ioannis

richard
- 29th January 2020, 01:20
Did you tested on 18F or 16F?

makes no difference , did you notice that i had removed the math from the array indexing for the better method ?

Ioannis
- 29th January 2020, 08:03
Yes I noticed that. Still no such reduction.

Most compact code was obtained with the crude

word_temp.byte0=adresl
word_temp.byte1=adresh
array[i]=word_temp

Now that I think about it, it is just two transfer. So makes sense, doesn't it?

Ioannis

richard
- 29th January 2020, 08:11
not much on today so i tried a few options with pic16f877 and 16f1825 with no other complications code wise
resultant code sizes are commented



array var word[2]
ADRESLO VAR BYTE
inx var byte
ADRESHi VAR BYTE


;METHOD 0
word_temp var word


;METHODS 2 AND 3
array_asbyte var byte ext
@array_asbyte=_array




;ALL METHODS EXCEPT 0 , 1
i var byte
i=0
;METHOD 4
@ MOVE?CW _array , FSR0L ; PIC16 ENH CORE
;METHOD 5
'@ MOVE?CW _array , FSR ; PIC16 SHITTY OLD CHIP


for inx=0 to 3 ;1 FOR METHOD 0 ; 36 WORDS
' word_temp.byte0=adreslo ;METHOD 0
' word_temp.byte1=adreshi
' array[inx]=word_temp



' array[inx]=(adreshi<<8)| adreslo ;METHOD 1 ; 52 WORDS


' if !i&1 then ;METHOD 2 ; 60 WORDS
' array_asbyte[i]=ADRESLO
' else
' array_asbyte[i]=ADRESHi
' endif
' i=1+1



' array_asbyte[i]=ADRESLO ;METHOD 3 ; 34 WORDS
' i=1+1
' array_asbyte[i]=ADRESHi
' i=1+1





asm ;METHOD 4 PIC16 ENH CORE; 23 WORDS
MOVE?BA _ADRESLO
MOVWI FSR0++
MOVE?BA _ADRESHi
MOVWI FSR0++
ENDASM

'asm ;METHOD 5 PIC16 SHITTY OLD CHIP; 29 WORDS
' MOVE?BA _ADRESLO
' MOVWF INDF
' INCF FSR,F
' MOVE?BA _ADRESHi
' MOVWF INDF
' INCF FSR,F
'ENDASM




next


stop

Ioannis
- 29th January 2020, 09:41
Wow! Thanks for the extensive test.

I suppose i=1+1 should be i=i+1, but does not matter in this test.

The MOVE?BA _ADRESLO are macros I guess, but where can I find documentation how to use that stuff?

Ioannis

richard
- 29th January 2020, 11:47
I suppose i=1+1 should be i=i+1, but does not matter in this test.

might need glasses





where can I find documentation how to use that stuff?

there is none i know of but its pretty simple
A = wreg
B= byte
C= constant
L= label
W=word
S= string
the same as USERCOMMAND
so
MOVE?BA _ADRESLO
is move byte @ ADRESLO to wreg

it saves all that banksel typing

ie
asm
banksel _ADRESLO
movf _ADRESLO,w
banksel whatever is next

Ioannis
- 29th January 2020, 13:40
Thanks Richard.

Well this makes things more clear. Once I remember doing things in ASM, the banklsel was a pain...

Ioannis

Ioannis
- 30th January 2020, 12:54
Received from Charles this very interesting (and I suppose undocumented) tip:

array.highbyte[i << 1]=adresh
array.lowbyte[i << 1]=adresl

OR

array.highbyte[i * 2]=adresh
array.lowbyte[i * 2]=adresl

instead of

array.highbyte[i]=adresh
array.lowbyte[i]=adresl

Really interesting!
Ioannis

mpgmike
- 30th January 2020, 14:25
Another PBP trick when mixing with ASM is to declare your variables with the addendum SYSTEM:



Variable VAR BYTE
@MOVF _Variable, W

...becomes:


Variable VAR BYTE SYSTEM
@MOVF Variable, W

richard
- 31st January 2020, 01:27
UPDATE METHODS


array var word[2]inx var byte
;UNCOMMENT FOR METHOD 8
ADRESHi VAR BYTE ;BANK0 SYSTEM
ADRESLO VAR BYTE ; BANK0 SYSTEM
;METHOD 0
word_temp var word


;METHODS 2 AND 3
array_asbyte var byte ext
@array_asbyte=_array




;ALL METHODS EXCEPT 0 , 1 ,6 ,7 ,8
'i var byte
'i=0
;METHOD 4 ,8
@ MOVE?CW _array , FSR0L ; PIC16 ENH CORE
;METHOD 5
'@ MOVE?CW _array , FSR ; PIC16 SHITTY OLD CHIP

; CHIP
for inx=0 to 1 ; 877 1825
' word_temp.byte0=adreslo ;METHOD 0 30 WORDS 31
' word_temp.byte1=adreshi
' array[inx]=word_temp



' array[inx]=(adreshi<<8)| adreslo ;METHOD 1 50 WORDS 48


' if !i&1 then ;METHOD 2 57 WORDS 57
' array_asbyte[i]=ADRESLO
' else
' array_asbyte[i]=ADRESHi
' endif
' i=i+1



' array_asbyte[i]=ADRESLO ;METHOD 3 30 WORDS 34
' i=i+1
' array_asbyte[i]=ADRESHi
' i=i+1





asm ;METHOD 4 PIC16 ENH CORE na WORDS 22
MOVE?BA _ADRESLO
MOVWI FSR0++
MOVE?BA _ADRESHi
MOVWI FSR0++
ENDASM

'asm ;METHOD 5 PIC16 OLD CHIP 27 WORDS na
' MOVE?BA _ADRESLO
' MOVWF INDF
' INCF FSR,F
' MOVE?BA _ADRESHi
' MOVWF INDF
' INCF FSR,F
'ENDASM

' array.highbyte[inx*2]=adreshi ;METHOD 6 76 WORDS 76
' array.lowbyte[inx*2]=adreslo

' array.highbyte[inx<<1]=adreshi ;METHOD 7 50 WORDS 49
' array.lowbyte[inx<<1]=adreslo


'asm ;METHOD 8 PIC16 ENH CORE na WORDS 22
' movf ADRESLO,w
' MOVWI FSR0++
' movf ADRESHi,w
' MOVWI FSR0++
'ENDASM


next


stop

Ioannis
- 31st January 2020, 08:35
It is very impressive how much room there is for improvements!

Thanks,
Ioannis