0

I am given two numbers and required to divide them.

I figured that the first step would be to move the dividend to EAX, but I also believe that EDX should be 0xffffffff if the sign of the dividend is negative and 0 if it's positive.

The problem is that I don't know how to this. Perhaps I should use some shifting instruction and then assign the value by hand depending on the result, but I am not really sure how to get the MSB of the dividend and how check whether it's 0 or 1. What is a good way to do this?

Please use basic instructions only (like jump, shift, mov, cmp and arithmetic operations). Thanks a lot.

EL_9
  • 404
  • 2
  • 10
  • 2
    Yes, sign-extending EAX into EDX:EAX is the first step before `idiv` (with a 32-bit divisor). x86 has an instruction for this, called `cdq`. You can emulate it using `mov edx, eax` / `sar edx, 31` to broadcast the sign bit of EAX to all bits of EDX. – Peter Cordes Apr 10 '20 at 19:57
  • Maybe I was hasty closing this as a duplicate since you're asking for how to do it "manually" with basic instructions, not just the standard recipe. Oh, but my answer there does mention the mov/sar way to emulate CDQ so that's ok. – Peter Cordes Apr 10 '20 at 20:02
  • @PeterCordes Thank you. If you post this as an answer I will accept it. – EL_9 Apr 11 '20 at 06:05

0 Answers0