I have just created a function in a Mitsubishi plc the pics show you how it is compiled and would be similar to how you would do it in DL. just the code will be different so I have simplified it below:
LD SM412 // conditional bit for call to sub so only move var if true
Move D0 to D12287 // move value 1 to var in 1
Move D1 to D12288 // move value 2 to Var in 2
Move D3 to D12289 // Move in/out to var in/out this is an in/out parameter
LD SM412 // logic bit to enable call to subroutine
JSR P1024 // Conditional jump to sub (pointer)
LD SM412 // as this is conditional jump to sub <-- Return line fom sub
Move D12289 to D3 // move modified in/out var back to D3
LD SM412
Mov D12884 to D2 // This moves the result Var out to D2
...... // rest of main program
......
......
FEND // this is Mitsi version of main cycle i.e. END
P2048: // this is the start of the subroutine
+ D12287, D12286 D12284 // Adds in 1 & in 2 into var out
LD>= D12284, K235 // do the compare
+ K1 D12289 // if greater then add 1 to in/out var
RET // Return from sub (RT in DL)
......... Next sub etc.
LD SM412 // conditional bit for call to sub so only move var if true
Move D0 to D12287 // move value 1 to var in 1
Move D1 to D12288 // move value 2 to Var in 2
Move D3 to D12289 // Move in/out to var in/out this is an in/out parameter
LD SM412 // logic bit to enable call to subroutine
JSR P1024 // Conditional jump to sub (pointer)
LD SM412 // as this is conditional jump to sub <-- Return line fom sub
Move D12289 to D3 // move modified in/out var back to D3
LD SM412
Mov D12884 to D2 // This moves the result Var out to D2
...... // rest of main program
......
......
FEND // this is Mitsi version of main cycle i.e. END
P2048: // this is the start of the subroutine
+ D12287, D12286 D12284 // Adds in 1 & in 2 into var out
LD>= D12284, K235 // do the compare
+ K1 D12289 // if greater then add 1 to in/out var
RET // Return from sub (RT in DL)
......... Next sub etc.