Option on DIM statement to force compiler to keep variable

Post your requests and ideas on the future development of mikroBasic PRO for PIC.
Post Reply
Author
Message
jimfouch
Posts: 18
Joined: 10 Mar 2010 17:06

Option on DIM statement to force compiler to keep variable

#1 Post by jimfouch » 18 Jun 2019 03:24

There are times I embed objects into Byte arrays to then later be addressed at run time.

When the compiler searches and does not see me address the array by using @ArrayName, it removed the array to try to optimize.

Here is an example of some object that are in my code. This is actually managed outside of MikroBasic by a project editor.

Code: Select all

  ' Menu Name:'MainMenu'
  ' Title:    'Main Menu'
  ' Address:  1992

  ' Menu Items.      Count:10

  ' Type  Label                 Pointer CMD  P1      P2      
  ' =========================================================
  ' 3     'Reset Fuel'          320                          
  ' 0     'Settings'            2164                         
  ' 0     'Calibration'         2236                         
  ' 0     'Maintenance'         2190                         
  ' 3     'Test Menu Item X'    108                          
  ' 3     'Test Menu Item Y'    164                          
  ' 3     'Test Menu Item Z'    156                          
  ' 4     'LED On'                      1    1       10000   
  ' 4     'LED Off'                     1    0       0       
  ' 4     'Toggle LED'                  2    0       0       
 CONST MainMenu as BYTE[172]=(
$01,$4D,$61,$69,$6E,$20,$4D,$65,$6E,$75,$00,$0A,$03,$52,$65,$73,$65,$74,$20,$46,$75,$65,$6C,$00,$40,$01,$00,$53,$65,$74,$74,$69,$6E,$67,$73,$00,$3A,$04,$00,$43,$61,$6C,$69,$62,$72,$61,$74,$69,$6F,$6E,$00,$5E,$04,$00,$4D,$61,$69,$6E,$74,$65,$6E,$61,$6E,$63,$65,$00,$47,$04,$03,$54,$65,$73,$74,$20,$4D,$65,$6E,$75,$20,$49,
    $74,$65,$6D,$20,$58,$00,$6C,$00,$03,$54,$65,$73,$74,$20,$4D,$65,$6E,$75,$20,$49,$74,$65,$6D,$20,$59,$00,$A4,$00,$03,$54,$65,$73,$74,$20,$4D,$65,$6E,$75,$20,$49,$74,$65,$6D,$20,$5A,$00,$9C,$00,$04,$4C,$45,$44,$20,$4F,$6E,$00,$01,$01,$00,$10,$27,$04,$4C,$45,$44,$20,$4F,$66,$66,$00,$01,$00,$00,$00,$00,$04,$54,$6F,$67,$67,
    $6C,$65,$20,$4C,$45,$44,$00,$02,$00,$00,$00,$00) org $007C8

  ' Menu Name:'SettingsMenu'
  ' Title:    'Settings'
  ' Address:  2164

  ' Menu Items.      Count:2

  ' Type  Label                 Pointer CMD  P1      P2      
  ' =========================================================
  ' 0     'MI1'                 1992                         
  ' 0     'MI2'                 1992                         
 CONST SettingsMenu as BYTE[25]=(
$01,$53,$65,$74,$74,$69,$6E,$67,$73,$00,$02,$00,$4D,$49,$31,$00,$E4,$03,$00,$4D,$49,$32,$00,$E4,$03) org $00874

I'm forced to have code like this to make sure the compiler keeps them...

Code: Select all

    ' {MANAGED OBJECT KEEPALIVES START}
    t_Byte=@MainMenu
    t_Byte=@SettingsMenu
    t_Byte=@MaintenanceMenu
    t_Byte=@CalMenu
    t_Byte=@LU1
    t_Byte=@LU_DistanceUM
    t_Byte=@LU_TempUnits
    t_Byte=@luEffency

    ' {MANAGED OBJECT KEEPALIVES START}
Not that each line above takes a lot to store, it still robs a few bytes of code space for each one. I'm guessing if it were an option added to the DIM statement it would take zero extra bytes.

Code: Select all

;MotoGadget.mbas,1198 ::                 t_Byte=@MainMenu
0x7142        0x0EC8              MOVLW       _MainMenu
0x7144        0x6FE4              MOVWF       _T_Byte, 1
It would be very nice to be able to add something after the DIM statement to tell the compiler not to remove the array. Something like a simple KEEP

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Option on DIM statement to force compiler to keep variab

#2 Post by janni » 18 Jun 2019 14:00

It would be very nice to be able to add something after the DIM statement to tell the compiler not to remove the array. Something like a simple KEEP
It would certainly be handy. Before it happens you may use a trick that does not produce code

Code: Select all

CONST SettingsMenu as BYTE[25]=(
$01,$53,$65,$74,$74,$69,$6E,$67,$73,$00,$02,$00,$4D,$49,$31,$00,$E4,$03,$00,$4D,$49,$32,$00,$E4,$03) org $00874

main:
 Lo(SettingsMenu[0])

jimfouch
Posts: 18
Joined: 10 Mar 2010 17:06

Re: Option on DIM statement to force compiler to keep variab

#3 Post by jimfouch » 18 Jun 2019 15:39

Thank you Sir. :D :D :D

That works great. and it saves me 10 bytes for each object. That can add up real quick since some of the objects are pretty small.





janni wrote:
It would be very nice to be able to add something after the DIM statement to tell the compiler not to remove the array. Something like a simple KEEP
It would certainly be handy. Before it happens you may use a trick that does not produce code

Code: Select all

CONST SettingsMenu as BYTE[25]=(
$01,$53,$65,$74,$74,$69,$6E,$67,$73,$00,$02,$00,$4D,$49,$31,$00,$E4,$03,$00,$4D,$49,$32,$00,$E4,$03) org $00874

main:
 Lo(SettingsMenu[0])

Post Reply

Return to “mikroBasic PRO for PIC Wish List”