The `idiv` instruction generates incorrect remainder in RDX. Why?

Viewed 44

I want to calculate the remainder of a signed division, but the idiv instruction generates an incorrect result.
I'm trying to calculate " -1 mod 20 ".

I wrote this :

mov  rdx , 0
mov  rax , -1
mov  rbx , 20
idiv rbx
mov  rbx, rdx       ; move remainder to rbx

After running this code, RBX should be 19 but after seeing result in gdb, RBX equals 0xF (15 in decimal). Why?

0 Answers
Related