0% found this document useful (0 votes)
9 views

10-Assembly Language example programs-08-01-2025

The document provides a detailed guide on various programs using the 8086 Microprocessor emulator, focusing on basic arithmetic and logical operations such as addition, subtraction, multiplication, division, and logical operations. It includes algorithms, source codes, sample inputs and outputs for each operation, as well as additional experiments like binary to BCD conversion, sorting, string searching, data transfer operations, password checking, and printing RAM size and system date. Each section concludes with results and questions for further exploration related to the experiments.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

10-Assembly Language example programs-08-01-2025

The document provides a detailed guide on various programs using the 8086 Microprocessor emulator, focusing on basic arithmetic and logical operations such as addition, subtraction, multiplication, division, and logical operations. It includes algorithms, source codes, sample inputs and outputs for each operation, as well as additional experiments like binary to BCD conversion, sorting, string searching, data transfer operations, password checking, and printing RAM size and system date. Each section concludes with results and questions for further exploration related to the experiments.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

B.

8086 PROGRAMS

26
EXP NO:9
BASIC ARITHMETIC & LOGICAL OPERATIONS

OBJECTIVE
To perform the basic arithmetic and logical operations using the 8086 Microprocessor
emulator

9A. ADDITION

ALGORITHM
Step 1. Allocate some space for the result in data segment
step 2. In code segment, store accumulator with some value
step 3. Store B register with some value
step 4. Add the register content with accumulator
step 5. Result is stored in accumulator
step 6. The result is stored in required memory location

SOURCE CODE
Start: mov AX, 05H
mov BX, 03H
ADD AX,BX
end: HLT

SAMPLE INPUTS& OUTPUTS


Before Execution: After Execution:
AX = 0005H AX = 0008H
BX = 0003H

9B. SUBTRACTION

ALGORITHM
a) Start the program.
b) Allocate some space for the result in data segment
c) In code segment, store accumulator with some value
d) Store B register with some value
e) Subtract the register content from the accumulator
f) Result is stored in accumulator
g) The result is stored in required memory location
h) Stop the program.

SOURCE CODE
Start: mov AX, 05H
mov BX, 03H
SUB AX,BX
end: HLT

27
SAMPLE INPUTS & OUTPUTS
INPUT: 0005H ,0003H
OUTPUT: 0002H

9.C MULTIPLICATION

ALGORITHM
a) Start the program
b) Allocate some space for the result in data segment
c) In code segment,store accumulator with some value
d) Store B register with some value
e) Multiply the register content with accumulator
f) Result is stored in accumulator
g) The result is stored in required memory location
h) Stop the program.

SOURCE CODE
Start: mov AX, 05H
mov BX, 03H
MUL AX,BX
end: HLT

SAMPLE INPUTS & OUTPUTS


INPUT: 0006H, 0004H
OUTPUT: 0018H

9D.DIVISION

ALGORITHM:
a) Start the program.
b) Allocate some space for the result in data segment
c) Take 2 data as 2 inputs in 2 different registers
d) Perform the Division operation.
e) The quotient is stored in accumulator and the remainder is stored in D register
f) Store the remainder and quotient in required memory location.
g) Display the result.
h) Stop the program.

SOURCE CODE
Start: mov AX, 08H
mov BX, 02H
DIV AX,BX
end: HLT

28
SAMPLE INPUTS & OUTPUTS

INPUT: 0008H ,0002H


OUTPUT: 0004H

9E.LOGICAL AND OPERATION

ALGORITHM
Step 1. Allocate some space for the result in data segment
step 2. In code segment, store accumulator with some value
step 3. Store B register with some value
step 4. Perform AND operation on the register content with accumulator
step 5. Result is stored in accumulator
step 6. The result is stored in required memory location

SOURCE CODE
Start: mov AX, 01H
mov BX, 01H
AND AX,BX
End: HLT

SAMPLE INPUTS & OUTPUTS


Before Execution: After Execution:
AX = 0001H AX = 0001H
BX = 0001H

