need help in 64 bit / 8 bit division

hello everybody,

I have 8 bit CPU, using keil cross compiler.

keil provides 32 bit operation only, they dont have 64 bit operation or long long as data type which gcc have.

Now i want 64 bit [ +, -, *, / ] operations,

Does anyone know 64 bit library for 8 bit C51 CPU.

I found 32 bit * 32 bit (long * long ) which has result of 64 bit in 2 long variable as upper and lower.

int main(void) { unsigned long m = 0xffffffff; unsigned long n = 0xffffffff; unsigned long a, b, c, d, hi, lo, temp;

a = (m & 0xffff0000UL) >> 16; b = m & 0xffffU; c = (n & 0xffff0000UL) >> 16; d = n & 0xffffU;

hi = a * c; lo = b * d;

temp = a * d; hi += temp >> 16; lo += (temp & 0x0000ffffUL) > 16; lo += (temp & 0x0000ffffUL)

Reply to
Sachin Gole
Loading thread data ...

Lot of libraries are available in in

formatting link
Check it out.

w.r.t 32-bit, visit ->

formatting link
You can move to 64-bit based on these 32-bit ideas also.

Karthik Balaguru

Reply to

64/8 bit division is trivial if you have a 32/8 or 16/8 bit primitive. All you need to do is to repeat it with the remainder shifted left and the next bits added in until you've done all 64 bits. You can repeat this for any size.

What is difficult is doing 64/64 bit, especially efficiently. GCC for example does terrible on this even for 32-bit targets...


Reply to
Wilco Dijkstra

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.