ASM syntax error

Just starting out? Need help? Post your questions and find answers here.
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

ASM syntax error

Post by Lord »

Hi!

For a long time I used PurePDF in a larger program without troubles.
viewtopic.php?f=14&t=17247&p=362157
I could always successfully compile with both versions (x86 and x64).
Today I tried PB 6.00 Alpha 1 (x64) and it failed.
This procedure raises a syntax error with both compilers (asm and c):

Code: Select all

;Thanks to Rescator / skywalk / wilbert for the Procedures EndianW() / EndianL() / EndianQ()
Procedure.l ipdf_EndianL(value.l)
  ; Rescator : http://forums.purebasic.com/english/viewtopic.php?p=84270#p84270
  EnableASM
  MOV Eax, value; <-- this line raises the syntax error
  BSWAP Eax
  DisableASM
  ProcedureReturn
EndProcedure
What's wrong now with this code?
As the syntax error comes up with both new backends, I post it here
and not in "Bugs - C backend"
As I said, it worked with PB5.73LTS(x64) and PB5.73LTS(x86).
Image
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: ASM syntax error

Post by Lord »

Sorry, but I have to correct myself.

I tested again and now I get as a result that only the C backend failes.
Can a moderator please move this posting in "Bugs - C backend"?
Tank you.
Image
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: ASM syntax error

Post by DoubleDutch »

It's not a C backend bug, it just needs updating with either a C version or a regular PB version.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: ASM syntax error

Post by DoubleDutch »

Code: Select all

CompilerIf #PB_Compiler_Processor=#PB_Processor_C   ; CompilerIf #PB_Compiler_Backend=#PB_Processor_C
	
	Procedure.l ipdf_EndianL(value.l)
		ProcedureReturn (value>>24&$ff)|(value>>8&$ff00)|(value<<24&$ff000000)|(value<<8&$ff0000)
	EndProcedure
	
	Procedure.q ipdf_EndianQ(value.q)
		ProcedureReturn	(value>>56&$ff)|(value>>40&$ff00)|(value>>24&$ff0000)|(value>>8&$ff000000)|(value<<56&$ff00000000000000)|(value<<40&$ff000000000000)|(value<<24&$ff0000000000)|(value<<8&$ff00000000)
	EndProcedure
	
	Procedure.w ipdf_EndianW(value.w)
		ProcedureReturn (value>>8&$ff)|(value<<8&$ff00)
	EndProcedure
	
CompilerElse
	
	;Thanks to Rescator / skywalk / wilbert for the Procedures EndianW() / EndianL() / EndianQ()
	Procedure.l ipdf_EndianL(value.l)
	  ; Rescator : http://forums.purebasic.com/english/viewtopic.php?p=84270&sid=7f3f06eae02ad44b303655fb722bb0f0#p84270
	  EnableASM
	  MOV Eax,value
	  BSWAP Eax
	  DisableASM
	  ProcedureReturn
	EndProcedure
	
	CompilerIf #PB_Compiler_Processor=#PB_Processor_x64
	  Procedure.q ipdf_EndianQ(value.q)
	    ; Rescator : http://www.purebasic.fr/english/viewtopic.php?p=84270#p84270
	    EnableASM
	    MOV rax, value
	    BSWAP rax
	    DisableASM
	    ProcedureReturn
	  EndProcedure
	CompilerElse
	  Procedure.q ipdf_EndianQ(value.q)
	    ; Wilbert : http://www.purebasic.fr/english/viewtopic.php?p=361932#p361932
	    Protected addr.l=@value
	    EnableASM
	    MOV edx, addr
	    MOV eax, [edx + 4]
	    MOV edx, [edx]
	    BSWAP eax
	    BSWAP edx
	    DisableASM
	    ProcedureReturn
	  EndProcedure
	CompilerEndIf
	
	Procedure.w ipdf_EndianW(value.w)
	  ; skywalk/wilbert : http://forums.purebasic.com/english/viewtopic.php?p=352259&sid=7f3f06eae02ad44b303655fb722bb0f0#p352259
	  EnableASM
	  ROL value, 8
	  DisableASM
	  ProcedureReturn value
	EndProcedure

CompilerEndIf
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: ASM syntax error

Post by Lord »

