It is currently Fri Jun 22, 2018 6:42 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Strange problem with labels
PostPosted: Sat Aug 20, 2016 5:34 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Mar 27, 2009 9:41 am
Posts: 611
Location: Athens, Greece
If I say:
Code:
aa.l
EnableASM
mov eax, 1
cmp eax, 1
je l_nxt
mov eax, 5
nxt:
mov aa, eax
DisableASM
Debug aa
I get output 1 as expected but if I say:
Code:
Procedure test()
aa.l
EnableASM
mov eax, 1
cmp eax, 1
je l_nxt
mov eax, 5
nxt:
mov aa, eax
DisableASM
Debug aa
EndProcedure

test()
I get undefined symbol 'l_nxt' error. Why? What is the right expression?

_________________
http://kc2000labs.shadowtavern.com/pb/pb_eng.htm


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sat Aug 20, 2016 5:54 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Jan 21, 2011 8:25 am
Posts: 1018
Location: 'stralia!
Quote:
If the label is defined in a procedure, then its prefix is 'l_procedurename_', in lowercase.

Manual is actually wrong here, it should be ll_:

Code:
Procedure test()
aa.l
EnableASM
mov eax, 1
cmp eax, 1
je    ll_test_nxt
mov eax, 5
nxt:
mov aa, eax
DisableASM
Debug aa
EndProcedure

test()

_________________
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sat Aug 20, 2016 6:27 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1673
another option is to !inline them directly to the assembler:
Code:
aa.l
EnableASM
mov eax, 1
cmp eax, 1
!je nxt         ;<--
mov eax, 5
!nxt:           ;<--
mov aa, eax
DisableASM
Debug aa

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sat Aug 20, 2016 6:47 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Mar 27, 2009 9:41 am
Posts: 611
Location: Athens, Greece
Thanx for the replies. I had tried ll_ but I didn't know that procedure name should be included.

_________________
http://kc2000labs.shadowtavern.com/pb/pb_eng.htm


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sat Aug 20, 2016 7:29 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3142
Location: Netherlands
Personally I prefer the inline approach Keya demonstrated.
As far as I remember, the way labels are named hasn't always been the same across different PB versions.
It also looks inconsistent to me that the label you have to use for the jump instruction is different form the label declaration itself.
By coding manually, I have full control and know things are working as they should.

_________________
MacOS 10.13 High Sierra, PB 5.60 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sat Aug 20, 2016 9:19 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Mar 27, 2009 9:41 am
Posts: 611
Location: Athens, Greece
wilbert wrote:
Personally I prefer the inline approach Keya demonstrated.
As far as I remember, the way labels are named hasn't always been the same across different PB versions.
It also looks inconsistent to me that the label you have to use for the jump instruction is different form the label declaration itself.
By coding manually, I have full control and know things are working as they should.

Yes, you are right. The way labels work in asm have changed at least two times the last years. I would like to have something more "stable", something that will last regardless PB changes. Is Keya's approach this kind of "stable"?

_________________
http://kc2000labs.shadowtavern.com/pb/pb_eng.htm


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sat Aug 20, 2016 11:08 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Apr 12, 2006 7:59 pm
Posts: 166
Location: Germany
We hope so :) !
In procedures use label with point as local label. See:
Code:
Procedure test()
aa.l
EnableASM
mov eax, 1
cmp eax, 1
!je nxt
mov eax, 5
!nxt:
mov aa, eax
DisableASM
Debug aa
EndProcedure

Procedure test1()
aa.l
EnableASM
mov eax, 1
cmp eax, 1
!je nxt
mov eax, 5
!nxt:
mov aa, eax
DisableASM
Debug aa
EndProcedure

test()
test1()

But:
Code:
Procedure test()
aa.l
EnableASM
mov eax, 1
cmp eax, 1
!je .nxt
mov eax, 5
!.nxt:
mov aa, eax
DisableASM
Debug aa
EndProcedure

