1

I had a quick question about assembler multiplication from tracing this sequence of steps (I tried to add in comments as well to show my thinking):

mov ax,0305h    ; ax = 0305
mov cx,0204h    ; cx = 0204
mul ch          ; ch = 02, 03 * 02 would make ax = 0006
inc ax          ; ax = 0007
div cl          ; 0007 / 04 would make ax = 0301

Would 0301h be the correct new value for ax at the end of these steps? For some reason, the answer is 0302 but I am not sure why. I don't see how the quotient could be 02 at all.

user10335564
  • 133
  • 3
  • 16
  • `mul ch` is `ax = al * ch`. The value of `al` at that point is 5, not 3. – Michael Mar 11 '19 at 15:39
  • 1
    `mul ch` does `ax=al*ch`so you get `5*2=10`, `inc ax` then changes that to `11` and dividing by `4` gives quotient `2` remainder `3`. Learn to use a debugger to step through code. – Jester Mar 11 '19 at 15:39
  • The only error in your attempt to run this code by hand (instead of with an actual debugger which you should have done after the by-hand way didn't get the known-correct answer) is that you took `AL=05`, given AH:AL = 0x0305. Or did you think that `mul ch` would do `AX = CH * AH`? In that case there's probably another duplicate target, or just https://www.felixcloutier.com/x86/MUL.html – Peter Cordes Mar 11 '19 at 15:44

0 Answers0