9F. LOGICAL OR OPERATION

ALGORITHM
Step 1. Allocate some space for the result in data segment
step 2. In code segment, store accumulator with some value
step 3. Store B register with some value
step 4. Perform OR operation on register content with accumulator
step 5. Result is stored in accumulator
step 6. The result is stored in required memory location.

SOURCE CODE
Start: mov AX, 01H
mov BX, 00H
OR AX,BX
end: HLT

29
SAMPLE INPUTS & OUTPUTS
Before Execution: After Execution:
AX = 0001H AX = 0001H
BX = 0000H

RESULT
The machine programs for basic arithmetic and logical operations were successfully
implemented Using8086 emulator.

QUESTIONS RELATED TO THE NEXT EXPERIMENT

1.How to convert binary to BCD by giving the input in hexa?


2.What instruction is used to scan the character of string?
3.What is procedure ?
4.What is the use of data segment and how to get data as array?
5.How to display a msg?

30
EXP. NO: 10 A
CODE CONVERSIONS – BINARY TO BCD
OBJECTIVE
To convert a given binary to BCD.

ALGORITHM:
Step 1: Initialize the data to the data segment.
Step 2: Move the input to AX register.
Step 3: Move 64 to CL register
Step 4: Divide AL, CL value
Step 5: Increment memory by 1 and move AL value
Step 6: Move AH value to AL
Step 7: Move 0A to CL register
Step 8: Divide the AL, CL
Step 9: Rotate CL register 4 times
Step 10: Add AH, AL
Step 11: Store the resultant in memory location.

SOURCE CODE
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
BIN DW 01A9H
BCD DB 2 DUP (0)
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV AX, BIN
MOV CL, 64H
DIV CL
MOV BCD+1, AL
MOV AL, AH
MOV AH, 00H
MOV CL, 0AH
DIV CL
MOV CL, 04
ROR AL, CL
ADD AL, AH
MOV AH, 4CH
INT 21H
CODE ENDS
END START
OUTPUT
INPUT : 01A9H
OUTPUT : 0425
RESULT
Thus the program to convert a binary to BCD was executed.
31
EX. NO: 10 B
SORTING

OBJECTIVE
To sort the given number in ascending order using 8086.

ALGORITHM
Step 1: Get the input number from memory and move it to AL register
Step2: Move the count value to DX register (outer loop)
Step3: Decrement the value of DX by one and move it to CX register (inner loop)
Step4: Compare the AL and the next element in the memory
Step5: If CY=1 then AL is less than next element
Step6: If CY=0 then AL is greater than next element so exchange both value
Step7: Continue the step3 to step7 until CX and DX goes to zero.
Step8: Store the resultant value

SOURCE CODE
ASSUME CS: CODE, DS:DATA
DATA SEGMENT
SERIES DB 81H,82H,93H,95H,10H,56H,33H,99H,13H,44H
COUNT DW 10H
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV DX, COUNT
DEC DX
GO:
MOV CX, DX
LEA SI, SERIES
NXT_BYTE:
MOV AL,[SI]
CMP AL,[SI+1]
JB NEXT
XCHG AL,[SI+1]
XCHG AL,[SI]
NEXT:
INC SI
LOOP NXT_BYTE
DEC DX
JNZ GO
MOV AH, 4CH
INT 21H
CODE ENDS
END START

32
INPUT:

50000 81H
50002 82H
50004 93H
50006 95H
50008 10H
5000A 56H
5000C 33H
5000E 99H
50010 13H
50012 44H

OUTPUT:

50000 10H
50002 13H
50004 33H
50006 44H
50008 56H
5000A 81H
5000C 82H
5000E 93H
50010 95H
50012 99H

RESULT
Thus the program to Sort the given array in ascending order was executed
successfully.

33
EX . NO: 10 C
SEARCHING A STRING

OBJECTIVE
To search the character in a string using 8086.

