| CS306 | Processing Systems and Structures | 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 word [VarW] MOV [ResultH], DX MOV [ResultL], AX |

VarB DB 23 Result1 DW ? MOV AL, 6 MUL byte [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.


%macro DIV16 3
; Calculate %1 = %2 / %3
; (all 16-bit signed integers)
; Destroys Registers AX,DX
MOV AX, [%2] ; Load AX with Dividend
CWD ; Extend Sign into DX
IDIV word [%3] ; Signed Division
MOV [%1], AX ; Store Quotient
%endmacro |
; Variable Section varX1 DW 20 varX2 DW 4 varR DW ? ; Code Section DIV16 varR,varX1,varX2 |
MOV AX, [varX1] CWD IDIV word [varX2] MOV [varR], AX |