The JMP op-code is a simple instruction to jump by a certain number of lines.
Consider the following example :
if NumDaysInMonth(nCurYear,nCurMonth) >= nDayOfMonth
sRESULT = IntToStr(nDayOfMonth)
else
sRESULT = ''
endif
which compiles to :
0011 CALL n001=$0GB(@nCurYear|@nCurMonth) //NumDaysInMonth
0011 CALL b001=$0CJ(@n001|@nDayOfMonth) //GreaterOrEqual
0011 IF_001 @b001 jne+0003
0012 CALL sRESULT=$0DH(@nDayOfMonth) //IntToStr
0013 JMP+0002 //ELSE_001
0014 MOV sRESULT=
0015 ENDF_001
In the above example if the condition is true, the instructions following the IF_001 are all executed and when the interpreter reaches the JMP+0002 instruction it skips the following 2 lines (which correspond to the compiled code for the case when the condition is false).
Note that jumps can also be negative.
while nDate < 38000
nDate = nDate + 1
endwhile
The above macro compiles to :
0007 CALL b001=$0FD(@nDate|38000) //LessThan
0007 IF_001 @b001 jne+0003
0008 CALL nDate=$0AA(@nDate|1) //Add
0009 JMP-0003 //GOIF_001
0009 ENDF_001
which shows how an IF_xxx op-code combined with a JMP op-code replaces the need for an op-code to represent the while loop.
Topic 135400, last updated on 18-Apr-2020