Reputation: 11
I'm new to assembly language and I would like to ask you the following:
mov ax, y imul z; dx:ax = y*z mov bx, dx mov cx, ax ; bx:cx = y*z mov ax, x cwd ; dx:ax = x sub ax, cx sbb dx, bx ; dx:ax = x-y*z
Why do I have to use the last code line. What am I trying to do is to calculate x-y*z...
Thank you in advance
Upvotes: 0
Views: 284
Reputation: 7946
If I recall my 80386 assembly (yes, it's been that long), the last line is a subtract with borrow. This is the same as when you do subtraction by hand: if you subtract 16 from 24, for example, you subtract 6 from 4 first. But to do that you BORROW a 1 from the tens column and get 12-6=6 for the low order digit. When you do the high order digit, you have to remember that you borrowed and take that into account: 10-10 =0, so the answer is 6.
When you sub ax,cx
, the borrow flag is set if borrowing was necessary, when you sbb dx, bx
, you adjust for the previous borrow.
Upvotes: 2