multiplication and division instructions

24
Introduction to Computer Engineering by Richard E. Haskell Multiplication and Division Instructions Module M16.4 Section 10.4

Upload: marge

Post on 29-Jan-2016

47 views

Category:

Documents


0 download

DESCRIPTION

Multiplication and Division Instructions. Module M16.4 Section 10.4. Binary Multiplication. 9 C = 156. Binary Multiplication. 13 x 12 26 13 156. 1101 1100 0000 0000 1101 1101 10011100. Hex Multiplication. Hex Multiplication. Dec. Hex. 3D - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Multiplication and DivisionInstructions

Module M16.4

Section 10.4

Page 2: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Binary Multiplication

Table 10.8Binary Multiplication Table

0 10 0 01 0 1

Page 3: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Binary Multiplication

13x 12 26 13 156

1101 1100 0000 0000 1101 110110011100

9 C = 156

Page 4: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Table 10.9Hexadecimal Multiplication Table

0 1 2 3 4 5 6 7 8 9 A B C D E F0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

Hex Multiplication

Page 5: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

61x 905490

3D x 5A 262 A x D = 82, A x 3 = 1E + 8 = 26 131 5 x D = 41, 5 x 3 = F + 4 = 13 157216 = 549010

Dec Hex

Page 6: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Hex Multiplication

0000 B0 3D MOV AL,3DH ;AL=3DH0002 B3 5A MOV BL,5AH ;BL=5AH0004 F6 E3 MUL BL ;AX=ALxBL

product = 1572H is in AX

Page 7: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

AND b r/m,imm

SUB b r/m,imm

AND w r/m,imm

SUB w r/m,imm

SUB se r/m,imm

Postbyte Opcodes (PBOC)

000 001 010 011 100 101 110 111

80,82

81

83

F6

F7

mod PBOC r/m

ADD b r/m,imm

ADD w r/m,imm

ADD se r/m,imm

TEST b r/m,imm

TEST w r/m,imm

OR b r/m,imm

OR w r/m,imm

ADC b r/m,imm

ADC w r/m,imm

ADC se r/m,imm

SBB b r/m,imm

SBB w r/m,imm

SBB se r/m,imm

XOR b r/m,imm

XOR w r/m,imm

CMP b r/m,imm

CMP w r/m,imm

CMP se r/m,imm

D0

D1

D2

D3

FE

FF

ROL b r/m,1 ROL b r/m,1

ROR b r/m,1

RCL b r/m,1

RCR b r/m,1

ROL w r/m,1

RORw r/m,1

RCL w r/m,1

RCR w r/m,1

ROL b r/m,CL

ROR b r/m,CL

RCL b r/m,CL

RCR b r/m,CL

ROL w r/m,CL

ROR w r/m,CL

RCL w r/m,CL

RCR w r/m,CL

SHL/SALb r/m,1

SHL/SALw r/m,1

SHL/SALb r/m,CL

SHL/SALw r/m,CL

SHR b r/m,1

SHR w r/m,1

SHR b r/m,CL

SHR w r/m,CL

RAR b r/m,1

RAR w r/m,1

RAR b r/m,CL

RAR w r/m,CL

NOT b r/m

NOT w r/m

NEG b r/m

NEG w r/m

MUL b r/m

MUL w r/m

IMUL b r/m

IMUL w r/m

DIV b r/m

DIV w r/m

IDIV b r/m

IDIV w r/m

INC b r/m

INC w r/m

DEC b r/m

DEC w r/m

CALL intra

CALL inter

JMP intra

JMP inter

PUSH r/m

MUL BL

100

F6

11 011 = E3

E3

Page 8: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

16-Bit Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

31A4 x1B2C 253B0

4 x C = 30A x C = 78 + 3 = 7B1 x C = C + 7 = 133 x C = 24 + 1 = 25

Page 9: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

16-Bit Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

31A4 x1B2C 253B0 6348

2 x 4 = 82 x A = 141 x 2 = 2 + 1 = 32 x 3 = 6

Page 10: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

16-Bit Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

31A4 x1B2C 253B0 6348 2220C

4 x B = 2CA x B = 6E + 2 = 701 x B = B + 7 = 123 x B = 21 + 1 = 22

Page 11: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

16-Bit Hex MultiplicationTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

31A4 x1B2C 253B0 6348 2220C 31A4

0544D430

0000 B8 A4 31 MOV AX,31A4H ;AX=31A4H0003 BB 2C 1B MOV BX,1B2CH ;BX=1B2CH0006 F7 E3 MUL BX ;DX:AX = AX x BX

Page 12: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Unsigned MUL Instruction

Machine Assembly LanguageCode Instruction Operation F6 PB MUL b r/m AX = AL x r/m8F7 PB MUL w r/m DX:AX = AX x r/m16

Page 13: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Unsigned MultiplicationDec Hex

165x 36 990495 5940

