It is currently Tue Jan 19, 2021 8:00 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: IDIV - x86 vs. x64
PostPosted: Sun Jan 25, 2015 8:47 pm 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3967
Location: Berlin, Germany
Hi,

I started ASM programming with 16 bit CPUs, later I wrote some small 32 bit ASM codes, and now I don't actually have a clue about 64 bit ASM. :-(

Inspired by a 32 bit ASM code by Fred, I wrote the following code:

Code:
; PB 5.31

Procedure.i AsmDiv (x.i, n.i)
   CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
      ! MOV  eax, [p.v_x]
      ! MOV  ecx, [p.v_n]
      ! CDQ
      ! IDIV ecx
      ; ! MOV  eax, edx       ; uncomment this to make it REMAINDER instead of DIV
   CompilerElse
      ! MOV  rax, [p.v_x]
      ! MOV  rcx, [p.v_n]
      ! CQO
      ! IDIV rcx     
      ; ! MOV  rax, rdx       ; uncomment this to make it REMAINDER instead of DIV
   CompilerEndIf
   
   ProcedureReturn            ; result is in eax or rax, respectively
EndProcedure


Debug AsmDiv( 17,  5)
Debug AsmDiv(-17,  5)
Debug AsmDiv( 17, -5)
Debug AsmDiv(-17, -5)


Is the code correct (for Windows, Mac, and Linux)?
Thanks in advance!

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: IDIV - x86 vs. x64
PostPosted: Mon Jan 26, 2015 6:11 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
Little John wrote:
Is the code correct (for Windows, Mac, and Linux)?

It looks fine to me.

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: IDIV - x86 vs. x64
PostPosted: Mon Jan 26, 2015 6:16 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3556
Location: New Zealand
looks right to me, works fine x64 linux


Top
 Profile  
Reply with quote  
 Post subject: Re: IDIV - x86 vs. x64
PostPosted: Mon Jan 26, 2015 8:08 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3967
Location: Berlin, Germany
Many thanks, wilbert and idle!

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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:  

 


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