Page 1 of 1

iPow

Posted: Sun Sep 28, 2003 2:44 pm
by jack
Code updated For 5.20+ (same As Pow())

iPow function
raises x to power y

Code: Select all


Procedure.l iPow(x.l,y.l)
;by bitRAKE  Win32ASM Community messageboard
;thanks bitRAKE
iPowRet.l
! MOV ebx,[esp+4]
! MOV ecx,[esp]
! MOV eax, 1
! JMP _a
! _2: XCHG eax, ecx
! IMUL eax
! XCHG eax, ecx
! _a: SHR ebx, 1
! JNC _3
! IMUL ecx
!_3: JNE _2
! mov [esp+8],eax
ProcedureReturn iPowRet
EndProcedure
edit: fixed version by bitRAKE

Posted: Sun Sep 28, 2003 4:16 pm
by Karbon
Was there something wrong with the Pow() procedure already in PB? Or is this different..

Cool to see it in assembly either way..

Posted: Sun Sep 28, 2003 4:25 pm
by jack
well someone mentioned about wanting a Pow function for integers,
so i thought i give it a try, unfortunately there's a bug that has me
stumped.
for example 2^21=2097152 whereas iPow returns 33554432
and 3^19=1162261467 whereas iPow returns 2030534587
and by now am sure is wrong for other powers as well.

edit: it's fixed now.

Posted: Sun Sep 28, 2003 4:28 pm
by Karbon
Ahh, gotcha :-)

Wish I could help but assembly isn't something I'm very good at!