• No results found

Assembly Language Programs for Multiplication and Division

N/A
N/A
Protected

Academic year: 2021

Share "Assembly Language Programs for Multiplication and Division"

Copied!
5
0
0

Loading.... (view fulltext now)

Full text

(1)

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

(2)

.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

(3)

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

(4)

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

(5)

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

References

Related documents

If {I/my child} test negative for a variant known to be present in other members of {my/my child’s family}, this result rules out a diagnosis of the same genetic disorder in

THE KEY STAGE 4 PROGRAMME MEANINGFUL WORK PLACEMENTS PROJECT-BASED LEARNING AND ADDITIONAL QUALIFICATIONS INCLUDING BTECS Logistics Sustainable technologies

On the other hand, many older women who have lived in these areas for a number of years (some came as young brides) are now finding it difficult to maintain their property, be it

M2: Functional Materials and Composites for Engineering Applications M3: Advanced metallurgy & rapid manufacturing of metalic parts M4: Mechanical testing..

 Work breakdown structure: The process of breaking the project into easily identifiable major systems, their Abstract: This thesis is based on analysis of pre-engineered

But even when I am persuaded that there is particular evidence that some contemporary privacy scholarship or policy has actually responded to and improved from

A theoretical expression of the photocurrent density Jph is presented as a calibrated function, diffusion length depending of incident angle values, it intercepts

 Markets  are  volatile  and  forecasting  models  always