ALGORITHM
Step 1: Load the source index register with starting address.
Step 2: Initialize the counter with the total number of characters.
Step 3: Clear the direction flag for auto incrementing mode of transfer.
Step 4: Use the string manipulation instruction SCASW to search a character from string.
Step 5: If a match is found (z=1), display the MSG1. Otherwise, display the MSG2.

SOURCE CODE
ASSUME CS: CODE, DS: DATA, ES:DATA
DATA SEGMENT
MSG DB 'HELLO'
CNT EQU $-MSG
SRC EQU 'E'
MSG1 DB 10,13,'CHARACTER FOUND$'
MSG2 DB 10,13,'CHARACTER NOT FOUND$'
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV ES, AX
LEA SI, MSG
MOV AL, SRC
MOV CL, CNT
MOV CH, 00H
CLD
UP: SCASB
JZ DOWN
LOOP UP
LEA DX, MSG2
MOV AH, 09H
INT 21H
JMP EXIT
DOWN:
LEA DX, MSG1
MOV AH, 09H
INT 21H
EXIT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START

34
OUTPUT :

INPUT: HELLO
SEARCH: E

OUTPUT:
CHARACTER FOUND

RESULT
Thus the program to search the character in a string was executed.

LIST OF QUESTION FOR NEXT EXPERIMENT

1. What is the operation of XLAT instruction?


2. Compare LEA and LES instruction.
3. List out the steps how PUSH AX instruction stores the value in the stack( AX=324B).
4. What is the purpose of XCHG instruction?
5. What is the use of POPF instruction?

35
EXP. NO: 11
DATA TRANSFER OPERATIONS

OBJECTIVE
To write a Program using 8086 for Copying 12 Bytes of Data from Source to Destination
& Verify.

ALGORITHM:
STEP 1: Start the program
STEP 2: Clear the direction flag DF
STEP 3: Move source address to SI
STEP 4: Move destination address in DI
STEP 5: Increment the count and index register
STEP 6: Move Byte
STEP 7: Terminate the program

SOURCE CODE
Mnemonics Operands Comments

CLD Clear direction flag DF


MOV SI,0300 Source address in SI
MOV DI,0202 Destination address in DI
MOV CX,[SI] Count in CX
INC SI Increment SI
INC SI Increment SI
MOV SB Move byte
LOOP BACK Jump to BACK until CX becomes
Zero
INT Interrupt program

SAMPLE INPUTS & OUTPUTS

INPUT DATA 030B : 0A


0300 : 0B 030C : 0B
0301 : 00 030D : 0E
0302 : 03
0303 : 04
0304 : 05 OUTPUT DATA
0305 : 06 0202 : 03
0306 : 15 0203 : 04
0307 : 07 0204 : 05
0308 : 12 0205 : 06
0309 : 08 0206 : 15
030A : 09 0207 : 07

RESULT
Thus the program Copying 6 Bytes of Data from Source to Destination was executed

36
FEW (MIN. 5) QUESTIONS RELATED TO THE NEXT EXPERIMENT

1. What are the DOS function calls?


2. How a CALL instruction will be executed?
3. What is the role of stack?
4. What is the difference between DOS and BIOS interrupts?
5. What is an interrupt vector table of 8086?

37
EXP. NO: 12
PASSWORD CHECKING

AIM
To write an ALP program for password checking using 8086.
ALGORITHM:
• Create a display micro
• Initialise a counter for max number of attempts available
• In the data segment store the password in a location
• In the code segment accept the string one by one and compare the stored value
• If the strings are equal display “valid password”
• If they are not equal then display invalid password
• Code ends
SOURCE CODE
disp macro x
mov ah,09h
lea dx,x
int 21h
endm
data segment
s db 13,10,"enter string:$"
u db 13,10,"right password $"
r db 13,10,"invalid $"
m1 db '*$'
m2 db 13,10,"try again $"
pwd db "cmt $"
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,0003h
int 10h
mov bl,03h
a1:
mov cl,03h
mov si,00h
disp s
a2:
mov ah,08h
int 21h
cmp al,pwd[si]
disp m1
jne l1
inc si
loop a2
disp u

