User manual

mikroBasic PRO for PIC32
MikroElektronika
231
Gosub Statement
Use the gosub statement to unconditionally jump to a local label — for more information, refer to Labels. The syntax
of the gosub statement is:
gosub label_name
...
label_name:
...
return
This will transfer control to the location of a local label specied by label_name. Also, the calling point is remembered.
Upon encountering the return statement, program execution will continue with the next statement (line) after gosub.
The gosub line can come before or after the label.
It is not possible to jump into or out of routine by means of gosub. Never jump into a loop or other structured statement,
since this can have unpredictable effects.
Note: Like with goto, the use of gosub statement is generally discouraged. mikroBasic PRO for PIC32 supports
gosub only for the sake of backward compatibility. It is better to rely on functions and procedures, creating legible
structured programs.
asm Statement
mikroBasic PRO for PIC32 allows embedding assembly in the source code by means of the asm statement. Note that
you cannot use numerals as absolute addresses for register variables in assembly instructions. You may use symbolic
names instead (listing will display these names as well as addresses).
You can group assembly instructions with the asm keyword:
asm
block of assembly instructions
end asm
The only types whose name remains the same in asm as it is in the mikroBasic PRO for PIC32 are registers, e.g.
INTCON, PORTB, WREG, GIE, etc.
mikroBasic PRO for PIC32 comments are allowed in embedded assembly code.
Accessing variables
Depending on the place of declaration, accessing a variable can be done in several ways
- Accessing global variable:
1. If declared under implementation section (visible only in the le where it was declared) : <source_le_
name>_<variable_name>.
2. If declared in the interface section (visible throughout the whole project) : _<variable_name>.
3. If accessing registers (declared through register, rx or sfr speciers, visible throughout the whole project) :
<variable_name>.