MUL and DIV

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Microprocessor and Interfacing

BITS Pilani
Pilani Campus
Multiply & Divide

BITS Pilani, Pilani Campus


MUL SOURCE
➢ Source times AL
➢ Source times AX
➢ Source can be a register or memory location
➢ Result for Byte multiplication in AX
➢ Result for Word multiplication in DX :AX
➢ CF and OF zero if MSB/MSW zero
➢ AF,PF,SF,ZF -undefined

BITS Pilani, Pilani Campus


MUL BH
MUL CX
MUL BYTE PTR [BX]

MOV AX, MULTIPLICAND _16 Multiplying byte with a word requires


the byte’s MSB to be filled with 0’s
MOV CL, MULTIPLIER _8
MOV CH, 00H
MUL CX

BITS Pilani, Pilani Campus


.MODEL TINY
.DATA
MULTIPLICAND DW 2040H
MULTIPLIER DW 2000H
PRODUCT1 DW ?
PRODUCT2 DW ?

.CODE
.STARTUP
MOV AX, MULTIPLICAND
MUL MULTIPLIER
MOV PRODUCT1, AX
MOV PRODUCT2, DX
.EXIT
END

BITS Pilani, Pilani Campus


IMUL SOURCE
▪ Signed Multiplication
▪ Source times AL
▪ Source times AX
▪ Source can be a register or memory location
▪ Result for Byte multiplication in AX
▪ Result for Word multiplication in DX :AX
▪ CF and OF zero if MSB/MSW zero ---- allows the user to detect and perhaps
discard unnecessary leading zero’s in a result. If MSB and MSW contain part of the
result, then both CF=OF=1
▪ AF,PF,SF,ZF -undefined

BITS Pilani, Pilani Campus


IMUL BH
IMUL CX
IMUL BYTE PTR [BX]

MOV CX, MULTIPLICAND _16


MOV AL, MULTIPLIER _8
CBW
IMUL CX

BITS Pilani, Pilani Campus


DIV SOURCE
Divides UNSIGNED WORD by a BYTE
Divides UNSIGNED DWORD by a WORD

➢ Word/Byte
➢ Word in AX,
➢ Byte in Register/Memory location
➢ AL- quotient AH- reminder
To divide a byte by a byte, put the dividend byte in AL
and fill AH with 0’s
➢ DWORD/WORD
➢ DWORD in DX : AX
➢ Word in Register/Memory Location
➢ AX- Quotient DX- Reminder

All Flags undefined

BITS Pilani, Pilani Campus


IDIV SOURCE
SIGNED WORD/BYTE
SIGNED DWORD/WORD

Word/Byte
Dividend Word in AX,
Divisor Byte in Register/Memory location
AL- quotient AH- reminder
To divide a byte by a byte, put the dividend byte in AL
and fill AH with copies of the sign bit from AL.
DWORD/WORD
Dividend DWORD in DX : AX
Divisor Word in Register/Memory Location
AX- Quotient DX- Reminder

All Flags undefined- Sign of remainder same as dividend

BITS Pilani, Pilani Campus


BITS Pilani, Pilani Campus
BITS Pilani, Pilani Campus

You might also like