Procedure test1()
aa.l
EnableASM
mov eax, 1
cmp eax, 1
!je .nxt
mov eax, 5
!.nxt:
mov aa, eax
DisableASM
Debug aa
EndProcedure

test()
test1()


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sun Aug 21, 2016 9:54 am 
Offline
Addict
Addict
User avatar

Joined: Fri Jan 21, 2011 8:25 am
Posts: 1018
Location: 'stralia!
If it's just about one or two local labels, I prefer using anonymous labels:
Code:
Procedure.i foobar()
   
   !jmp @f
   MessageRequester("skip", "skip")
   !@@:
   
   ProcedureReturn 0   
EndProcedure

foobar()


Use @f to jump forward or @b to jump backwards.

_________________
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sun Aug 21, 2016 11:02 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 12, 2015 6:55 pm
Posts: 105
Yes the fact you must decorate your labels it's clunky, particularly inside EnableASM/DisableASM

request viewtopic.php?p=451756#p451756

Are anon labels available on mac too ? Don't know if nasm or yasm is used on mac, but in any case I'm not sure if anon labels are supported there.


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sun Aug 21, 2016 11:15 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3142
Location: Netherlands
The dot syntax Helle mentioned seems to work fine on OSX.
Anonymous labels (@f with @@) are not supported on OSX. Nasm/Yasm doesn't support this.
If you want your Asm code to be cross platform compatible, don't use them.

_________________
MacOS 10.13 High Sierra, PB 5.60 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sun Aug 21, 2016 11:26 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 12, 2015 6:55 pm
Posts: 105
wilbert wrote:
Anonymous labels (@f with @@) are not supported on OSX. Nasm/Yasm doesn't support this.


Thank you, but out of curiosity it's nasm or yasm used on osx ? :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sun Aug 21, 2016 12:15 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3142
Location: Netherlands
sys64802 wrote:
Thank you, but out of curiosity it's nasm or yasm used on osx ? :)

Both :shock:
PureBasic uses yasm for the 64 bit version of PureBasic on OSX and nasm for the 32 bit version.
Don't ask me why because I have no idea why Fred made this choice.
To me it would be more logical to choose one of the two and use it for both 32 and 64 bit.

Edit:
It seems also possible to use Fasm on OSX with the help of the objconv tool from Agner Fog.
http://www.agner.org/optimize/objconv-instructions.pdf
https://github.com/JohnDDuncanIII/fasm-osx

_________________
MacOS 10.13 High Sierra, PB 5.60 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sun Aug 21, 2016 12:48 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 12, 2015 6:55 pm
Posts: 105
Thank you. :shock:

Didn't know about objconv, that guy is crazy. Awesome. But I don't know enough to fully understand the limitations I think. Way over my head.

Still awesome from what I can understand.


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Sun Aug 21, 2016 1:41 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Mar 27, 2009 9:41 am
Posts: 611
Location: Athens, Greece
sys64802 wrote:
Thank you. :shock:

Didn't know about objconv, that guy is crazy. Awesome. But I don't know enough to fully understand the limitations I think. Way over my head.

Still awesome from what I can understand.

What's the awesome? :?: What's objconv?

_________________
http://kc2000labs.shadowtavern.com/pb/pb_eng.htm


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange problem with labels
PostPosted: Mon Mar 12, 2018 11:17 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Nov 26, 2015 6:52 pm
Posts: 148
Location: Italy
There have also been around Mac ports of FAsm. Here is one:

https://github.com/JohnDDuncanIII/fasm

the repository contains a flat assembler version that will run on Macintosh OS X 10.6-10.11 (both x86 and x86_64).

Even though this isn't an officially supported FAsm version, and won't be guaranteed to be always updated along with latest official FAsm releases, it would be nice if in the upcoming PureBasic versions there was an option to use the FAsm compiler on Mac, instead of Yasm/MASM. I wonder if this is possible ...

If Mac where to support FAsm then there would no longer be the cross-compatiblity issue that is currently introduced by the presence of ASM code in PB sources.

_________________
The PureBASIC Archives:
FOSS Resources:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye