32
Exp no: 1 Program for 16-bit Addition & Subtraction in 8086 Microprocessor kit Aim : To write an Assembly Language Program for 16-bit Addition & Subtraction in 8086 Microprocessor kit Apparatus Required : 8086 Microprocessor Trainer Kit with Power Supply. Addition: Algorithm: 1. Start the Program 2. Initialize the contents of memory locations in AX & BX registers 3. Initialize the value 00 for CL register. 4. Add the value of AX and BX by using ADD Mnemonics and store the result in a memory location. 5. If there is carry Increment the value of CL register by 1, else move the content of AX to a location for result. 6. Move the value of CL to a location for output. 7. Stop the Program Program: Start: Mov AX,[2000H] Mov BX,[2002H] Mov CL,00

8086 Masm Manual

Embed Size (px)

Citation preview

Page 1: 8086 Masm Manual

Exp no: 1

Program for 16-bit Addition & Subtraction in 8086 Microprocessor kit

Aim:

To write an Assembly Language Program for 16-bit Addition & Subtraction in

8086 Microprocessor kit

Apparatus Required:

8086 Microprocessor Trainer Kit with Power Supply.

Addition:

Algorithm:

1. Start the Program

2. Initialize the contents of memory locations in AX & BX registers

3. Initialize the value 00 for CL register.

4. Add the value of AX and BX by using ADD Mnemonics and store the result in a

memory location.

5. If there is carry Increment the value of CL register by 1, else move the content of

AX to a location for result.

6. Move the value of CL to a location for output.

7. Stop the Program

Program:

Start: Mov AX,[2000H]

Mov BX,[2002H]

Mov CL,00

ADD AX,BX

JNC L1

INC CL

L1: Mov [2006H],AX

Mov [2008H],CL

End: HLT

Page 2: 8086 Masm Manual

Subtraction:

Algorithm:

1. Start the Program

2. Initialize the contents of memory locations in AX & BX registers

3. Initialize the value 00 for CL register.

4. Subtract the value of AX and BX by using SUB Mnemonics and store the result in

a memory location.

5. If there is carry Increment the value of CL register by 1, else move the content of

AX to a location for result.

6. Move the value of CL to a location for output.

7. Stop the Program

Program:

Strat: Mov AX,[2000H]

Mov BX,[2002H]

Mov CL,00H

SUB AX,BX

JNC L1

INC CL

L1: Mov [2006H],AX

Mov [2008H],CL

End: HLT

Result:

Thus the ALP to add and subtract 16 bit number using 8086 Microprocessor Kit

was written and executed successfully.

Page 3: 8086 Masm Manual

Exp no: 2

Program for 16-bit Division & Multiplication in 8086 Microprocessor kit.

Aim:

To write an Assembly Language Program for 16-bit Division & Multiplication in

8086 Microprocessor kit.

Apparatus Required:

8086 Microprocessor Trainer Kit with Power Supply.

Multiplication:

Algorithm:

1. start the program

2. initialize the contents for AX and BX from memory locations

3. Multiple the AX and BX value using MUL Mnemonics and store the result in a

memory location.

4. move the content of AX and DX to memory locations to check the result.

5. stop the program

Program:

Start: mov AX,[2000H]

mov BX,[2002H]

MUL BX

mov [2006H],AX

mov [2008H],DX

end: HLT

Division:

Algorithm:

1. start the program

Page 4: 8086 Masm Manual

2. initialize the contents for AX and BX from memory locations

3. Multiple the AX and BX value using MUL Mnemonics and store the result in a

memory location.

4. move the content of AX and DX to memory locations to check the result.

5. stop the program

Program:

Start: mov AX,[2000H]

mov BX,[2002H]

DIV BX

mov [2006H],AX

mov [2008H],DX

end: HLT

Result:

Thus the ALP to multiple and divide 16 bit number using 8086 Microprocessor Kit

was written and executed successfully.

Page 5: 8086 Masm Manual

Exp no: 3

Program for Ascending order and Descending order in 8086 Microprocessor kit.

Aim:

To write an Assembly Language Program for Ascending order and Descending

order in 8086 using MASM software.

Apparatus Required:

MASM Software

Ascending order:

Algorithm:

1. Start the program

2. Declare the set of elements in list and initialize the count value in the data

segment.

3. In code segment(CS), move the data segment values to data segment register.

4. Initialize the starting address of list to BX and count values to CX register.

5. Get the succesive elements in source index(BX) and sort the elements in

ascending order.

6. Termination interrupt is performed to terminate the program.

7. Stop the program.

Program:

Assume CS:code,DS:DataData Segment #Open the data segmentList dw 05h,07h,06h,02h #Declare the set of values to listCount equ 04h #Assign the control valuesData ends #end of data segmentCode segment #Open code segment

Start: Mov AX,data #Assign the value of data to DS through an

Page 6: 8086 Masm Manual

accumulatorMov DS,AX #Iniatilize AX value to DSMov DX,count-1 #Initialize the count register

L3 Mov CX,DX #Initialize the DX value to CXMov BX,offset list #Assign the first address of list to bx

L2 Mov AX,[BX] #Move the first value to AXCmp AX,[BX+2] #Compare AX with successive elementJL L1 #Jump if AX < [BX+2] the goto L1XCHG [BX+02],AX #excahnge the values of [BX],AXXCHG [BX],AX #excahnge the values of [BX],AX

L1 Add BX,02h #increment the value BX valueLoop L2 #goto L2Dec DX #Decrement by the value DxJNZ L3 #if DX is No Zere, goto L3Mov AH,4Ch #interrupt signalInt 21h # interrupt signalCode ends #end the code segment

End start #end of start

Descending order:

Algorithm:

1. Start the program

2. Declare the set of elements in list and initialize the count value in the data

segment.

3. In code segment(CS), move the data segment values to data segment register.

4. Initialize the starting address of list to BX and count values to CX register.

5. Get the succesive elements in source index(BX) and sort the elements in

descending order.

6. Termination interrupt is performed to terminate the program.

7. Stop the program.

Program:

Assume CS:code,DS:DataData Segment #Open the data segmentList dw 05h,07h,06h,02h #Declare the set of values to list

Page 7: 8086 Masm Manual

Count equ 04h #Assign the control valuesData ends #end of data segmentCode segment #Open code segment

Start: Mov AX,data #Assign the value of data to DS through an accumulator

Mov DS,AX #Iniatilize AX value to DSMov DX,count-1 #Initialize the count register

L3 Mov CX,DX #Initialize the DX value to CXMov BX,offset list #Assign the first address of list to bx

L2 Mov AX,[BX] #Move the first value to AXCmp AX,[BX+2] #Compare AX with successive elementJG L1 #Jump if AX > [BX+2] the goto L1XCHG [BX+02],AX #excahnge the values of [BX],AXXCHG [BX],AX #excahnge the values of [BX],AX

L1 Add BX,02h #increment the value BX valueLoop L2 #goto L2Dec DX #Decrement by the value DxJNZ L3 #if DX is No Zere, goto L3Mov AH,4Ch #interrupt signalInt 21h # interrupt signalCode ends #end the code segment

End start #end of start

Result:

Thus , the Assembly language program for sort the elements in ascending and

descending order was written , executed successfully and the output was verified.

Page 8: 8086 Masm Manual

Exp no:4

Program for String copy.

Aim:

To write an Assembly Language Program for String Copy in 8086 using MASM

software.

Apparatus Required:

MASM Software

Algorithm:

1. Start the program

2. In the data segment initialize the elements in array (source), initialize the

destination address to des and counter value.

3. In code segment(CS), move the data segment value to data segment register.

4. Initialize the starting address of source to SI and move the des, count value to

DI,CX.

5. Swap the elements to specified address with the use of cld rep MOVSW

command.

6. Use interrupt to terminate the program.

7. Stop the program.

Program:

Assume CS:code,DS:Data

Page 9: 8086 Masm Manual

Data segmentSource dw 01h,05h,06hDes equ 3000hCount equ 03hData endsCod segment

