Bit Altering an External variable issue.

Beta Testing discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
pakirk
Posts: 30
Joined: 26 May 2011 01:57

Bit Altering an External variable issue.

#1 Post by pakirk » 08 Jul 2011 01:33

I have found that if you try to alter a BIT of a variable that had been dim’d externally does not work.
Example

Code: Select all

Dim MyVer as word EXTERNAL
MyVer.1 = 1                   'Does not make MyVer.1 = 1
'Or
MyVer.1 = Not MyVer.1    'Does not alter MyVer.1 
'However 
Dim MyVer as word
MyVer.1 = 1  'Does alter MyVer.1
'and
MyVer.1 = 'Not MyVer.1 Does alter MyVer.1
The only way I have found that gets around this is to INCLUDE the module even if it is “included” in the project.
There is a problem with this as I am using VTFT it always removes the INCLUDE as it has to be at the beginning of the module.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Bit Altering an External variable issue.

#2 Post by filip » 08 Jul 2011 08:48

Hi,

I have tried to reproduce this issue, but failed to do so.
Made a simple project with one module in which the variable is declared and in the main source file used the external modifier with this variable.

In the main, I have altered bits just like you wrote in your code.

Can you please attach here the project that represents this issue ?

Regards,
Filip.

pakirk
Posts: 30
Joined: 26 May 2011 01:57

Re: Bit Altering an External variable issue.

#3 Post by pakirk » 09 Jul 2011 01:02

Well there is something very odd with my code. I have tested this with a simple code and it works.
But not in my code.
The veriable in module TxMenuV1e_events_code is Dim Digital1_TP_New_State as word external
The Veriable in module TxMenuV1e_Digital is Dim Digital1_TP_New_State as word

Below is a LIST of the section giving me trouble, This is with the variable “Digital1_TP_New_State” is Dim’ed externaly.

Code: Select all

module TxMenuV1e_events_code
Dim Digital1_TP_New_State as word external
1.	;TxMenuV1e_events_code.mbas, 1015 ::                 sub procedure Dig1Button1Click()
2.	0x9D006BE8        0x27BDFFFC  ADDIU        SP, SP, -4
3.	;TxMenuV1e_events_code.mbas, 1017 ::                 Digital1_TP_New_State.0 = not Digital1_TP_New_State.0
4.	0x9D006BEC        0x802287EA  LB        R2, Offset(_Digital1_TP_New_State+0)(GP)
5.	0x9D006BF0        0x7C420000  EXT        R2, R2, 0, 1
6.	0x9D006BF4        0x38420001  XORI        R2, R2, 1
7.	0x9D006BF8        0x304300FF  ANDI        R3, R2, 255
8.	0x9D006BFC        0x802287EA  LB        R2, Offset(_Digital1_TP_New_State+0)(GP)
9.	0x9D006C00        0x7C620004  INS        R2, R3, 0, 1
10.	0x9D006C04        0xA02287EA  SB        R2, Offset(_Digital1_TP_New_State+0)(GP)
11.	;TxMenuV1e_events_code.mbas, 1019 ::                 end sub
12.	L_end_Dig1Button1Click:
13.	0x9D006C08        0x03E00008  JR        RA
14.	0x9D006C0C        0x27BD0004  ADDIU        SP, SP, 4
15.	; end of _Dig1Button1Click
16.	_Dig2Button1Click:
17.	;TxMenuV1e_events_code.mbas, 1021 ::                 sub procedure Dig2Button1Click()
18.	0x9D006BC0        0x27BDFFFC  ADDIU        SP, SP, -4
19.	;TxMenuV1e_events_code.mbas, 1023 ::                 Digital1_TP_New_State.1 = not Digital1_TP_New_State.1
20.	0x9D006BC4        0x802287EA  LB        R2, Offset(_Digital1_TP_New_State+0)(GP)
21.	0x9D006BC8        0x7C420000  EXT        R2, R2, 0, 1
22.	0x9D006BCC        0x38420001  XORI        R2, R2, 1
23.	0x9D006BD0        0x304300FF  ANDI        R3, R2, 255
24.	0x9D006BD4        0x802287EA  LB        R2, Offset(_Digital1_TP_New_State+0)(GP)
25.	0x9D006BD8        0x7C620004  INS        R2, R3, 0, 1
26.	0x9D006BDC        0xA02287EA  SB        R2, Offset(_Digital1_TP_New_State+0)(GP)
27.	;TxMenuV1e_events_code.mbas, 1025 ::                 end sub
Note that on line 3 the sub "not"’s the Digital1_TP_New_State.0
Appropriately line 5 states
0x9D006BF0 0x7C420000 EXT R2, R2, 0, 1
............................................^This 0 is correct.

As it is Digital1_TP_New_State.0 to be altered.
However where is goes wrong is line 21
Line 19 which is to "not" the Digital1_TP_New_State.1 now look at line 21
0x9D006BC8 0x7C420000 EXT R2, R2, 0, 1
........................................... ^This 0 is NOT correct it should be a 1

This code alters bit "0" but should alter bit "1"

However if it is dim’ed the other way round it compiles differently
The veriable in module TxMenuV1e_events_code is Dim Digital1_TP_New_State as word
The Veriable in module TxMenuV1e_Digital is Dim Digital1_TP_New_State as word external

Code: Select all

