It is currently Sat Jan 23, 2021 2:37 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: RDRAND ASM Syntax error
PostPosted: Fri Nov 13, 2015 7:49 pm 
Offline
User
User

Joined: Sat May 10, 2008 7:52 am
Posts: 38
Location: SecondLife
Code:
Procedure.f mrdrand()
  EnableASM
  ;MOV RAX, 0
  RDRAND EAX
  DisableASM
  ProcedureReturn
EndProcedure


I get a syntax error on RDRAND line.
(works if i comment it and uncomment the previous one. but... well... obviously, i want a random number as a result, not 0 :p )

btw, i rand some test, RDRAND is slower than calling Random() :(


Top
 Profile  
Reply with quote  
 Post subject: Re: RDRAND ASM Syntax error
PostPosted: Fri Nov 13, 2015 7:56 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1672
try "!rdrand eax" instead of "rdrand eax"? and check cpuid because i think only newer cpus support it, mine doesnt heehee :)

_________________
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: RDRAND ASM Syntax error
PostPosted: Fri Nov 13, 2015 8:05 pm 
Offline
User
User

Joined: Sat May 10, 2008 7:52 am
Posts: 38
Location: SecondLife
mine support it. (i7 4770k)

what is this ! operator ?
now i have an error on the next instruction :D

The code i created using /REASM :

Code:
_Procedure4:
  ;PS4=48
  ;SUB    rsp,40
;
;
;
; ProcedureReturn ((Random(2147483647)/(536870911)) - 2.0)
  ;PUSH   qword 2147483647
  ;POP    rcx
  ;CALL   PB_Random
  ;MOV    qword [rsp-8],rax
  ;FILD   qword [rsp-8]
  RDRAND EAX
  FILD EAX

  FDIV   dword [F14]
  FADD   dword [F15]
  MOVSXD rax,eax
  JMP   _EndProcedure5


Top
 Profile  
Reply with quote  
 Post subject: Re: RDRAND ASM Syntax error
PostPosted: Fri Nov 13, 2015 8:07 pm 
Offline
User
User

Joined: Sat May 10, 2008 7:52 am
Posts: 38
Location: SecondLife
well, it's in the manual of course !!

- It's possible to pass directly an assembly line to the assembler without being processed by the compiler by using the '!' character at the line start. This allow to have a full access to the assembler directives. When using this, it's possible to reference the local variables using the notation 'p.v_variablename' for a regular variable or 'p.p_variablename' for a pointer


Top
 Profile  
Reply with quote  
 Post subject: Re: RDRAND ASM Syntax error
PostPosted: Fri Nov 13, 2015 8:23 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
I didn't know that instruction but it seems to work fine on my computer
Code:
Procedure rdrand()
  !rdrand_loop:
  !rdrand eax
  !jnc rdrand_loop
  ProcedureReturn
EndProcedure

Debug rdrand()

Keya is right that it would be wise to check if the cpu supports this feature.

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: RDRAND ASM Syntax error
PostPosted: Fri Nov 13, 2015 9:03 pm 
Offline
User
User

Joined: Sat May 10, 2008 7:52 am
Posts: 38
Location: SecondLife
Code:

Procedure.f mrdrand()
  Define r.f
  Define d.f = 536870911
  Define two.f = 2
  EnableASM
    ! RDRAND eax
    ! MOV dword [p.v_r], eax
    ! FILD dword [p.v_r]
    ! FDIV dword [p.v_d]
    ! FSUB dword [p.v_two]
    ! FST dword [p.v_d]
    ! MOV EAX, [p.v_d]
  DisableASM
  ProcedureReturn
EndProcedure


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 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:  
cron

 


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