[Tutorial] AMX Assembly (#emit)
#2

Jump Instructions
There are assembly instructions which allow you to jump.

Instruction List & Usage
Here is a list of all of them:
#mnemonicoperandsemantics
51JUMPoffsetCIP = CIP + offset (jump to the address relative from the current position)
53JZERoffsetif PRI == 0 then CIP = CIP + offset
54JNZoffsetif PRI != 0 then CIP = CIP + offset
55JEQoffsetif PRI == ALT then CIP = CIP + offset
56JNEQoffsetif PRI != ALT then CIP = CIP + offset
57JLESSoffsetif PRI < ALT then CIP = CIP + offset (unsigned)
58JLEQoffsetif PRI <= ALT then CIP = CIP + offset (unsigned)
59JGRTRoffsetif PRI > ALT then CIP = CIP + offset (unsigned)
60JGEQoffsetif PRI >= ALT then CIP = CIP + offset (unsigned)
61JSLESSoffsetif PRI < ALT then CIP = CIP + offset (signed)
62JSLEQoffsetif PRI <= ALT then CIP = CIP + offset (signed)
63JSGRTRoffsetif PRI > ALT then CIP = CIP + offset (signed)
64JSGEQoffsetif PRI >= ALT then CIP = CIP + offset (signed)
128JUMP.priCIP = PRI (indirect jump)
The PAWN Implementer Guide says we can pass offsets to the jump instructions but unfortunately passing offsets as numbers crashes the compiler.

Код:
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 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
Код:
#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
}
Using jump instructions in assembly hardly gives you any advantage. It will only improve performance by negligible amount when compared to using "goto label;".

Код:
if(k == 0) goto label;
will produce an assembly output

Код:
#emit LOAD.S.pri k
#emit JZER somewhere

somewhere:
JUMP label
The extra jump can be avoided by manually jumping using assembly
Код:
#emit LOAD.S.pri k
#emit JZER label
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.

Код:
goto abc; //No error
#emit LOAD.pri a
#emit LOAD.alt b
#emit JSLESS abc //Error, undefined symbol abc

abc:
your code
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.
Reply


Messages In This Thread
AMX Assembly (#emit) - by Yashas - 15.10.2015, 17:33
Re: AMX Assembly (#emit) - by Yashas - 15.10.2015, 17:35
Re: AMX Assembly (#emit) - by Yashas - 15.10.2015, 17:37
Re: AMX Assembly (#emit) - by Ahmad45123 - 15.10.2015, 18:10
Re: AMX Assembly (#emit) - by SecretBoss - 15.10.2015, 20:31
Re: AMX Assembly (#emit) - by DaniceMcHarley - 17.10.2015, 08:49
Re: AMX Assembly (#emit) - by Stanford - 13.01.2016, 23:19
Re: AMX Assembly (#emit) - by darkdevil - 17.05.2016, 14:37
Re: AMX Assembly (#emit) - by Dutheil - 24.06.2016, 20:59
Re: AMX Assembly (#emit) - by Nero_3D - 24.06.2016, 21:32
Re: AMX Assembly (#emit) - by Yashas - 25.06.2016, 06:59
Re: AMX Assembly (#emit) - by Yashas - 15.07.2016, 15:00
Re: AMX Assembly (#emit) - by Luicy. - 05.08.2016, 19:07
Re: AMX Assembly (#emit) - by Sanya4 - 26.08.2016, 21:16
Re: AMX Assembly (#emit) - by Nero_3D - 27.08.2016, 03:14
Re: AMX Assembly (#emit) - by Sanya4 - 27.08.2016, 19:12
Re: AMX Assembly (#emit) - by Nero_3D - 27.08.2016, 22:15
Re: AMX Assembly (#emit) - by JakeXxX - 28.08.2016, 07:35
Re: AMX Assembly (#emit) - by spookie - 31.01.2017, 22:14
Re: AMX Assembly (#emit) - by HydraHumza - 01.02.2017, 12:03
Re: AMX Assembly (#emit) - by Dutheil - 18.07.2017, 13:43
Re: AMX Assembly (#emit) - by KushalD - 30.07.2017, 06:00
Re: AMX Assembly (#emit) - by Yashas - 01.10.2017, 09:39
Re: AMX Assembly (#emit) - by Yashas - 03.06.2018, 11:31

Forum Jump:


Users browsing this thread: 9 Guest(s)