Hi DoubleDutch!

Thank you for offering a solution.
But there is still a problem with (some) assembler part(s) in my program.
---------------------------
PureBasic - Assembler error
---------------------------
purebasic.c: In function 'f_decodekekule':

purebasic.c:40010:2: error: unknown type name 'MOV'

MOV rdx, [p.p_K]; rdx -> *K

^~~

purebasic.c:40010:11: error: expected identifier or '(' before '[' token

MOV rdx, [p.p_K]; rdx -> *K

^

...

^
---------------------------
OK
---------------------------
This time the error is raised by this procedure:

Code: Select all

Procedure DecodeKekule(*K.K)
  ! MOV rdx, [p.p_K];          rdx -> *K
  ! MOV rax, [rdx];            -> K=Kekule
  ! cmp rax, 2
  ! jl _G1
  ! BSR rcx, rax
  ! BTR rax, rcx
  ! ADD rcx, 1
  ! MOV [rdx +  8], rcx;       -> G=Generation
  ! MOV [rdx + 16], rax;       -> P=Position
  ! AND rax, 1
  ! MOV [rdx + 24], rax;       -> X=Gender
  ! mov rax, 1
  ! jmp _return 
  !_G1:
  ! cmp rax, 1
  ! jne _G0
  ! MOV qword[rdx +  8],  1;   -> G=1
  ! MOV qword[rdx + 16],  0;   -> P=0
  ! MOV qword[rdx + 24], -1;   -> X invalid
  ! mov rax, 1
  ! jmp _return 
  !_G0:
  ! MOV qword[rdx +  8], -1;   -> G invalid  
  ! MOV qword[rdx + 16], -1;   -> P invalid
  ! MOV qword[rdx + 24], -1;   -> X invalid
  ! mov rax, -1
  !_return:
  ProcedureReturn
EndProcedure
Are assembler instructions not allowed anymore with the new C backend?
Is there another notation neccessary to use assembler with the C Backend?
Image
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: ASM syntax error

Post by DoubleDutch »

Basically, what you need to do is study what that procedure did and re-write it in purebasic, not assembler.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ASM syntax error

Post by mk-soft »

Wait for the compiler option "EnableC DisableC".

Then it will also run later on other processors (ARM, M1).
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: ASM syntax error

Post by Lord »

Hi DoubleDutch!
DoubleDutch wrote: Mon May 24, 2021 11:13 am Basically, what you need to do is study what that procedure did and re-write it in purebasic, not assembler.
Thank you for your answer.
But this doesn't answer my two questions and is not the needed solution.
It is also not helping me in understanding the underlying problem.
DecodeKekule() is used to get the generation, the position within this generation
and the gender of a person with a specific Kekule number.
This number enters the procedure in K\Kekule
The used structure for K is:

Code: Select all

Structure K
  Kekule.i
  Generation.i
  Person.i
  Gender.i
EndStructure
Define K.K
A rewrite in PB-Syntax is counter productive as I had this before and
went to asm for faster execution.
Image
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: ASM syntax error

Post by Lord »

Hi mk-soft!
mk-soft wrote: Mon May 24, 2021 11:38 am Wait for the compiler option "EnableC DisableC".

Then it will also run later on other processors (ARM, M1).
You don't also have any idea when this will be available?
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ASM syntax error

Post by mk-soft »

The development is still alpha status ...
Fred has released the alpha version for Windows early so that we can support him with the debugging.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: ASM syntax error

Post by DoubleDutch »

Under the new version, it could also be that the code runs faster as the c compiler may be better at optimising the code.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: ASM syntax error

Post by Lord »

@mk-soft
Thank you for your answer.

@DoubleDutch
Does that mean, that if I select "C Backend" it's still asm output?
Until now I didn't get any speed increase.
No matter if "optimize generated code" is selected or not.
Image
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: ASM syntax error

Post by DoubleDutch »

The eventual output will be assembler, but via the C compiler. The C compiler may have had more time invested in optimising the output than regular PureBasic - so it could be faster.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: ASM syntax error

Post by Lord »

I can't see any speed increase.
It's not faster or slower compiling nor running the exe.
The only difference that i see is, that the C backend produces
a little smaller executable.
But the program for testing has only ~20000 lines.
Image
Post Reply