#61945 - winneymj - Fri Nov 25, 2005 5:17 pm
Hi,
I am fairly new to DS development but have been a C/ASM/JAVA program for some 15 years.
I am using DevKitPro/DevKitArm r17, DsEMU 0.4.8 and ndslib 20051018.
I have been having persistent problems with the Modulus (%) and divide (/) not returning back correct results.
Example (1 % 10) keeps returning 0, and as we all know it should return 1.
I traced/debugged the assember code to the SWI 9, bios call and here is what I am seeing.
R00 - loaded with numerator (example = 1)
R01 - loaded with divisor (example = 10)
Call made to SWI 9
R00 - now has 10
R01 - now has 0
According to documentation I found on the BIOS at ndslib, the SWI 9 call is supposed to return the remainder in R01 (see below), and should contain value 1, not zero. I am not sure the R00 register is correct either.
//////////////////////////////////////////////////////////////////////
//
// swi 0x09: Divide (returns result in r0, remainder in r1)
//
// int Divide(int numerator, int divisor);
// returns numerator / divisor
//
// int Remainder(int numerator, int divisor);
// returns numerator % divisor
//
// void DivMod(int numerator, int divisor, int * result, int * remainder);
// sets *result = numerator / divisor and remainder = numerator % divisor
//
//////////////////////////////////////////////////////////////////////
I saw from the DSEMU posts that 0.4.8, was to correct a SWI divide bug. What was the bug?
Thanks for anyhelp. This has been frustrating me for the last couple of weeks.
I am fairly new to DS development but have been a C/ASM/JAVA program for some 15 years.
I am using DevKitPro/DevKitArm r17, DsEMU 0.4.8 and ndslib 20051018.
I have been having persistent problems with the Modulus (%) and divide (/) not returning back correct results.
Example (1 % 10) keeps returning 0, and as we all know it should return 1.
I traced/debugged the assember code to the SWI 9, bios call and here is what I am seeing.
R00 - loaded with numerator (example = 1)
R01 - loaded with divisor (example = 10)
Call made to SWI 9
R00 - now has 10
R01 - now has 0
According to documentation I found on the BIOS at ndslib, the SWI 9 call is supposed to return the remainder in R01 (see below), and should contain value 1, not zero. I am not sure the R00 register is correct either.
//////////////////////////////////////////////////////////////////////
//
// swi 0x09: Divide (returns result in r0, remainder in r1)
//
// int Divide(int numerator, int divisor);
// returns numerator / divisor
//
// int Remainder(int numerator, int divisor);
// returns numerator % divisor
//
// void DivMod(int numerator, int divisor, int * result, int * remainder);
// sets *result = numerator / divisor and remainder = numerator % divisor
//
//////////////////////////////////////////////////////////////////////
I saw from the DSEMU posts that 0.4.8, was to correct a SWI divide bug. What was the bug?
Thanks for anyhelp. This has been frustrating me for the last couple of weeks.