Multiplication and Division Assembly Language
Multiplication Use of AX and DX is necessary Byte × Byte Word × Word Word × Byte
Byte × Byte One of the operand must be in AL Second can be register/memory Result in AX Example-1 MOV AL, 25H MOV BL, 65H MUL BL MOV myresult, AX
Example-2 MOV AL, DATA1 MUL DATA2 MOV myresult, AX
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 2F79H result 1 DW 2DUP(?) MOV AX, DATA3 MUL DATA4 MOV RESULT1, AX ;store lower result MOV RESULT1+2, DX ;store higher result
Word × Byte Similar to word × word AL contains the byte operand AH must be zero DATA5 DB 6BH DATA6 DW 12C3H Result3 DW 2DUP(?) MOV AL,DATA5 SUB AH,AH MUL DATA6 MOV [BX], offset result3 MOV [BX], AX MOV [BX]+2, DX
Unsigned Multiplication Summary Operand 1 Operand 2 Result Byte x byte AL Reg/memory AX Word x word DX:AX Word x byte AL=byte, AH=0
Unsigned Division Summary Multiplication Numerator Denominator Quotient Remainder Byte / byte AL=byet, AH=0 Reg/memory AL AH Word / word AX=word,DX=0 AX DX Word / byte AX=word Double word/word DXAX= double word
Byte/Byte Denominator can not be immediate Example-1 MOV AL,DATA SUB AH,AH DIV 10 MOV AL, DATA1 DIV DATA2 MOV quot, AL MOV remain, AH
Word/Word MOV AX,10050 SUB DX,DX MOV BX,100 DIV BX MOV quot, AX MOV remain,DX
Word/Byte MOV AX, 2055 MOV CL, 100 DIV CL MOV quot, AL MOV remain, AH