Start: Mov AX, dataMov ds, AXMov SI, offset sourceMov d1,desCLDRep movswMov ab,4chInt 21h

End: Code endsEnd start

Result:

Thus, the ALP for string copy using 8086 was executed successfully and the

output was verified.

Page 10: 8086 Masm Manual

Exp no: 5

Program for Reverse the String.

Aim:

To write an Assembly Language Program for Reverse the String in 8086 using

MASM software.

Apparatus Required:

MASM Software

Algorithm:

1. Start the program

2. In the data segment, initialize the elements in array named as src, initialize the

empty array size as ds and the count value.

3. In code segment (CS), move the data segment value to data segment register.

4. Move the count value (count +1) to count register and define the offset address

of des to di and move the 06h to dx.

5. Define the offset address of src to s1 then move the s1 to bx then bx to dx.

6. Decrement the destination index then subtract the source index value.

7. Decrement the CX if nonzero goto step 5.

8. Stop the program.

Program:

Assume cs: code, ds: dataData segmentsrc dw 09h,08h,07hdes dw 10h

Page 11: 8086 Masm Manual

count equ 03hdata ends

code segmentstart: mov ax, data

mov ds, axmov cx,count+1mov di, offset desmov dx, 06hmov si, offset srcadd si, dx

loop: mov bx, [si]mov [di], bxadd di, 02hdec cxjnz loopmov ah, 4chint 21hcode endsend start.

RESULT:Thus the ALP for reverse the string in 8086 was written and executed

successfully and the output was verified.

Page 12: 8086 Masm Manual

Exp no:6

Program for Searching an Element.

Aim:

To write an Assembly Language Program for Searching the given element in

8086 using MASM software.

Apparatus Required:

MASM Software

Algorithm:

1. Start the program.

2. Initialize all the elements of array and named them.

3. Define the messages in disp1 and disp2.

4. Initialize the counter value in data segment.

5. If counter reaches 0, goto step6, else do the following steps

Ø  Load the list to accumulator and then load the counter value to counter register

Ø  Compare the accumulator with given element, if it is present display the message as

“data is present” else jump to loop.

Ø  If it is not present , display the message as “Data is not present”

6. Stop the program.

Page 13: 8086 Masm Manual

Program:

Assume cs: code, ds: dataData segmentList dw 05h, 06h, 07h, 08h, 09hDisp1 db “Data is present”,”&”Disp2 db “Data is not present”,”&”Count equ 05hData ends

Code segmentOrg 1000h

Start: mov ax, datamov ds, dxmov si, offset listmov cx, count

loop: mov ax, [si]cmp ax, 05hjz loop1add si, 02hdec cxjnz loopjmp loop2

loop1: mov dx, offset disp1jmp loop3

loop2: mov dx, offset disp2jmp loop3

loop3: mov ah, 09hint 21hmov ah, 4chint 21hcode ends

endResult:

Thus, the ALP for searching an element was written and executed successfully and the output was verified.

Page 14: 8086 Masm Manual

Exp no:7

Program for File Manipulation in 8086.

Aim:

To write an Assembly Language Program for File Manipulation in 8086 using

MASM software.

Apparatus Required:

MASM Software

Algorithm:

1. Start the program

2. In the data segment define byte for filename and named as FN

3. In code segment, move the data segment values to ds register

4. Initialize the address of FN to DX register.

5. Interrupt command (3ch) is used to pen a file.

6. Perform the termination using terminate interrupt for program.

7. Stop the program.

Program:

Assume cs: code, ds: dataData segmentFN DB “siva.txt”,”$”Data endsCode segment

Page 15: 8086 Masm Manual

Start: mov ax, datamov ds, axmov dx, offset FNmov cx, 00hmov ah,3chint 21hcode ends

end start

Result:Thus the ALP for file manipulation in 8086 using MASM software was written and

executed successfully and the output was verified.

Exp no: 8

Interfacing of Stepper Motor controller using 8086 Microprocessor kit.

Aim:

To write an Assembly Language Program for run Stepper Motor in clockwise and

anticlockwise direction using 8086 Microprocessor kit.

Apparatus Required:

