Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
1 Lab Manual CSC159 1.4 MULTIPLICATION AND DIVISION INSTRUCTION i. MUL The MUL instructions multiply an 8-bit or 16-bit operand by AL or AX. If an 8-bit source operand is supplied, it is automatically multiplied by AL, and the result is stored in AX. If a 16-bit source operand is supplied, it is multiplied by AX , and the result is stored in DX and AX (the high 16 bits are in DX). Syntax: MUL source The source operand may be either a register or a memory operand, bit it may not be immediate data. The destination (either AX or DX:AX ) is implied and may not be changed. Example 1: 8 bit register data Mul CL If AX register consist value of 451416 and the content of CL register is 0516, after this instruction is executed, the content of register AX will be 006416. AX 45 14 AH AL CX 05 CH CL Mul CL AX 00 DH 64 DL 2 Lab Manual CSC159 How to calculate: AX AH AL 1416 = 0001 0100 0516 = 101 0001 0100 + 0 0000 000 00 0101 00 0000 0000 0110 0100 0 0 6 4 Example 2. Multiply AL by 10h: Mov Mov Mul AL , 6h BL, 10h BL How to calculate: ;AX = 0060h AX AH AL 1016 = 1 0000 0616 = 110 0 0000 10 000 + 100 00 110 0000 6 0 3 Lab Manual CSC159 Example 1: 16 bit register data Mul CX If AX register consist value of 763416 and the content of CL register is 0716, after this instruction is executed, the content of register AX will be 3B6C16, while the content of DX register will be 000316. AX 76 34 AH AL CX 07 CH CL Mul CX AX 3B 6C AH AL DX 00 DH 03 DL 4 Lab Manual CSC159 How to calculate: AH DH AL DL 3 2 7 1 6 1 3 4 7 51 3 16 √51 48 3 000 3 3 43 22 28 2 1 1 16√43 16√22 16√28 32 16 16 11 6 12 B 6 C 5 Lab Manual CSC159 Example 2. Multiply AX by 10h: Mov Mul . . . ax, var1 var2 var1 var2 ; dx = 0002h , AX = 0000h dw dw 2000h 0010h How to calculate: AH DH AL DL 2 000 2 0 0 0 1 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 0 6 Lab Manual CSC159 ii. DIV The DIV instructions perform both 8- and 16-bit division, signed and unsigned. A single operand is supplied (register or memory operand), which is assumed to be the divisor. Syntax: DIV source If the divisor is 8-bits long, AX is the dividend, AL the quotient, and AH the remainder. If the divisor is 16 bits, DX:AX is the dividend, AX the quotient, and DX the remainder. Dividend / AX DX:AX Divisor Operand Operand = Quotient AL AX Remainder AH DX 7 Lab Manual CSC159 Example 1. 8-bit division (83h/2 = 41h, remainder 1 mov mov div ax , 0083h bl , 2 bl ; dividend ; divisor ; AL = 41h, AH = 01h Example 1: 8 bit register data Div CL If AX register consist value of 005616 and the content of CL register is 1116, after this instruction is executed, the content of register AH will be 0116,while the register AL will have the quotient value of 0516 AX 00 56 AH AL CX 00 11 CH CL Div CL AX 01 05 AH How to calculate: Example 2: 16 bit register data AL 5 11 √0056 55 1 AL AH 8 Lab Manual CSC159 Div CX If AX register consist the value of 0F0516 ,the content of DX register is 068A16 and CX register is 08E916, after these instructions are executed, the content of register AX will have the quotient value of BBE116,while the register DX will have the remainder value of 073C16. AX 0F 05 AH AL DX 06 8A DH DL CX 08 E9 CH CL Div CX AX BB E1 AH AL DX 07 DH 3C DL 9 Lab Manual CSC159 How to calculate: 1. Convert all values inside the registers to decimal numbers. CX=08E916 =(8 x 162) +(E x 161) +(9 x 160) =(8 x 256) +(14 x 16) +(9 x 1) =2048 + 224 +9 =228110 DX : AX=068A16 : 0F0516 =(6 x 166) +(8 x 165) +(A x 164) +(F x 161) +(5x 160) =(6 x 16777216) +(8 x 1048576) +(10 x 65536) +(15 x 256) +(5x 1) =100663296 + 8388608 +655360 +3840+5 =10971110910 2. Do the quotient operation. 48097 2281 √109711109 9124 18471 AX 18248 22310 20529 17819 15967 1852 3. Convert from decimal to Hexadecimal. 16 | 48097 16 | 3006 16 | 187 |11 AX=BBE116 1 14 11 E B B DX 10 Lab Manual CSC159 16 | 1852 16 | 115 |7 DX=073C16 12 3 7 C