SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 20/06/2015, 06:47 PM   #1
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 862
Reputation: 290
Default #emit Discussion

Anyone knows how to use JZER/JUMP/etc?

This doesn't seem to work:
Code:
#emit l.15
#emit INC pos
#emit LOAD.pri pos
#emit LOAD.S.alt cmdtext
#emit LIDX
#emit EQ.C.pri 20
#emit JZER 16
#emit JUMP 15

#emit l.16

#emit LOAD.S.alt cmdtext
#emit LOAD.pri pos
#emit IDXADDR
Code:
Run time error 22: "AMX not initialized (or doubly initialized)"
Yashas is offline   Reply With Quote
Old 20/06/2015, 07:08 PM   #2
]Rafaellos[
Gangsta
 
Join Date: Feb 2012
Location: Cyprus
Posts: 730
Reputation: 48
Default Re: #emit Discussion

95% of this forum (including me) have no idea how to use #emit. So I believe that you may not find an answer to your question.
__________________
]Rafaellos[ is offline   Reply With Quote
Old 20/06/2015, 09:18 PM   #3
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,540
Reputation: 552
Default Re: #emit Discussion

Hm, I didn't even consider emitting labels possible, but it almost works:
Quote:
CODE 0 ; 0
;program exit point
halt 0

proc ; main
; line 1
break ; c
; line 2
break ; 10
push.c 0
call .Hello
;$exp
zero.pri
retn

proc ; Hello
; line 6
break ; 30
; line 7
break ; 34
;$lcl pos fffffffc
stack fffffffc
zero.pri
stor.s.pri fffffffc
;$exp
;$lcl cmdtext fffffff8
stack fffffffc
zero.pri
stor.s.pri fffffff8
;$exp

inc fffffffc
load.pri fffffffc
load.s.alt fffffff8
lidx
eq.c.pri 14
jzer 10
jump f
l. 10
load.s.alt fffffff8
load.pri fffffffc
idxaddr
; line 18
break ; b4
const.pri 1
stack 8
retn


DATA 0 ; 0
dump 6c 2e 31 35 0

STKSIZE 1000
As you can see, for some reason it almost works, but adds space before number. I wouldn't work with this. From quick analysis of YSI I see JUMP.rel and JZER.rel is more flexible approach. Also, unless you want to use pure Pcode, you can just write it as

Code:
new tmp;

do {
	#emit INC pos
	#emit LOAD.pri pos
	#emit LOAD.S.alt cmdtext
	#emit LIDX
	#emit STOR.S.pri tmp
} while (20 != tmp);

#emit LOAD.S.alt cmdtext
#emit LOAD.pri pos
#emit IDXADDR
Misiur is offline   Reply With Quote
Old 21/06/2015, 04:38 AM   #4
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 862
Reputation: 290
Default Re: #emit Discussion

I can't find JZER.rel in PAWN Imp Guide.

I am guessing that JZER.rel works like SCTRL? We add 4 bytes for each instruction and operand to calculate the relative address.

EDIT:
Code:
fatal error 104: invalid assembler instruction "jzer.rel"
I am not using amx_assembly so I can't use @emit
--------------------------------------------------------------------
Code:
static nullstr[] = "";
getproperty(0,cmdtext,cellmin,nullstr);
Code:
push.c f4
;$par
push.c 80000000
;$par
push.s 10
;$par
push.c 0
;$par
push.c 10
sysreq.c 2	; getproperty
is faster than

Code:
getproperty(.name = cmdtext);
Code:
const.pri 104
heap 4
movs 4
push.alt
;$par
push.c 80000000
;$par
push.s 10
;$par
push.c 0
;$par
push.c 10
sysreq.c 2	; getproperty
This happens if the default argument is a string!

Speed Test:
138ms,140ms,136ms
160ms,155ms,154ms

Last edited by Yashas; 21/06/2015 at 06:13 AM.
Yashas is offline   Reply With Quote
Old 21/06/2015, 07:50 AM   #5
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,540
Reputation: 552
Default Re: #emit Discussion

Oh, my bad then. Yes, JZER.rel is just a wrapper apparently.
Code:
stock AsmError:AsmEmitJzerRel(ctx[AsmContext], offset) {
	return AsmEmitJumpInstruction(ctx, OP_JZER, offset);
}
I wasn't aware of this second notation to getproperty.

Getting back to main topic: I think you need to retrieve CIP, add your offset, and use JUMP with new value - doing a faux relative jump. Same with JZER. It seems labels will get mangled when #emitting, so better to operate on known values. Use noop for padding if you wish.
Misiur is offline   Reply With Quote
Old 21/06/2015, 08:48 AM   #6
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 862
Reputation: 290
Default Re: #emit Discussion

Code:
native getproperty(id=0, const name[]="", value=cellmin, string[]="");
You can give the arguments in the order of your wish by preceding the parameter name with '.'
Code:
getproperty(.name = "name", .value = 100);
--------------------------------------------------------------------------
I made a different kind of loop.

Code:
#emit LCTRL 6 
#emit ADD.C 16 // 2*4 = 8 bytes
#emit STOR.pri addr //2*4 = 8 bytes

if(cmdtext[++pos] == ' ')
{
    #emit LOAD.pri addr
    #emit SCTRL 6
}
--------------------------------------------------------------------------

Main Topic:
If you look at the PAWNCC generated assembly, you'll find that it adds the label number to the JZER instruction rather than the address.

But the PAWN Imp Guide tells this "if PRI == 0 then CIP = CIP + offset"

Unlike JUMP.pri there is no JZER.pri so I have to give a number

So its impossible to use JZER?

Was searching YSI if Y_Less had ever used JUMP or the conditional jump instructions but couldn't find any!! He uses SCTRL everywhere
Yashas is offline   Reply With Quote
Old 25/06/2015, 12:29 AM   #7
PeterJane
Big Clucker
 
PeterJane's Avatar
 
Join Date: Dec 2014
Posts: 121
Reputation: 13
Default Re: #emit Discussion

Never mind. Just read your comment above.

_____________

Just to not ruin this comment...

You might find something useful.

http://forum.sa-mp.com/showthread.php?t=358084

https://github.com/Zeex/amx_assembly...ter/opcode.inc
PeterJane is offline   Reply With Quote
Old 12/07/2015, 07:56 AM   #8
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 862
Reputation: 290
Default Re: #emit Discussion

Figured out how to use JUMP & Conditional JUMP Instructions

Code:
lable1:
print("HI");

#emit JUMP lable1
Yashas is offline   Reply With Quote
Old 12/07/2015, 10:46 AM   #9
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 11,005
Reputation: 2647
Default Re: #emit Discussion

And how is that different from the generally frowned upon
Code:
goto label1;
?
__________________
Vince is offline   Reply With Quote
Old 12/07/2015, 10:54 AM   #10
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 862
Reputation: 290
Default Re: #emit Discussion

Quote:
Originally Posted by Vince View Post
And how is that different from the generally frowned upon
Code:
goto label1;
?
I mentioned Conditional JUMP Instructions too in my post.

Code:
#emit JZER lable
You cannot have conditional gotos.

Moreover my intention was let people who did not know how to give offset to jump instructions. I had asked many before and no one knew.

Code:
if(k == 0) goto lable;
will produce an assembly output something like this

Code:
#emit LOAD.S.pri k
#emit JZER somewhere
somewhere:
JUMP lable
you can avoid that extra jump using the following code
Code:
#emit LOAD.S.pri k
#emit JZER lable
Yashas is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
when should #emit be used sammp Scripting Help 3 15/11/2014 09:49 AM
@emit Slice Discussion 7 16/04/2013 06:30 PM
Emit Help Snir_sofer Scripting Help 2 25/09/2012 05:54 PM
#emit rVar Scripting Help 3 08/09/2012 06:26 PM
Help with #emit _Petrol_ Scripting Help 0 23/08/2012 03:54 PM


All times are GMT. The time now is 08:45 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.