Why does CQO instruction not recognized by PB

Bare metal programming in PureBasic, for experienced users
Jeff88
New User
New User
Posts: 8
Joined: Thu Jan 03, 2019 3:05 am

Why does CQO instruction not recognized by PB

Post by Jeff88 »

I wanted to see the timing difference between IDIV and DIV. So I wrote a simple program, looked at the assembly code and cut and pasted the portion for c=a/b into the timing loop. I changed IDIV to DIV. The compiler gave a syntax error for CQO line. I put a ! in front of the CQO to send directly to FASM and it worked fine. Any comments? Truly amazing how fast cpu's are today.

Code: Select all

ntimes=1e6

a=999999999999999999
b=567890123456789

atime=ElapsedMilliseconds()
For i=1 To ntimes
Next
btime=ElapsedMilliseconds()
For i=1 To ntimes
  c=a/b
Next
c=0
ctime=ElapsedMilliseconds()
For i=1 To ntimes
  ;c=a/b
  EnableASM
  MOV    r15,qword [v_a]
  PUSH   qword [v_b]
  MOV    rax,r15
  POP    rcx
  !CQO                            ;trouble spot
  DIV   rcx
  MOV    r15,rax
  MOV    qword [v_c],r15
  DisableASM
  Next
dtime=ElapsedMilliseconds()

OpenConsole()
PrintN("nsec/loop")
PrintN(Str(btime-atime)+" "+Str(ctime-btime)+"  "+Str(dtime-ctime))
PrintN(Str(a/b)+ "  "+Str(c))

Input()
End
User avatar
luis
Addict
Addict
Posts: 3713
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy
Contact:

Re: Why does CQO instruction not recognized by PB

Post by luis »

I'm just guessing here.
I think PB EnableASM supports only the opcodes up to 80486, and CQO was introduced with x64.
You have compiled your PB program on x64 so you found that instruction in the generated code.
Post Reply