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: Select all
; 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)
Thanks in advance!