multiplication and division assembly language. multiplication use of ax and dx is necessary i.byte...

11
Multiplication and Division Assembly Language

Upload: calvin-harrell

Post on 17-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Multiplication and Division

Assembly Language

Page 2: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Multiplication

• Use of AX and DX is necessaryi. Byte × Byteii. Word × Wordiii. Word × Byte

Page 3: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Byte × Byte

• One of the operand must be in AL• Second can be register/memory• Result in AX• Example-1

MOV AL, 25HMOV BL, 65HMUL BLMOV myresult, AX

Page 4: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

• Example-2MOV AL, DATA1MUL DATA2MOV myresult, AX

Page 5: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Word × Word• One of the operand must be in AX• Second can be register/memory• Result in DXAX• Example-1

DATA3 DW 2387H

DATA4 DW 2F79Hresult 1 DW 2DUP(?)MOV AX, DATA3MUL DATA4MOV RESULT1, AX ;store lower resultMOV RESULT1+2, DX ;store higher result

Page 6: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Word × Byte

• Similar to word × word• AL contains the byte operand• AH must be zero

DATA5 DB 6BHDATA6 DW 12C3HResult3 DW 2DUP(?)MOV AL,DATA5SUB AH,AHMUL DATA6MOV [BX], offset result3MOV [BX], AX MOV [BX]+2, DX

Page 7: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Unsigned Multiplication Summary

Multiplication Operand 1 Operand 2 Result

Byte x byte AL Reg/memory AX

Word x word AX Reg/memory DX:AX

Word x byte AL=byte, AH=0 Reg/memory DX:AX

Page 8: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Unsigned Division Summary

Multiplication Numerator Denominator Quotient Remainder

Byte / byte AL=byet, AH=0 Reg/memory AL AH

Word / word AX=word,DX=0 Reg/memory AX DX

Word / byte AX=word Reg/memory AL AH

Double word/word

DXAX= double word Reg/memory AX DX

Page 9: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Byte/Byte

• Denominator can not be immediate• Example-1

MOV AL,DATASUB AH,AHDIV 10MOV AL, DATA1SUB AH,AHDIV DATA2MOV quot, ALMOV remain, AH

Page 10: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Word/Word

MOV AX,10050SUB DX,DXMOV BX,100DIV BXMOV quot, AXMOV remain,DX

Page 11: Multiplication and Division Assembly Language. Multiplication Use of AX and DX is necessary i.Byte × Byte ii.Word × Word iii.Word × Byte

Word/Byte

MOV AX, 2055MOV CL, 100DIV CLMOV quot, ALMOV remain, AH