38
jmp l2
l1: dec bl
disp r
disp m2
cmp bl,00h
je l2
jne a1
l2:
mov ax,4c00h
int 21h
code ends
end start

OUTPUT

enter the password ***


right password

RESULT
Thus the ALP program for password checking using 8086 was executed

FEW (MIN. 5) QUESTIONS RELATED TO THE NEXT EXPERIMENT:


1. Explain the assembler directives.
2. What are the flags in 8086?
3. What is SIM and RIM instructions?
4. What is the difference between 8086 and 8088?
5. Which is the tool used to connect the user and the computer?

39
EXP. NO: 13
PRINT RAM SIZE AND SYSTEM DATE

OBJECTIVE
To write a program to Print RAM size and system date using 8086.

ALGORITHM
STEP 1: Create a display micro
STEP 2: C Initialise a Initialise the necessary register with the required values.
STEP 3: In Use a macro to display system date.
STEP 4: Terminate the program.

SOURCE CODE
Print RAM size:
PRINT MACRO MSG
MOV AH,09H
LEA DX,MSG
INT 21H
ENDM
DATA SEGMENT
ML1 DB 13,10,’SIZE OF RAM IS $’
M2 DB ‘KILO BYTES $’
ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DAT
START:
MOV DX,DATA
MOV DS,DX
MOV AX,0003H
INT 10H
PRINT M1
INT 12H
MOV B1,64H
DIV B1
MOV CH,AH
ADD A1,’0’
MOV D1,A1
MOV AH,02H
INT 21H
MOV A1,CH
MOV AH,00H
MOV B1,0AH
DIV B1
ADD A1,’0’
ADD AH,’0’
MOV CH,AH
MOV AH,02H
INT 21H

40
MOV D1,CH
MOV AH,02H
INT 21H
PRINT M2
MOV AX,4C00H
INT 21H
CODE ENDS
END START
System Date:
DISP MACRO X
PUSH DX
MOV AH,09H
LEA DX,X
POP DX
ENDM
PRINT MACRO
MOV BH,0AH
MOV AH,00H
DIV BH
ADD AL,’0’
ADD AH,’0’
MOV BH,AH
MOV DL,AL
MOV AH,02H
INT 21H
ENDM
MYDATE SEGMENT
S DB 13,10,’THE DATE IS:’$’
C DB,’/$’
MYDATAE ENDS
MYCODE SEGMENT
ASSUME CS:MYCODE,DS:MYDATE
START: MOV AX,MYDATE
MOV DS,AX
MOV AX,0003H
INT 10H
DISP S
MOV AH,2AH
INT 21H
MOV AL,DL
MOV BL,DH
PRINT
DISP C
MOV AL,BL
PRINT
DISP C
MOV AX,CX
MOV BX,03E8H
MOV DX,0000H
DIV BX

41
MOV CX,DX
MOV DL,AL
ADD DL,’0’
MOV AH,02H
INT 21H
MOV AX,CX
MOV DX,0000H
MOV BX,0064H
DIV BX
MOV CX,DX
ADD AL,’0’
MOV DL,AL
MOV AH,02H
INT 21H
MOV AX,CX
MOV BL,0AH
DIV BL
MOV BH,AH
ADD AL,’0’
MOV AH,02H
INT 21H
ADD BH,’0’
MOV DL,BH
MOV AH,02H
INT 21H
MOV AX,4C00H
INT 21H
MYCODE ENDS
END START

SAMPLE INPUTS & OUTPUTS:


The Date is : 07-08-2015
The size of RAM is : 1 GB

RESULT
Thus the program to Print RAM size and system date using 8086 was executed

QUESTIONS RELATED TO THE NEXT EXPERIMENT


1. What is the role of stack?
2. What is the role of Call delay?
3. What is an interrupt vector table of 8086?
4. Which Segment is used to store interrupt and subroutine return address registers?
5. Which microprocessor accepts the program written for 8086 without any changes?

42

You might also like