Page 1 of 1

Signed division in C

Posted: Tue Nov 11, 2008 7:11 am
by kestaz
How to write such code in C:

Temporary = AX / Source; //signed division
AL = Temporary;
AH = AX % Source; //signed modulus

I get ax, al, ah values which is by default unsigned, to perform signed divide i just need to convert them to signed and that's all ?

Re: Signed division in C

Posted: Tue Nov 11, 2008 7:45 am
by Combuster
since when would dividing signed numbers be done with an unsigned division? :roll:

Re: Signed division in C

Posted: Tue Nov 11, 2008 7:57 am
by kestaz
I don't understand your question?. I'm need to implement div and idiv instructions, but i don't see difference.

I found page: http://www.ragestorm.net/blogs/?p=62 it's talking about. Says to signed divide i need to do:

res = x/y; if (sign_of_x != sign_of_y) res = -res; (need do this in python)

Does this same in C ?

Re: Signed division in C

Posted: Tue Nov 11, 2008 8:56 am
by CodeCat
You need to write division in C? It might help if you told us a bit more about the requirements/restrictions. Otherwise I'd just say, why bother? Just use C's built in division.