Const code/data array in flash. How work with it and switch off optimization?

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
Petr2023
Posts: 14
Joined: 07 Jun 2023 16:39

Const code/data array in flash. How work with it and switch off optimization?

#1 Post by Petr2023 » 13 Jun 2023 16:56

Hi,
Please help )
Any directives to switch off optimization?
const's and func1() eliminated if no direct access to it.
I want access indirect to const's and func's
How organize const's to array or other structure?

const menu123 as item_t[2]=(menu,menu1)
Didn't work :(

Code: Select all

program Pointers

' Declarations section
typedef func_t as sub procedure
DIM aa as BYTE volatile

Sub Procedure func1()
    aa=0
End Sub

dim MyPtr as ^func_t

structure item_t
   dim  name as char[4]
   dim  mm as word
   dim func as word
end structure

const menu as item_t = ("123"+"a",1,@func1)   code
const menu1 as item_t = ("234"+"b",2,@func1)  code
const menu2 as item_t = ("345"+"c",3,@func1)  code
const submenu1 as item_t = ("sub"+"d",4,@func1) code

main:
'   Main program

'    Z=@menu
'    Z=@submenu1

end.
Each const - line with fixed width (bytes)
I want to get first line adress
Z=@menu
and then access to other lines indirect
Z=Z+8
But compiler eliminate other const's :(

The array is not so necessary. The compiler arranges one after the other.
But how to stop throwing out constants?
Last edited by Petr2023 on 14 Jun 2023 12:06, edited 2 times in total.

Petr2023
Posts: 14
Joined: 07 Jun 2023 16:39

Re: Const code/data array in flash. How work with it and switch off optimization?

#2 Post by Petr2023 » 14 Jun 2023 11:14

Guys, this is time killing software :lol:

Petr2023
Posts: 14
Joined: 07 Jun 2023 16:39

Re: Const code/data array in flash. How work with it and switch off optimization?

#3 Post by Petr2023 » 14 Jun 2023 12:32

dim MyPtr as ^func_t - not needed GREATE!!!
Wrap to ... wrap to .. wrap to ... like in "C" not needed GREATE!!!
= it can be small and fast like ASM

But a little peice of problem:

Is there any compiler directive?

For example:

Code: Select all

#DONTTOUCHITMOFO
const menu as item_t = ("123"+"¿",1,@func1)   code
const menu1 as item_t = ("234"+"¿",1,@func1)  code
const menu2 as item_t = ("345"+"¿",1,@func1)  code
const submenu1 as item_t = ("sub"+"¿",1,@func1) code
#DONTTOUCHITMOFO END
I found a solution for functions, but for const's ...
Use the SetFuncCall directive within routine body to instruct the linker which routines can be called indirectly from that routine :
SetFunCCall (called_func[, ,...])
Volatile - no effect
External - compile error

HEEEELP :cry:

Petr2023
Posts: 14
Joined: 07 Jun 2023 16:39

Re: Const code/data array in flash. How work with it and switch off optimization?

#4 Post by Petr2023 » 14 Jun 2023 14:30

So far I have found only these methods:
1. Declare array
Dim menu123 as item_t[2]
and then touch each item
menu123[0]=menu
But it generates huge code and duplicate data

2. Touch adress
Dim a as byte rx
a=@menu
....
a=@submenu1
SetFunCCall(func1)

If there is no other way, then it is very bad (very ugly code and duplicate entries + 4 bytes for each line menu) :(

Hmm...
Re-enable optimization (level Four) and compiler eliminate "touch"-code.
This is good, but some directive is needed for this (#DIRECTIVE).
Because it's bad to keep and show this garbage in main

Code: Select all

main:
a=@menu1
.........
...........
........
a=menu50
SetFunCCall(func1,func2, ........................................................................................func50)

Petr2023
Posts: 14
Joined: 07 Jun 2023 16:39

Re: Const code/data array in flash. How work with it and switch off optimization?

#5 Post by Petr2023 » 14 Jun 2023 15:06

Guys, please make an edit especially for me with this directive :oops:

Code: Select all

#DONTTOUCHITMOFO
const menu as item_t = ("123"+"¿",1,@func1)   code
const menu1 as item_t = ("234"+"¿",1,@func1)  code
const menu2 as item_t = ("345"+"¿",1,@func1)  code
const submenu1 as item_t = ("sub"+"¿",1,@func1) code
#DONTTOUCHITMOFOEND
Thank You :D

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

Re: Const code/data array in flash. How work with it and switch off optimization?

#6 Post by filip » 21 Jun 2023 08:23

Hi,

The optimization can be switched off only in the IDE, not in the code.

Have you been able to sort out this issue ?

Regards,
Filip.

Petr2023
Posts: 14
Joined: 07 Jun 2023 16:39

Re: Const code/data array in flash. How work with it and switch off optimization?

#7 Post by Petr2023 » 21 Jun 2023 11:32

filip wrote:
21 Jun 2023 08:23
Hi,

The optimization can be switched off only in the IDE, not in the code.

Have you been able to sort out this issue ?

Regards,
Filip.
I don't know how to do it.
Level: Zero and unchecked SSA - not work.
optimization.png
optimization.png (6.84 KiB) Viewed 795 times
And the file size increases significantly.
Therefore, I would like to keep the optimization and turn it off only in some sections.
But i can't find any directive to do it :(

filip
Do you have corrected and supplemented documentation?

Tnx

Petr2023
Posts: 14
Joined: 07 Jun 2023 16:39

Re: Const code/data array in flash. How work with it and switch off optimization?

#8 Post by Petr2023 » 21 Jun 2023 17:17

Hmmm....
Logic of MicroE

IF forum_question > 0 THEN
wait(is_user_prod_uninst)
else
IF forum_question > 1 THEN
wait(is_user_died)
END IF
END IF

But, where is profit? (no users ->no questions?)

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

Re: Const code/data array in flash. How work with it and switch off optimization?

#9 Post by filip » 29 Jun 2023 09:15

Hi,

Sorry for the delayed answer. The optimization can be switched off only for entire code/project, not in sections.

Regards,
Filip.

Post Reply

Return to “mikroBasic PRO for AVR General”