Multiplication-Assembly Language Programming-Lab Slides, Slides of Assembly Language Programming

Prof. Abhay Aggrawal delivered this lecture at Birla Institute of Technology and Science for lab of Assembly Language Programming. It includes: Multiplication, MAX, Binary, Instruction, Operands, IMUL, Division, Quotient, Remainder, Dividened

Typology: Slides

2011/2012

Uploaded on 07/26/2012

parina
parina 🇮🇳

4.4

(67)

222 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Multiplication (unsigned)
The MUL (unsigned multiply) instruction
multiplies an 8-, 16-, or 32-bit operand by either
AL, AX, or EAX.
The result of the unsigned product is always in
binary form.
The instruction formats are:
MUL Reg / Mem. Of 08 bits
MUL Reg / Mem. Of 16 bits
MUL Reg / Mem. Of 32 bits
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Multiplication-Assembly Language Programming-Lab Slides and more Slides Assembly Language Programming in PDF only on Docsity!

Multiplication (unsigned)

  • The

MUL

(unsigned multiply)

instruction

multiplies an 8-, 16-, or 32-bit operand by eitherAL, AX, or EAX.

  • The result of the unsigned product is always in

binary form.

  • The

instruction

formats are:

•^

MUL Reg / Mem. Of 08 bits

-^

MUL Reg / Mem. Of 16 bits

-^

MUL Reg / Mem. Of 32 bits

Multiplication

•^

08 Bit Multiplication

  • With 8 bit multiplication, the multiplicand is

always in the AL register(unsigned). Themultiplier can be 8 bit register or memorylocation.

  • It contains One operands because it always

multiplies the operand times the contents ofregister AL.

  • The result of 8 bit multiplication is always

stored in AX(16-bit) register because theresult is always the double of operand.

Multiplication

•^

16 Bit Multiplication

  • With 16 bit multiplication, the multiplicand is

always in the AX register(unsigned). Themultiplier can be 16 bit register or memorylocation.

  • The result of 16 bit multiplication is always

stored in DX:AX register because the result isalways the double of operand.

  • DX contains the most-significant (upper) 16

bits of the product & AX contains the least-significant (lower) 16 bits of result.

Multiplication (16 - Bit)

  • Example:

MOV CX , 2000h

;^

Moving Multiplier in CX

MOV AX , 100h

;^

Moving Multiplicand in AX

MUL CX

;^

Generating Product

MUL RESULT ,DX:AX ;

32-bit Result in DX:AX

DX:AX

00200000h,

CF=

  • The Carry flag indicates whether or not the upper half of the

product contains significant digits.

Multiplication (32 - Bit)

  • Example:

MOV ECX , 12345h

;^

Moving Multiplier in ECX

MOV EAX , 1000h;

Moving Multiplicand in EAX

MUL ECX

;^

Generating Product

MUL RESULT ,EDX:EAX

;^ 32-bit Result in EDX:EAX

EDX:EAX = 0000000012345000h, CF=

  • The Carry flag indicates whether or not the upper half of the

product contains significant digits.

Multiplication (Signed)

  • The I

MUL

(signed multiply)

instruction

multiplies an 8-, 16-, or 32-bit operand by eitherAL, AX, or EAX.

  • The result of the signed product is in the form of

2’s compliment.

  • The

instruction

formats are:

•^

IMUL Reg / Mem. Of 08 bits

-^

IMUL Reg / Mem. Of 16 bits

-^

IMUL Reg / Mem. Of 32 bits

Division (unsigned)

  • The DIV (unsigned division)

instruction

is used

for an 8-, 16-, or 32-bit unsigned division.

  • The dividend is always a double-width dividend

that is divided by the operand. It means that an8-bit division divides 16-bit number by 08-bitnumber, a 16-bit division divides a 32-bitnumber by 16-bit number and same as 32-bitdivision.

Division

(unsigned)

•^

08 Bit Division

  • An 8-bit division uses the AX register to store

the dividend that is divided by the contents ofany 8-bit register or memory location.

  • The Quotient moves into the AL register & AH

contains the remainder after the division.

•^

Important:^ • The important thing is that the dividend must

be of 16-bit. If it is not, then convert it into 16-bit then use the DIV instruction.

Division

(unsigned)

•^

16 Bit Division

  • A 16-bit division uses the DX:AX register to

store the dividend that is divided by thecontents of any 16-bit register or memorylocation.

  • The Quotient moves into the AX register &

DX contains the remainder after the division.

•^

Important:^ • The important thing is that the dividend must

be of 32-bit. If it is not, then convert it into 32-bit then use the DIV instruction.

Division 16 – Bit

(unsigned)

  • How to Convert 16-bit to 32-bit
    • To convert an 16-bit dividend into 32-bit dividend

simply put 16 zeros in the upper half of the dividend.

  • For this move 0 in the DX register.Example:

mov ax , no

; 16-bit 1

st

No.

mov dx,

; converting it to 32-bit

div no

; dividing by 2

nd

No.

mov qot , ax

; save quotient

mov rem , dx

; save remainder

Division 32 – Bit

(unsigned)

  • How to Convert 32-bit to 64-bit
    • To convert an 32-bit dividend into 64-bit dividend

simply put 32 zeros in the upper half of the dividend.

  • For this move 0 in the EDX register.Example:

mov eax , no

; 32-bit 1

st

No.

mov edx,

; converting it to 64-bit

div no

; dividing by 2

nd

No.

mov qot , eax

; save quotient

mov rem , edx

; save remainder

Division (signed)

  • The IDIV (signed division)

instruction

is used

for an 8, 16, 32 bit signed division.

  • The dividend is always a double-width dividend

that is divided by the operand. It means that an8-bit division divides 16-bit number by 08-bitnumber, a 16-bit division divides a 32-bitnumber by 16-bit number and same as 32-bitdivision.

Division 16 – Bit

(signed)

  • How to Convert 16-bit to 32-bit
    • CWD (convert word to double word) instruction sign-

extends the 16-bit into signed 32-bit number. Example:

mov ax , no

; 16-bit 1

st

No.

cwd

; converting it to 32-bit

div no

; dividing by 2

nd

No.

mov qot , ax

; save quotient

mov rem , dx

; save remainder

Division 32 – Bit

(signed)

  • How to Convert 32-bit to 64-bit
    • CDQ (convert double word to quad word) instruction

sign-extends the 32-bit into 64-bit signed number. Example:

mov eax , no

; 32-bit 1

st

No.

cdq

; converting it to 64-bit

div no

; dividing by 2

nd

No.

mov qot , eax

; save quotient

mov rem , edx

; save remainder