Page 1 of 1

C-backend (x86) with assembler

Posted: Wed Apr 09, 2025 8:56 am
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 :?

Re: C-backend (x86) with assembler

Posted: Wed Apr 09, 2025 9:27 am
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)

Re: C-backend (x86) with assembler

Posted: Wed Apr 09, 2025 12:51 pm
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

Re: C-backend (x86) with assembler

Posted: Wed Apr 09, 2025 4:24 pm
by Psychophanta
🙄

Re: C-backend (x86) with assembler

Posted: Sun Apr 13, 2025 6:36 pm
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

Re: C-backend (x86) with assembler

Posted: Sun Apr 13, 2025 7:01 pm
by Psychophanta
Thanks Denis 👍👍

Re: C-backend (x86) with assembler

Posted: Sun Apr 13, 2025 10:10 pm
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)

Re: C-backend (x86) with assembler

Posted: Mon Apr 14, 2025 6:28 am
by Denis
I forgot to mention that this is code only for Windows with Intel or AMD processors (not ARM etc.).