| ECE291 | Computer Engineering II | J. W. Lockwood |
Shifts and additions
01100010 (98)
x 00100101 (37)
==========
01100010
01100010--
+ 01100010-----
===============
111000101010 (3626)
|
Note: This method does NOT work for 2's complement numbers
The use of the AX (and DX) registers is implied!
Which operation you perform depends on the size of
the multiplier

VarW DW 513 ResultH DW ? ResultL DW ? MOV AX,54 MUL VarW MOV ResultH, DX MOV ResultL, AX |

VarB DB 23 Result1 DW ? MOV AL, 6 MUL VarB MOV Result1,AX |
| Operation X / Y | Q | R |
|---|---|---|
| 9 / 4 | 2 | 1 |
| -9 / 4 | -2 | -1 |
| 9 / -4 | -2 | 1 |
| -9 / -4 | 2 | -1 |
Again, The use of the AX (and DX)
registers is implied!
Which operation you perform depends on the size of
the divisor.


DIV16 MACRO Result,X,Y
; Calculate Result = X / Y
; (all 16-bit signed integers)
; Destroys Registers AX,DX
MOV AX, X ; Load AX with Dividend
CWD ; Extend Sign into DX
IDIV Y ; Signed Division
MOV Result, AX ; Store Quotient
ENDM |
; Variable Section varX1 DW 20 varX2 DW 4 varR DW ? ; Code Section DIV16 varR,varX1,varX2 |
MOV AX, varX1 CWD IDIV varX2 MOV varR, AX |