The Aseba Language is simple but powerful enough to manage also complex coding.
In Aseba language apparently there is not the possibility to define custom function as you can find in other languages. There are only subroutines without arguments.
Starting with this trick you must take in account that in Aseba all the variables are global.
You can use subroutines and variables in order to implement something very similar to functions that we will call pseudofunctions. You can declare global variables conventionally tied to a subroutine and use them for passing arguments and get back results.
You can see there a sample for a psudofunction f1 with three arguments, that perfroms the multiplication of the first two argoments and then add the third.
# declaring pseudofunction input and output arguments. We introduce the notation of prefixing the name of the
# variable with the name of the pseudo function, just in order to remember that these
# variables are dedicated to the named pseudofunction.
var f1_arg1
var f1_arg2
var f1_arg3
var f1_res
var X
# declaring pseudofunction
sub f1
f1_res = f1_arg1 * f1_arg2 + f1_arg3
# Now You can call pseudofunction f1 as follow:
# initialize arguments
f1_arg1=10
f1_arg2=3
f1_arg3=4
# Call the pseudofunction
callsub f1
x = f1_res # The result will be 34 in the variable x
Note for expert programmers
An expert programmer can consider that normally this is not a good way of implementing functions.
This method is "safe" (in the sense that it works correctly) just only because in the Aseba language you cannot call subroutines in a recursive way (also indirectly). This coding is not re-entrant safe but also re-entrant programming is not possible (interrupts are not managed at all).
Sic Parvis Magna