Google

Jan 1, 2008

Assembly Language Programs to compute an expression

AIM: To write 8086 Assembly Language Program to compute Z = (A + B) × C × (D ÷ E).

Program

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

A DB 56H ; Initialize A to 56H

B DB 78H ; Initialize B to 78H

C DB 05H ; Initialize C to 05H

D DB 0ACH ; Initialize D to ACH

E DB 04H ; Initialize E to 04H

Z DW ? ; Declare Z



.CODE ; Code segment starts

START:

MOV AX,@DATA ;Initialize DS

MOV DS,AX

MOV AL,A ;Move contents of A to AL

MOV BL,B ;Move contents of B to BL

ADD AL,BL ;AL = AL + BL

MOV CL,C ;Move contents of C to CL

MUL CL ; AL = AL×CL

MOV BX,AX ;Move contents of AX to BX

MOV AX,0000 ;Move 0000 to AX

MOV AL,D ;Move contents of D to AL

MOV CL,E ;Move contents of E to CL

DIV CL ; AL = AL ÷ CL

MUL BX ; AX = AX×BX

MOV Z[SI+2],AX ;Move contents of Z to AX

MOV Z[SI],DX ;Move contents of Z1 to DX

INT 03H ; Halt

END START


INPUT:

A = 56H

B =78H

C = 05H

D = 0ACH

E = 04H

OUTPUT:
Z = 0000 0AD02 H

AIM: To write 8086 Assembly Language Program to compute Z = ∑ Xi × Yi.

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

X DB 1H, 2H, 3H ; Declare array of 3bytes named X

Y DB 4H, 5H, 6H ; Declare array of 3bytes named Y

Z DW ? ; Reserve 1word by name Z

.CODE ; Code segment starts

START:

MOV AX,@DATA ; Initialize DS

MOV DS,AX

MOV DX,0000H ;Initialize DX to 0000h

MOV BX,0000H ;Initialize BX to 0000h

MOV SI,0000H ;Initialize SI to 0000h

MOV CL,03H ;Initialize CL to 03h

UP:

MOV AL,X[BX] ;Move the elements of X to AL

MUL BYTE PTR Y[SI] ;Multiply AL with the contents of Y

ADD DX,AX ;DX=DX+AX+CF

INC BX ; Increment BX by 1

INC SI ; Increment SI by 1

DEC CL ; Decrement CL by 1

JNZ UP ; If zero flag is not zero jump to label up

MOV Z,DX ;Move the contents of DX to Z

INT 03H ; Halt

END START

INPUT:

X =1H, 2H, 3H

Y = 4H, 5H, 6H



OUTPUT:

Z = 0020 H


AIM: To write 8086 Assembly Language Program to compute Z = ∑ Xi2.

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

X DB 0FFH, 0FFH, 0FFH ; Initialize X with 3bytes

Z DW ? ; Initialize Z

.CODE ; Code segment starts

START:

MOV AX,@DATA ;Initialize AX

MOV DS,AX

MOV DX,0000H ;Initialize DX to 0000h

MOV BX,0000H ;Initialize BX to 0000h

MOV CH,03H ;Initialize CH to 03h

MOV CL,00H ;Initialize CL to 00h

MOV DX,0000H ;Initialize DX to 0000h

MOV SI,0000H ;Initialize SI to 0000h

UP: MOV AL,X[BX] ;Move contents of X[BX] to AL

MUL BYTE PTR X[BX] ;Multiply AL with contents of X[BX]

ADD DX,AX ;DX=DX+AX

ADC CL,00H ;CL=CL+00+CF

INC BX ; Increment BX by 1

DEC CH ; Decrement CH by 1

JNZ UP ; If zero flag is not zero jump to up

MOV Z[SI],CX ;Move contents of CX to Z[SI]

MOV Z[SI+2],DX ;Move contents of DX to Z[SI+2]

INT 03H ; Halt

END START


INPUT:

Z = FF2 + FF2 + FF2 = 2FA03 H

X =FFH, FFH, FFH

OUTPUT:

Z = 0002 FA03 H

AIM: To write 8086 Assembly Language Program to compute Z = ∑ Xi3.

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

A DB 0FFH, 0FFH, 0FFH ; Initialize an array A

Z DW ?

.CODE ; Code segment starts

START:

MOV AX,@DATA ; Initialize the data segment

MOV DS,AX

MOV BX,0000H ; Initialize the BX register

MOV CX,03H ; CX register is decremented whenever loop instruction executes

MOV SI,00H ; Initialize SI & DI

MOV DI,0000H

UP: XOR AX,AX ; Clear AX register

MOV AL,A[SI] ;Move the element in array A pointed by SI to AL

MOV BX,AX ;Move AX register to BX

MUL AX ; Multiplies AX with AX

MUL BX ; Multiplies BX with AX and stores the result in DX:AX

ADD Z[DI+2],AX ; Adds lower 16 bits of z with AX

ADC Z[DI],DX ; Adds higher 16 bits of z with DX

ADD SI,01 ; Increment SI by 1

LOOP UP ; Goes up until CX becomes zero

INT 03H ; Halt

END START

INPUT:

Z = FF3 + FF3 + FF3 = 02F7 08FD H

ARRAY OF 3 NO'S (FFH, FFH, FFH)

OUTPUT:

Z = 02F7 08FD H

You might be also interested in:

:: MASM 611 SOFTWARE

:: Traffic light control system using 8086

:: Interfacing Stepper Motor to 8086 using 8255

1 comment:

Unknown said...

Thanks for sharing your info. I truly appreciate your efforts and I am waiting for your next post thank you once again.
Application Packaging Course Offered From Hyderabad India