My program's supposed to perform division by using subtraction. However, I'm getting nonsense results as output. Could someone help me with my procedure and the loop within? Thank you.

```
div proc
pushad
mov ecx,firstInt
mov ebx,0
subtracting:
sub ebx,secondInt
loop subtracting
mov divResult,ebx
popad
ret
divt endp
```

You continu subtracting for as long as there is no borrow. If a borrow happened, you have the count:

EDITWhat the above code still lacks is checking if the divider is zero. If we allow a zero-divider the code will run forever because subtracting zero will never produce a borrow!

This simple solution gets the job done, but it is unacceptably slow for big quotients. This calls for a better solution without betraying of course the task of "Division by using subtracting" aka "Don't use

`div`

(or any similar instruction)".In order to mimic the

`div`

instruction:we can write:

The problem with this simple solution is that we could be subtracting a small number many, many times. What if we could find a way to subtract more at once?

We can, if we subtract binary multiples of the divider (*1, *2, *4, *8, *16, ...). It will be the summing of these factors that produces the quotient.

To calculate e.g.

`503 / 20`

we would subtract the following:In code:

To illustrate the importance of developing a better solution, I've timed a few divisions:

`4294967295 / 1`

is the worst case division`2147483648 / 10`

is used to start displaying the number 2147483648`47623 / 320`

is used to convert a 320x200 256-color video mode offset address 47623 into (x,y) coordinates