Program Organization

mikroBasic PRO for ARM imposes strict program organization. Below you can find models for writing legible and organized source files. For more information on file inclusion and scope, refer to Modules and to Scope and Visibility.

Organization of Main Module

Basically, the main source file has two sections: declaration and program body. Declarations should be in their proper place in the code, organized in an orderly manner. Otherwise, the compiler may not be able to comprehend the program correctly.

When writing code, follow the model presented below. The main module should look like this:

program <program name>
include <include other modules>

'********************************************************
'* Declarations (globals):
'********************************************************

' symbols declarations
symbol ...

' constants declarations
const ...

' structures declarations
structure ...
  
' variables declarations
dim Name[, Name2...] as [^]type [absolute 0x123] [external] [volatile] [register] [sfr]

' procedures declarations
sub procedure procedure_name(...)
  <local declarations>
  ...
end sub

' functions declarations
sub function function_name(...) as return_type
  <local declarations>
  ...
end sub

'********************************************************
'* Program body:
'********************************************************

main:
  ' write your code here
end.

Organization of Other Modules

Modules other than main start with the keyword module. Implementation section starts with the keyword implements. Follow the model presented below:

module  <module name>
include <include other modules>

'********************************************************
'* Interface (globals):
'********************************************************

' symbols declarations
symbol ...

' constants declarations
const ...

' structures declarations
structure ...

' variables declarations
dim Name[, Name2...] as [^]type [absolute 0x123] [external] [volatile] [register] [sfr]

' procedures prototypes
sub procedure sub_procedure_name([dim byref] [const] ParamName as [^]type, [dim byref] [const] ParamName2, ParamName3 as [^]type)

' functions prototypes
sub function sub_function_name([dim byref] [const] ParamName as [^]type, [dim byref] [const] ParamName2, ParamName3 as [^]type) as [^]type

'********************************************************
'* Implementation:
'********************************************************

implements

' constants declarations
const ...

' variables declarations
dim ...

' procedures declarations
sub procedure sub_procedure_name([dim byref] [const] ParamName as [^]type, [dim byref] [const] ParamName2, ParamName3 as [^]type) [ilevel 0x123] [overload] [forward]
  <local declarations>
  ...
end sub

' functions declarations
sub function sub_function_name([dim byref] [const] ParamName as [^]type, [dim byref] [const] ParamName2, ParamName3 as [^]type) as [^]type [ilevel 0x123] [overload] [forward]
  <local declarations>
  ...
end sub

end.
  Note : Sub functions and sub procedures must have the same declarations in the interface and implementation section. Otherwise, compiler will report an error.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code