15.10.2015, 17:35
(
Последний раз редактировалось Yashas; 01.10.2017 в 07:35.
)
Jump Instructions
There are assembly instructions which allow you to jump.
Instruction List & Usage
Here is a list of all of them:
The PAWN Implementer Guide says we can pass offsets to the jump instructions but unfortunately passing offsets as numbers crashes the compiler.
The above code will crash the compiler.
The only way you can now pass offsets to the jump instructions is by using labels.
The following code illustrates how to use labels as offsets for jump instructions
Using jump instructions in assembly hardly gives you any advantage. It will only improve performance by negligible amount when compared to using "goto label;".
will produce an assembly output
The extra jump can be avoided by manually jumping using assembly
Compiler Bug
If you try to compile the following code you will get an error stating that symbol "abc" is undefined even though it is defined.
The compiler allows you to use goto with lables that are defined later. But unfortunately the compiler does not recognize labels that are defined later when you use #emit.
Bug #13 in Known Runtime/Compiler Bugs topic.
There are assembly instructions which allow you to jump.
Instruction List & Usage
Here is a list of all of them:
# | mnemonic | operand | semantics |
51 | JUMP | offset | CIP = CIP + offset (jump to the address relative from the current position) |
53 | JZER | offset | if PRI == 0 then CIP = CIP + offset |
54 | JNZ | offset | if PRI != 0 then CIP = CIP + offset |
55 | JEQ | offset | if PRI == ALT then CIP = CIP + offset |
56 | JNEQ | offset | if PRI != ALT then CIP = CIP + offset |
57 | JLESS | offset | if PRI < ALT then CIP = CIP + offset (unsigned) |
58 | JLEQ | offset | if PRI <= ALT then CIP = CIP + offset (unsigned) |
59 | JGRTR | offset | if PRI > ALT then CIP = CIP + offset (unsigned) |
60 | JGEQ | offset | if PRI >= ALT then CIP = CIP + offset (unsigned) |
61 | JSLESS | offset | if PRI < ALT then CIP = CIP + offset (signed) |
62 | JSLEQ | offset | if PRI <= ALT then CIP = CIP + offset (signed) |
63 | JSGRTR | offset | if PRI > ALT then CIP = CIP + offset (signed) |
64 | JSGEQ | offset | if PRI >= ALT then CIP = CIP + offset (signed) |
128 | JUMP.pri | CIP = PRI (indirect jump) |
Код:
main() { new x,y = 10,z = 50; #emit LOAD.S.pri y #emit LOAD.S.alt z #emit JEQ 8 #emit CONST.pri 100 #emit STOR.S.pri x printf("%d",x); }
The only way you can now pass offsets to the jump instructions is by using labels.
The following code illustrates how to use labels as offsets for jump instructions
Код:
#include <a_samp> main() { new y = 10,z = 11; print("Checking two numbers for equality"); goto check; not_equal: printf("The numbers are not equal"); return 0; equal: print("The numbers are equal!"); return 0; check: #emit LOAD.S.pri y #emit LOAD.S.alt z #emit JEQ equal #emit JUMP not_equal }
Код:
if(k == 0) goto label;
Код:
#emit LOAD.S.pri k #emit JZER somewhere somewhere: JUMP label
Код:
#emit LOAD.S.pri k #emit JZER label
If you try to compile the following code you will get an error stating that symbol "abc" is undefined even though it is defined.
Код:
goto abc; //No error #emit LOAD.pri a #emit LOAD.alt b #emit JSLESS abc //Error, undefined symbol abc abc: your code
Bug #13 in Known Runtime/Compiler Bugs topic.