module TxMenuV1e_events_code 
Dim Digital1_TP_New_State as word
1.	;TxMenuV1e_events_code.mbas, 1015 :: 		sub procedure Dig1Button1Click()
2.	0x9D006BE8	0x27BDFFFC  ADDIU	SP, SP, -4
3.	;TxMenuV1e_events_code.mbas, 1017 :: 		Digital1_TP_New_State.0 = not Digital1_TP_New_State.0
4.	0x9D006BEC	0x902287EA  LBU	R2, Offset(_Digital1_TP_New_State+0)(GP)
5.	0x9D006BF0	0x7C420000  EXT	R2, R2, 0, 1
6.	0x9D006BF4	0x38420001  XORI	R2, R2, 1
7.	0x9D006BF8	0x304300FF  ANDI	R3, R2, 255
8.	0x9D006BFC	0x902287EA  LBU	R2, Offset(_Digital1_TP_New_State+0)(GP)
9.	0x9D006C00	0x7C620004  INS	R2, R3, 0, 1
10.	0x9D006C04	0xA02287EA  SB	R2, Offset(_Digital1_TP_New_State+0)(GP)
11.	;TxMenuV1e_events_code.mbas, 1019 :: 		end sub
12.	L_end_Dig1Button1Click:
13.	0x9D006C08	0x03E00008  JR	RA
14.	0x9D006C0C	0x27BD0004  ADDIU	SP, SP, 4
15.	; end of _Dig1Button1Click
16.	_Dig2Button1Click:
17.	;TxMenuV1e_events_code.mbas, 1021 :: 		sub procedure Dig2Button1Click()
18.	0x9D006BC0	0x27BDFFFC  ADDIU	SP, SP, -4
19.	;TxMenuV1e_events_code.mbas, 1023 :: 		Digital1_TP_New_State.1 = not Digital1_TP_New_State.1
20.	0x9D006BC4	0x902287EA  LBU	R2, Offset(_Digital1_TP_New_State+0)(GP)
21.	0x9D006BC8	0x7C420040  EXT	R2, R2, 1, 1
22.	0x9D006BCC	0x38420001  XORI	R2, R2, 1
23.	0x9D006BD0	0x304300FF  ANDI	R3, R2, 255
24.	0x9D006BD4	0x902287EA  LBU	R2, Offset(_Digital1_TP_New_State+0)(GP)
25.	0x9D006BD8	0x7C620844  INS	R2, R3, 1, 1
26.	0x9D006BDC	0xA02287EA  SB	R2, Offset(_Digital1_TP_New_State+0)(GP)
27.	;TxMenuV1e_events_code.mbas, 1025 :: 		end sub
Now look as line 21 the “0” is now a “1” which is correct and this code works.
21. 0x9D006BC8 0x7C420040 EXT R2, R2, 1, 1
................................................^The “0” is now a “1” this is correct
The only diference is
TxMenuV1e_events_code is "Dim Digital1_TP_New_State as word" rather than external and
The Veriable in module TxMenuV1e_Digital is "Dim Digital1_TP_New_State as word external"

This is not just Bizarre and confusing but I can not do this kind of operation in module TxMenuV1e_Digital as I get the same problem !!!!
I have also tried moving the dim,s incase there are bridging memory banks but makes no diference.
Could you email me so I can Email the code to you
Regards
Anthony

pakirk
Posts: 30
Joined: 26 May 2011 01:57

Re: Bit Altering an External variable issue.

#4 Post by pakirk » 09 Jul 2011 16:09

Hi I have done further testing with this isue.
On a simple code there is no problem BUT when using VTFT there is a problem.
I have attached example codes using VTFT.

You will see
BitTest.0 = not BitTest.0 - Works
BitTest.1 = not BitTest.1 - Does not work it alters BtiTest.0
BitTest.2 = not BitTest.2 - Does not work it alters BtiTest.0
BitTest.3 = not BitTest.3 - Does not work it alters BtiTest.0
Ect...
There is a module Bittest where the veriable BitTest is defined
and in module VTFT_Bit_Test_events_code veriable BitTest is defined external

If you swap this around ie.
module Bittest
dim BitTest as word external
and in module VTFT_Bit_Test_events_code
dim BitTest as word
The code works as expected however you can not alter veriable BitTest in modual Bittest at a bit by bit.

Regards
Anthony

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Bit Altering an External variable issue.

#5 Post by filip » 11 Jul 2011 09:11

Hi,

Please, can you attach here the minimal project that represents this issue, packed in a ZIP or RAR archive ?
Which compiler version are you using ?

Regards,
Filip

pakirk
Posts: 30
Joined: 26 May 2011 01:57

Re: Bit Altering an External variable issue.

#6 Post by pakirk » 11 Jul 2011 13:46

Hi Filip had to Email to you as this is 387 Kb and sight only allows 256K.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Bit Altering an External variable issue.

#7 Post by filip » 12 Jul 2011 09:51

Hi,

I have reproduced this issue and reported it to our developers.
As a workaround, you can manually include the Bittest module at the beginning of the Events code module :

Code: Select all

 include Bittest
In this way it will work correctly.

I apologize for the inconvenience.

Regards,
Filip.

pakirk
Posts: 30
Joined: 26 May 2011 01:57

Re: Bit Altering an External variable issue.

#8 Post by pakirk » 12 Jul 2011 14:40

Thanks for looking at this. I know that if you include a modual is a work around but as I mentioned erlier--
The only way I have found that gets around this is to INCLUDE the module even if it is “included” in the project.
There is a problem with this as I am using VTFT it always removes the INCLUDE as it has to be at the beginning of the module
There is is also another way, that is use a temp veriable ie

dim MyVer as word external
dim Temp as word

Temp = MyVer
Temp.1 = NOT Temp.1
MyVer = Temp

Regards
Anthony

Post Reply

Return to “mikroBasic PRO for PIC32 Beta Testing”