Assembly Language Programs for Multiplication and Division
February 22, 2017 | Author: Surekha Pitta | Category: N/A
Short Description
Download Assembly Language Programs for Multiplication and Division...
Description
Assembly Language Programs for Multiplication and Division this part has following programs 5 programmes
1) To write 8086 Assembly Language Program to Multiply two unsigned number.
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
2) To write 8086 Assembly Language Program to multiply two signed number.
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 MOV AX,WORD PTR A[SI] ;Take lower 16bits(5678) of A into AX MUL WORD PTR B[BX+0] ;Multiply AX with lower 16bits of B(1111) and store in AX MOV C[DI],AX ;Move the contents of AX to C[DI] MOV CX,DX ;Move the value of DX to CX MOV AX,WORD PTR A[SI+2] ;Take higher 16bits(1234) of A into AX
MUL WORD PTR B[BX+0] ;Multiply AX with lower 16bits of B(1111)and store in AX ADD CX,AX ;CX=CX+AX MOV C[DI+2],CX ;Move the contents of CX to C[DI+2] MOV CX,DX ;Move contents of DX to CX MOV AX,WORD PTR A[SI] ;Take lower 16bits(5678) of A in AX MUL WORD PTR B[BX+2] ;Multiply contents of AX with higher 16bits of B(1111) ADD WORD PTR C[DI+2],AX ;C[DI+2]=C[DI+2]+AX ADC CX,DX ;CX=CX+DX+CF MOV C[DI+4],AX ;Move contents of AX to C[DI+4] MOV AX,WORD PTR A[SI+2] ;Take higher 16bits of A(1234) into AX MUL WORD PTR B[BX+2] ;Multiply AX with higher 16bits of B(1111) and store in AX ADD CX,AX ;CX=CX+AX MOV WORD PTR C[DI+4],CX ;Move contents of CX to C[DI+4] ADC DX,0000 ;DX=DX+0000+CF MOV C[DI+6],DX ;Move the contents of DX to C[DI+6] INT 03H ; Halt END START
INPUT A = 1234 5678 H B = 1111 1111 H OUTPUT C=0136 BO6E 652F B5F8 H
4) To write 8086 Assembly Language Program to Division two unsigned number.
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
5) To write 8086 Assembly Language Program to Division two signed number.
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 You might be also interested in: :: Assembly Language Programs on array of Hexadecimal numbers :: Assembly Language Programs on strings
View more...
Comments