uBASIC Local variabiles strange behave

General discussion on mikroBasic PRO for ARM.
Post Reply
Author
Message
Alessandro Fulignani
Posts: 101
Joined: 04 Nov 2016 13:09

uBASIC Local variabiles strange behave

#1 Post by Alessandro Fulignani » 13 Nov 2019 17:07

Hi mikroE,

I can not acces to local variables in subP and subF.

Either in simulation or debug i can not access to the local variable "prova".

Am i doing somethig wrong?

Thank you,

Alex

Simple test program:


program MyProject

' Declarations section

Sub procedure test1()

dim prova as byte

prova = prova +1

end sub


main:

test1()

nop

end.

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: uBASIC Local variabiles strange behave

#2 Post by jovana.medakovic » 15 Nov 2019 10:22

Hello,

In the declaration of the variable, add the word volatile about which you can read in our help file from the compiler.

Code: Select all

dim prova as byte volatile
Kind regards,
Jovana

Alessandro Fulignani
Posts: 101
Joined: 04 Nov 2016 13:09

Re: uBASIC Local variabiles strange behave

#3 Post by Alessandro Fulignani » 16 Nov 2019 12:20

Hi Jovana,

Thank you very much for your answer. That clarify something.

But i still struggle to understand something...

I'v read many(50) of your uB examples and nobody have never declared as "volatile" a variable inside a procedure or a function.
It seems that who wrote those examples was expecting a standard local variables bheave...

If you try the follow simple example you will see that the procedure test1() is working fine without the "volatile" declaration,while the test2() it is working as in my previous post.
It seems that who wrote those examples was expecting a standard beheave from local variables...

If you debug the follow code in assembly, then you see that test1() has the right assembly program, while the routine test2() it's empty!

Let me know your opinion, and if this things can be fixed.

Thank you very much,

Alex

dim pippo as byte

Sub procedure test1()

dim temp as byte

inc(temp)
pippo = temp

end sub


Sub procedure test2()

dim temp as byte

inc(temp)

end sub


while true
test1()
test2()
wend

hexreader
Posts: 1786
Joined: 27 Jun 2010 12:07
Location: England

Re: uBASIC Local variabiles strange behave

#4 Post by hexreader » 16 Nov 2019 12:37

Guessing a bit, but if mikroBasic is similar to mikroC, then the compiler will notice that test2() does absolutely nothing in the real world, and will optimise out the code.

Not sure, but if you turn on warnings and hints in compiler output window, you may, or may not get some indication of "temp" local variable removed.

Could be wrong (but I reckon I am right :) )
Start every day with a smile...... (get it over with) :)

Alessandro Fulignani
Posts: 101
Joined: 04 Nov 2016 13:09

Re: uBASIC Local variabiles strange behave

#5 Post by Alessandro Fulignani » 16 Nov 2019 17:47

Hi Hexreader,

Yes, you're right!

11 1520 variable 'temp' might not have been initialized MyProject.mbas
25 1011 Hint: Variable "temp" has been eliminated by optimizer MyProject.mbas

I wonder if the optimizer can be switched off on some specific routines...

Do you know where i can find informations on the uB optimiser?

Thank you very much!

Alex

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: uBASIC Local variabiles strange behave

#6 Post by jovana.medakovic » 18 Nov 2019 15:35

Hi,

When you run the compiler, go to Tools -> Options -> Output Settings and there you can set Optimization level.

Kind regards,
Jovana

Post Reply

Return to “mikroBasic PRO for ARM General”