Microprocessor kit, Power cable, stepper motor kit and Data cable.

Algorithm:

1. Start the program

2. Initialize a memory location to DI

3. Initialize the counter value as 04

4. Move the content of DI to AL

5. Write the AL value as 00h to port

6. Move the content of memory location to DX.

7. Decrement the DX value and if it is no zero call delay program.

8. Increment the DI value and goto step 4

9. Goto step 2.

10.Stop the program

Page 16: 8086 Masm Manual

Clockwise direction values: - 09h, 05h, 06h , 0Ah, 09h

Anticlockwise direction values: - 09h , 0Ah, 06h, 05h, 09h

Program:

L2: MOV DI, [1018h]

MOV CL, 04

L1: MOV AL, [DI]

OUT 00, AL

MOV DX, [1010h]

delay: DEC DX

JNZ delay

INC DI

LOOP L1

JUMP L2

HLT

Clockwise direction values: - 09h, 05h, 06h, 0Ah, 09h

Anticlockwise direction values: - 09h, 0Ah, 06h, 05h, 09h

Result:

Thus, the assembly language program in 8086 for stepper motor in clockwise

and anticlockwise was written and executed successfully and the output was verified.

Page 17: 8086 Masm Manual

Exp no:9

Interfacing of Keyboard / Display (8279) using Microprocessor kit.

Aim:

To write an Assembly Language Program for Interfacing of Keyboard / Display

(8279) in 8086 Microprocessor kit for displaying character ‘A’ and rolling display.

Apparatus Required:

Microprocessor kit, Power cable, 8279 keyboard/display kit and Data cable.

Algorithm for Character Display of ‘A’:

1. Start the program

2. Initialize the AL as 00h and write the AL value to port.

3. Enter the value for Character “A” as 88h

4. Write the value to output port

5. Goto step 4.

6. Stop the program.

Program for Character Display of ‘A’

Page 18: 8086 Masm Manual

MOV AL,00h

OUT C2,AL

MOV AL, CCh

OUT C2,AL

MOV AL,90h

OUT C2,AL

MOV AL,88h

OUT C0,AL

MOV AL,FFh

OUT C2,AL

MOV CX,0006h

L1: OUT C0,AL

LOOP L1

HLT

Algorithm for Rolling Display:

1. Start the program

2. Set the counter value for number of characters to roll and write the value port.

3. Move the 10h, CCh, 90h value for number of characters to roll and write the

value port.

4. Move the roll character values to source index(SI) and write into port.

5. Move the value 0A0Fh to the register DX

6. Decrement it till reach 00h.

7. If DX is no zero goto step 6 and increment Source index to accept next value

8. Goto step 4.

9. Stop the program.

Program for Rolling Display:

Page 19: 8086 Masm Manual

START: MOV SI,[2000h] MOV CX, 000FhMOV AL, 10hOUT C2, ALMOV AL, CChOUT C2,ALMOV AL,90hOUT C2,AL L1: MOV AL,[SI]OUT C0,ALMOV DX,0A0Fh L2: DEC DX JNZ L2 INC SI LOOP L1 JMP START

Result:

Thus, the assembly language program in 8086 to display the character ‘A’

and roll the display was written and executed successfully and the output was verified.

Exp no:10

Interfacing of ADC with 8086 Microprocessor kit.

Aim :

To write an Assembly Language Program for Interfacing ADC in 8086

Microprocessor kit.

Apparatus Required:

Microprocessor kit, Power cable, ADC kit and Data cable

Algorithm for ADC:

1.      Start the program.

2.      Move the control register values to AL register and write those values to ports.

3.      Move the initial value 00yh to AL and write the value to port.

4.      Accept the analog value from ADC kit and store it in AL.

5.      Compare the AL with 01h, if it true and no zero goto step 4.

Page 20: 8086 Masm Manual

6.      Accept the analog value from port and store it in AL.

7.      Move the value in AL to a memory Location [1500h].

8.      Stop the program.

Program for ADC:

MOV AL,10h

OUT C8,AL

MOV AL,18h

OUT C8,AL

MOV AL,01h