A5x 24 29414A 1734

594010 = 173416

But A5 = 10100101 can be a signed number2’s comp = 01011011 = 5BH = 9110 Therefore, A5 can represent -91

Page 14: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Signed MultiplicationDec

-91 x 36 546 273 -3276

327610 = 0CCC16

= 0000 1100 1100 11002’s comp = 1111 0011 0011 0100 = F334H

Therefore, for signed multiplicationA5H x 24H = F334Hand not 1734H

The 8086 IMUL instruction performs SIGNED multiplciation

Page 15: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Signed Multiplication

0000 B0 A5 MOV AL,A5H ;AL=A5H0002 B3 24 MOV BL,24H ;BL=24H0004 F6 EB IMUL BL ;AX=ALxBL

product = F334H is in AX

Page 16: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Signed IMUL Instruction

Machine Assembly LanguageCode Instruction Operation F6 PB IMUL b r/m AX = AL x r/m8F7 PB IMUL w r/m DX:AX = AX x r/m16

Page 17: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Binary Division

1001110011001

110001111

1

110000110

0

000001100

1

11000000

DC 9C

Page 18: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Hex DivisionTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

EE BC2FC

C x E = A8C x E = A8 + A = B2

B28 9AF

A

Page 19: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Hex DivisionTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

EE BC2FC

A x E = 8CA x E = 8C + 8 = 94

B28 9AF

A

94C 63

Dividend = BC2FDivisor = EEQuotient = CARemainder = 63

Page 20: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Hex DivisionTable 10.9

Hexadecimal Multiplication Table0 1 2 3 4 5 6 7 8 9 A B C D E F

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 01 1 2 3 4 5 6 7 8 9 A B C D E F2 4 6 8 A C E 10 12 14 16 18 1A 1C 1E3 9 C F 12 15 18 1B 1E 21 24 27 2A 2D4 10 14 18 1C 20 24 28 2C 30 34 38 3C5 19 1E 23 28 2D 32 37 3C 41 46 4B6 24 2A 30 36 3C 42 48 4E 54 5A7 31 38 3F 46 4D 54 5B 62 698 40 48 50 58 60 68 70 789 51 5A 63 6C 75 7E 87A 64 6E 78 82 8C 96B 79 84 8F 9A A5C 90 9C A8 B4D A9 B6 C3E C4 D2F E1

0000 B8 2F BC MOV AX,0BC2FH ;AX=BC2FH0003 B3 EE MOV BL,0EEH ;BL=EEH0006 F6 F3 DIV BL ;AL=AX/BL

quotient = AL = CAHremainder = AH = 63H

EE BC2FC

B28 9AF

A

94C 63

Page 21: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

8086 Division Instructions

Machine Assembly LanguageCode Instruction Operation F6 PB DIV rm8 AL = AX/rm8 (unsigned)

AH = remainderF7 PB DIV rm16 AX = DX:AX/rm16 (unsigned)

DX = remainderF6 PBI IDIV rm8 AL = AX/rm8 (signed)

AH = remainderF7 PBI IDIV rm16 AX = DX:AX/rm16 (signed)

DX = remainder

Page 22: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

Divisor may be too small

E BC2FD71 rem 1

Quotient does not fit in ALCauses a “divide by zero” interrupt

Page 23: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

IPCSIP

CSIP

CSIP

CSIP

CSIP

CS

IPCSIP

CSIP

CSIP

CSIP

CSIP

CSIP

CSIP

CSIP

CSIP

CSIP

CSIP

CSIP

CS

IPCSIP

CSIP

CSIP

CS

Offset Address

000

004

008

00C

010

014

040

044

048

04C

050

054

058

0

1

2

3

4

5

10

11

12

13

14

15

16

17

18

19

1A

1B

1C

20

21

22

23

IPCSIP

CS

FE

FF

05C

060

064

068

06C

070

080

084

088

08C

3F8

3FC

Type No.

Division by zero

Single Stepping

NMI Interrupt

1-byte INT (opcode = CC)

Signed overflow

Print Screen

Video I/O

Equipment Check

Memory Size

Diskette I/O

Serial Communication I/O

Cassette I/O

Keyboard I/O

Printer I/O

Cassette BASIC

Bootstrap

Time of Day

Keyboard Break

Timer Tick

Program Terminate

Function Request

Terminate Address

Ctrl-Break Exit Address

DOS

BIOS

InterruptVectorTable

Page 24: Multiplication and Division Instructions

Introduction to Computer Engineering by Richard E. Haskell

IPCS

000

004

008

00C

010

014

0

1

2

3

4

5

CS

CS

CS

CS

CS

IP

IP

IP

IP

IP

Interrupt Vector TableOffsetaddress Type number

Division by zero

Single Stepping

NMI Interrupt

1-Byte INT (opcode = CC)

Signed overflow (INTO)

Print screen