C-backend (x86) with assembler

Just starting out? Need help? Post your questions and find answers here.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

C-backend (x86) with assembler

Post by Psychophanta »

Code: Select all

Procedure.d EnvolverAngulo(angle.d)
  !fldpi
  !fadd st0,st0; <- now i have 2*pi into st0
  !fld qword[p.v_angle]
  !fprem1
  !fstp st1
  ProcedureReturn
EndProcedure
Debug EnvolverAngulo(5)
This code does work with normal compilation but it does not with C-backend :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: C-backend (x86) with assembler

Post by wilbert »

This is not a bug.
You can't use inline asm like this with the C backend.
The ! mark is used for inline C when you are using the C backend.

Code: Select all

Procedure.d EnvolverAngulo(angle.d)
  CompilerIf #PB_Compiler_Backend = #PB_Backend_C
    !return remainder(v_angle, 6.2831853071795865);
  CompilerElse
    !fldpi
    !fadd st0,st0; <- now i have 2*pi into st0
    !fld qword[p.v_angle]
    !fprem1
    !fstp st1
    ProcedureReturn
  CompilerEndIf
EndProcedure

Debug EnvolverAngulo(5)
Windows (x64)
Raspberry Pi OS (Arm64)
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: C-backend (x86) with assembler

Post by Quin »

You can still get away with some inline assembly using the __asm keyword though: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: C-backend (x86) with assembler

Post by Psychophanta »

🙄
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: C-backend (x86) with assembler

Post by Denis »

Psychophanta,

another way is to create a lib with your code.I've done a lib and done some test and i seems to be Ok with both x86 backend compiler.

here code x86

Code: Select all

; Fasm x86
format MS COFF

;--------------------------------------------------------------------------------
;       Parameter
;--------------------------------------------------------------------------------
; angle (Double)
angle  equ esp + 4

;////////////////////////////////////////////////////////////////////////////////
;//                         Section code EnvolverAngulo                        //
;////////////////////////////////////////////////////////////////////////////////
 
public _PB_EnvolverAngulo@8
section '.text' code readable executable

_PB_EnvolverAngulo@8:

  FLDPI
  FADD   st0, st0       ; <- now i have 2*pi into st0
  FLD    qword[angle]
  FPREM1
  FSTP   st1

  RET    8
and desc file

Code: Select all

; Langage utilisé pour coder la librairie ASM ou C
C

; Nombre de Dll windows utilisées par la lib
0

; Type de librairie
LIB

; Nombre de librairies PureBasic/Utilisateur utilisé par la librairie
0

; Nom du fichier d'aide de la libraire
Psy_2.chm

; Fonction unique créée
EnvolverAngulo, Double, ( angle.d ) - 
Double | StdCall
A+
Denis
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: C-backend (x86) with assembler

Post by Psychophanta »

Thanks Denis 👍👍
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: C-backend (x86) with assembler

Post by mk-soft »

You should slowly remove ASM from your own code and switch to C backend.
At the latest when you have the first windows computer with ARM.
With Raspberry you already only have the ARM at your disposal (or with macOS M1-M4)
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
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: C-backend (x86) with assembler

Post by Denis »

I forgot to mention that this is code only for Windows with Intel or AMD processors (not ARM etc.).
A+
Denis
Post Reply