OUT D0,AL

MOV AL,00h

MOV AL,00h

MOV AL,00h

MOV AL,00h

OUT D0,AL

L1: IN AL,D8

AND AL,01h

CMP AL,01h

JNZ L1

IN AL,C0

MOV BX,1500h

MOV [BX],AL

HLT

Result :

Thus, the assembly language program in 8086 to convert the analog value

to digital using ADC convertor was written and executed successfully and the output

was verified.

Page 21: 8086 Masm Manual

Exp no:11

Interfacing of DAC with 8086 Microprocessor kit.

Aim :

To write an Assembly Language Program for Interfacing of DAC with 8086

Microprocessor kit for generating waveforms such as sine wave, triangular wave, saw

tooth wave and square wave.

Apparatus Required:

Microprocessor kit, Power cable, DAC kit and Data cable.

Algorithm:

SAW TOOTH WAVE:

1. Start the program

2. Initialize the register AL as 00h

3. Write the initial value in port

4. Increment the AL value and check if no zero goto step 3.

Page 22: 8086 Masm Manual

5. Stop the program

TRIANGULAR WAVE:

1. Start the program

2. Initialize the BL register as 00h

3. Move the contents of BL to AL

4. Write the AL value in Port

5. Increment the BL value and check if it is no zero goto step 2

6. Initialize the BL register as FFh

7. Move the contents of BL to AL

8. Write the AL value in Port

9. Decrement the BL register and check if it is zero goto step 6

10.Goto step 1

11.Stop the program

SQUARE WAVE:

1. Start the program

2. Initialize the AL as 00h

3. Write the port value of AL register and goto step

4. Initialize as AL as highest value and write the AL value to port and call step 6.

5. Goto step 2

6. Move the contents of 05FFh to CX and goto step 5

7. Stop the program

SINE WAVE :

1. Start the program

Page 23: 8086 Masm Manual

2. Initialize the look up table in a memory location

3. Initialize the value 46h

4. Move the contents of BX to AL

5. Increment the BX value

6. Write the AL value to ports goto step 4

7. Goto step 2

8. Stop the program

Program:

SAW TOOTH WAVE:

START : MOV AL,00h L1 : OUT C0,ALINC ALJNZ L1JMP START

TRIANGULAR WAVE: L3: MOV BL,00hL1: MOV AL,BLOUT C8,ALINC BLJNZ L1MOV BL,FFhL2: MOV AL,BLOUT C8,ALDEC BLJNZ L2JMP L3

SQUARE WAVE: START: MOV AL,00hOUT C8,ALCALL ROUTINEMOV AL,FFhOUT C8,ALCALL ROUTINEJMP STARTROUTINE : MOV CX,05FFh

Page 24: 8086 Masm Manual

L3 : LOOP L3 RET

SINE WAVE GENERATION:

START: MOV BX,1100h MOV CL,46h L1: MOV AL,[BX] OUT C0,AL INC BX LOOP L1 JMP START

Result :

Thus, the assembly language program in 8086 to convert the digital

values to analog using DAC convertor for generating waveforms such as sine wave,

triangular wave, saw tooth wave and square wave was written and executed

successfully and the output was verified.

Exp no:12

Interfacing of Timer with 8086 Microprocessor kit.

Aim:

To write an Assembly Language Program for Interfacing of Timer with 8086

Microprocessor kit.

Apparatus Required:

Microprocessor kit, Power cable, Timer kit and Data cable.

Algorithm:

Page 25: 8086 Masm Manual

1.      Start the program.

2.      Move the counter value to AL either it may be even or odd and write the AL value to

output port.

3.      Move the highest value (10h) to AL either it may be even or odd and write the AL value

to output port.

4.      Move the initial value (00h) to AL either it may be even or odd and write the AL value to

output port.

5.      Stop the program.

Program:

Mov AL, 36h

Out C8, AL

Mov AL, 10h

Out C8, AL

Mov AL, 00h

Out C8, AL

HLT.

Result:

Thus, the assembly language program in 8086 microprocessor interface

with timer was written and executed successfully and the output was verified.