Professional Documents
Culture Documents
Assembly Language Programs For Multiplication and Division
Assembly Language Programs For Multiplication and Division
MODEL SMALL
.STACK 100
.DATA ; Data Segment to initialize the variables
A DW 0FF87H ; First signed number A = (-79H) = FF87H (2'Compliment form)
B DW 0FF84H ; Second signed number B = (-7CH) = FF84H (2'Compliment form)
C DW ? ; Variable C to store result
.CODE
START:
MOV AX,@DATA
MOV DS,AX ; Initialize data segment
MOV SI,0000H ; Initialize SI to 0000H
MOV AX,A ;Take first number A in AX register
MOV CX,B ;Take second number B in CX register
MUL CX ; Performs unsigned Multiplication DX:AX = AX CX
MOV C[SI],DX ; Store higher 16-bit result
MOV C[SI+2],AX ; Store lower 16-bit result
INT 03H
END START
Input:
FF87 FF84 = FF0B 3A9C H
A = 0FF87 H (2'compliment of -79H)
B = 0FF84 H (2'compliment of -7CH)
Output:
C = FF0B 3A9C H
MODEL SMALL
.STACK 100
.DATA ; Data Segment to initialize the variables
A DW 0FF87H ; First signed number A = (-79H) = FF87H (2'Compliment form)
B DW 0FF84H ; Second signed number B = (-7CH) = FF84H (2'Compliment form)
C DW ? ; Variable C to store result
.CODE
START:
MOV AX,@DATA
MOV DS,AX ;Initialize data segment
MOV SI,0000H ;Initialize SI to 0000H
MOV AX,A ;Take first number A in AX register
MOV CX,B ;Take second number B in CX register
IMUL CX ; Performs signed Multiplication DX:AX = AX CX
MOV C[SI],DX ;Store higher 16-bit result
MOV C[SI+2],AX ;Store lower 16-bit result
INT 03H
END START
Input:
-79 -7C = 3A9C H
A = 0FF87 H (2'compliment of -79H)
B = 0FF84 H (2'compliment of -7CH)
Output:
C = 0000 3A9C H
3) To write 8086 Assembly Language Program to multiply two 32-bit unsigned numbers.
MODEL SMALL
.STACK 100
.DATA ; Data segment starts
A DW 5678H, 1234H, 5 DUP(0) ;A is 32bit number A=1234 5678
b DW 1111H, 1111H, 5 DUP(0) ;B is 32bit number B=1111 1111
C DW 4 DUP(?) ; Reserve 4 words of uninitialized data space to an offset C
.CODE
START:
MOV AX,@DATA ;Initialize DS
MOV DS,AX
MOV SI,OFFSET A ;Point to first number in A
END START
INPUT
A = 1234 5678 H
B = 1111 1111 H
OUTPUT
C=0136 BO6E 652F B5F8 H
MODEL SMALL
.STACK 100
.DATA ; Data Segment to initialize the variables
Dividend DW 1234H, 5678H ; Dividend = 1234 5678 H
Divisor DW 270FH ; Divisor = 207FH
Quotient DW ? ; Variable Quotient to store Quotient
Reminder DW ? ; Variable Reminder to store Reminder
.CODE
START:
MOV AX,@DATA
MOV DS,AX ;Initialize data segment
MOV SI,0000H ;Initialize SI to 0000H
MOV DX,Dividend[SI] ;Take higher 16-bit number which is to be divided in DX register
MOV AX,Dividend[SI+2] ;Take lower 16-bit number which is to be divided in AX register
MOV CX,Divisor ;Take divisor in CX register
DIV CX ; Performs unsigned Division DX:AX CX
; AX = Quotient DX = Reminder
MOV Reminder,DX ;Store Reminder
MOV Quotient,AX ;Store Quotient
INT 03H
END START
Input:
12345678H 207FH = 7751H
Dividend = 1234 5678 H
Divisor = 207F H
Output:
Quotient = 7751 H
Reminder = 01B9 H
MODEL SMALL
.STACK 100
.DATA ; Data Segment to initialize the variables
Dividend DW 0FFFFH, 0FF88H ; Dividend = (-78H) = FFFF FF88H (2'Compliment form)
Divisor DW 0006H ; Divisor = 0006H
Quotient DW ? ; Variable Quotient to store Quotient
Reminder DW ? ; Variable Reminder to store Reminder
.CODE
START:
MOV AX,@DATA
MOV DS,AX ;Initialize data segment
MOV SI,0000H ;Initialize SI to 0000H
MOV DX,Dividend[SI] ;Take higher 16-bit number which is to be divided in DX register
MOV AX,Dividend[SI+2] ;Take lower 16-bit number which is to be divided in AX register
MOV CX,Divisor ;Take divisor in CX register
IDIV CX ; Performs signed Division DX:AX CX
; AX = Quotient DX = Reminder
MOV Reminder,DX ;Store Reminder
MOV Quotient,AX ;Store Quotient
INT 03H
END START
Input:
-78H 06H = -14H
Dividend = FFFF FF87 H (32-bit 2'compliment of -78H)
Divisor = 0006 H
Output:
Quotient = FFEC H (2'compliment of -14H)
Reminder = 0000 H