You are on page 1of 15

COA Lab Manual

School of Computer Science & Engineering


Course Name and Code: COA (CS408P) Class: CSE Second Year
Session: 2019-2023 (Year-2021-2022) Semester: IV

LAB MANUAL
LIST OF EXPERIMENT
S.NO. NAME OF EXPERIMENTS DATE OF
EXPERIMENTS

01. Program using MACRO: Display personal information


using MACRO.
18-May-2022

02. Program for Addition of 2 numbers using NEAR /FAR


procedure.
23-May-2022

03. Program for Subtraction of 2 numbers using NEAR/FAR


procedure.

04. Program for Password Verification

25-May-2022

05. Program to display System Date/Time.

30- May -2022

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


1
COA Lab Manual

06 Program to sort the given array in ascending and


descending order.

01- June -2022


07. Program for BCD to HEX conversion.

08. Program for HEX to BCD conversion.

09 Program for Multiplication of 2 numbers using 06-jun-2022


NEAR/FAR procedure.

10. Program for Division of 2 numbers using NEAR/FAR 08-jun-2022


procedure

11. Program to add two BCD numbers.

12. Program using Structure.


13. Program to generate Fibonacci Series.
14. Program for block transfer from one segment to another
segment
15. Study of DOS and BIOS interrupts and 8086 Assembler
Directives.
16. Program to find out Factorial of any given number using 15-jun-2022
recursive procedure.

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


2
COA Lab Manual

EXPERIMENT-1
Title:
Program using MACRO: Display personal information using MACRO.

Objective:
Implementation of assembly language Program to display Personal information using
MACRO
SOFTWARE REQUIRED: MASM
THEORY:
Macro is the same concept as that of Procedure except that macros are used when the repeated group of
instructions is too short or whenever procedure is not appropriate to written.
In case of Macro, a Macro name or label is assigned with the repeatedly appearing instructions. The
process of assigning a label or Macro name to a sequence of instruction is called as defining a macro. The
Macro name or Macro definition is then used throughout the main program to refer to that of instructions.

CODE SEGMENT
DISPLAY MACRO MAC
LEA DX, MAC
MOV AH, 09H
INT 21H
ENDM
DISPLAY M1
DISPLAY M2
CODE ENDS
From the above code DISPLAY is a Macro name &MAC is a parameter and also the M1 &M2
are the variable names declared in DATA SEGMENT

ALGORITHM:
1) Initialize a Data Segment

2) Declare the variables (Message name first, second and third for display message).

3) Ends a Data Segment

4) Initialize Code Segment

5) Declare the name of logical segments with the ASSUME directive

6) Define the MACRO with the Macro name DISPLAY & parameter MAC

7) Passing the parameter to macro while calling the MACRO

8) Ends a MACRO.

9) Call macro with the parameter to display the further messages.

10) Ends a Code Segment.

11) End the program.

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


3
COA Lab Manual

EXPERIMENT-2

Title: Program using NEAR and FAR procedure


Objective : a) Implementation of assembly language program for addition of two HEX numbers using
NEAR procedure
b) Implementation of assembly language program for addition of two HEX numbers using FAR procedure

SOFTWARE REQUIRED:MASM
THEORY:
Manual Conversion 1st no = 18H
2nd no = 15H
Result = 2DH
Near procedure is defined in same code segment where main program is stored. Far procedure is defined in
different code segment where main program is stored.

Syntax:-
a) CODE SEGMENT

-------------
--------------
CALL PROC_NAME
----------------
PROC_ NAME PROC
------------ PROC_NAME ENDP
CODE ENDS

b) CODE SEGMENT

-------------
CALL FAR PTR PROC_NAME
--------------- CODE ENDS CODE1 SEGMENT
-------------
--------------
PROC_ NAME PROC
------------ PROC_NAME ENDP
CODE1 ENDS

ALGORITHM:
a)
1) Initialize a Data Segment

2) Declare the variables (Message name first for o/p message, array name first & second for storing
immediate data.)
3) Ends a Data Segment

4) Initialize Code Segment

5) Declare the name of logical segments with the ASSUME directive

6) Display the M1 o/p message.


School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)
4
COA Lab Manual

7) Store the content of R1 & R2 in AL & BL register resp.

8) ADD the content of AL with BL & move the content of AL to BL register.

9) Mask the content of ALWith 0F0H & shift right 4 times by using instruction SHR.

10) Compare the content of AL with 0AH (Hexadecimal no. of 10).

11) Jump if less on label ABC.

12)ADD AL with 07H.

13) In label ABC,

i. ADD 30H with AL.

ii. CALL procedure Disp.


iii. Move the content of AL to BL register.

iv. Mask the content of AL With 0FH.

v. Compare the content of AL with 0AH (Hexadecimal no. of 10).

vi. Jump if less on label XYZ.

vii. ADD AL with 07H.

14) In XYZ label,

i. ADD 30H with AL.

ii. CALL procedure Disp.

15) Return to DOS promt using AH=4CH interrupt.

16) Define NEAR procedure Disp, to display the result.

17) End code segment.

18) End the program.

b)
1) Initialize a Data Segment

2) Declare the variables (Message name first for o/p message, array name first and second for storing
immediate data.)
3) Ends a Data Segment

4) Initialize Code Segment

5) Declare the name of logical segments with the ASSUME directive

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


5
COA Lab Manual

6) Display the first message o/p message.

7) Store the content of array first & second in AL & BL register resp.

8) ADD the content of AL with BL & move the content of AL to BL register.

9) Mask the content of AL With 0F0H & shift right 4 times by using instruction SHR.

10) Compare the content of AL with 0AH (Hexadecimal no. of 10).

11) Jump if less on label ABC.

12)ADD AL with 07H.

13) In label ABC,

i. ADD 30H with AL.

ii. CALL FAR procedure Disp using directive PTR.

iii. Move the content of AL to BL register.

iv. Mask the content of AL With 0FH.


v. Compare the content of AL with 0AH (Hexadecimal no. of 10).

vi. Jump if less on label XYZ.

vii. ADD AL with 07H.

14) In XYZ label,

i. ADD 30H with AL.

ii.CALL FAR procedure Disp using directive PTR.

15) Return to DOS promt using AH=4CH interrupt.

16) End code segment.

17) Initialize another Code Segment.

18)Declare the name of logical segments with the ASSUME directive

19)Define FAR procedure Disp, to display the result.

20) END Code segment.

21) End the program.

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


6
COA Lab Manual

EXPERIMENT-3
Title: Program for Password Verification

Objective:
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
jmp l2

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


7
COA Lab Manual

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

EXPERIMENT-4

Title: Program to display system time and date.


Objective: Display current system Time and Date of the system.

SOFTWARE REQUIRED:MASM

THEORY:
Display the system time and date according to given format Time format
hr:min:sec Date format dd/mm/yyyy

ALGORITHM:
1) Initialize a Data Segment

2) Declare the variables

3) Ends a Data Segment

4) Initialize Code Segment

5) Declare the name of logical segments with the ASSUME directive

6) BX=offset address of string TIME

7) Get the current system time by using MOV AH, 2CH INT 21H.

8) Set AL=CH , CH=hours

9) Call the procedure CONVERT

10) Set [BX]=hr , [BX] is pointing to hr ; in the string TIME

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


8
COA Lab Manual

11) Set AL=CL , CL=minutes

12) Call the procedure CONVERT


Set [BX+3]= min, [BX] is pointing to min ; in the string TIME

13) Set AL=DH , DH=seconds Call the procedure CONVERT


Set [BX+6] =min, [BX] is pointing to sec ; in the string TIME

14) SI=offset address of string TIME

15)MOV AH, 2AH ; Get the current system time INT 21H

16) Set AL=CH , CH=hours


Call the procedure CONVERT
Set [SI] =hr, [SI] is pointing to hr ; in the string TIME

17) Set AL=CL , CL=minutes


Call the procedure CONVERT
Set [SI+3] =min, [SI] is pointing to min ; in the string TIME

18) Return control to DOS

19) Procedure

Input: AL=binary code


Output: AX=ASCII code
PUSH DX onto the STACK Set AH=0
Set DL=10
Set AX=AX/DL
Convert the binary code in AX into ASCII POP a value from STACK into DX Return control to the calling
procedure End of procedure CONVERT

20) Ends a Code Segment.

21) End the program.

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


9
COA Lab Manual

EXPERIMENT-5
Title: Program to sort the given array in ascending and descending order.
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

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


10
COA Lab Manual

33
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.

Experiment-06

Title: Write An Alp To Multiply Two 16-Bit Numbers


Objective: To Write An Alp To Multiply Two 16-Bit Numbers
Software Required: Masm 16 Bit

Algorithm: 1. Get The Multiplier.


2. Get The Multiplicand
3. Initialize The Product To 0.
4. Product = Product + Multiplicand
5. Decrement The Multiplier By 1
6. If Multiplicand Is Not Equal To 0,Repeat From Step (D) Otherwise Store The Product.

Program:
School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)
11
COA Lab Manual

.MODEL SMALL
.STACK
.DATA .CODE START:
MULTIPLICAND DW 00FFH; FIRST WORD HERE
MULTIPLIER DW 00FFH; SECOND WORD HERE
PRODUCT DW 2 DUP(0); RESULT OF MULIPLICATION HERE
MOV AX, @DATA
MOV DS, AX
MOV AX, MULTIPLICAND MUL MULTIPLIER
MOV PRODUCT, AX
MOV PRODUCT+2, DX
MOV AH, 4CH
INT 21H
END START

Experiment-07

Title: Write An Alp To Divide Two Numbers

Objective: To Write An Alp To Divide Two Numbers

Software Required: Masm 16 Bit


School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)
12
COA Lab Manual

Algorithm:
1. Get the dividend
2. Get the divisor
3. Initialize the quotient to 0.
4. Dividend = dividend – divisor
5. If the divisor is greater, store the quotient. Go to step g.
6. If dividend is greater, quotient = quotient + 1. Repeat from step (d)
7. Store the dividend value as remainder.

Program:
.MODEL SMALL
.DATA
W1 DW 02222H
W2 DW 1111H
Q DW ?
R DW ?
.CODE
MOV AX, @DATA
MOV DS, AX ; INITIALIZE DATA SEGMENT
MOV AX, W1 ; GET DIVIDEND
MOV BX, W2 ; GET DIVISOR
DIV BX ; DIVIDE
MOV Q, AX ; STORE QUOIENT
MOV R, DX ; STORE REMAINDER
MOV AH, 4CH
INT 21H
END ; END PROGRAM

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


13
COA Lab Manual

Experiment-08

Title: Program to find out Factorial of any given number using recursive procedure.

Objective : TO WRITE AN ALP TO FIND THE FACTORIAL OF A GIVEN NUMBER USING


RECURSIVE PROCEDURE
SOFTWARE REQUIRED: MASM 16 BIT

Code Segment:
.MODEL SMALL
.DATA
NUM DW 8
RESULT DW (?) ; INITIALIZE MEMORY FOR THE RESULT

.CODE
MAIN PROC

MOV AX, @DATA ; INITIALIZE DATA SEGMENT


MOV DS, AX
MOV AX, 01 ; INITIALIZE RESULT AS 01 IF THE NUMBER IS 0
MOV CX, NUM ; INITIALIZE NUMBER
CMP CX, 00 ; CHECK WHETHER NUMBER IS 0
JE LOOP1 ; YES, TERMINATE PROGRAM
MOV BX, CX ; SAVE THE NUMBER IN BX
CALL FACT ; CALL FACTORIAL PROCEDURE
LOOP1:
MOV RESULT, AX ; SAVE FACTORIAL RESULT
MOV AH, 4CH
INT 21H
MAIN ENDP ; END MAIN PROCEDURE
FACT PROC
CMP BX, 01
JZ LOOP2
PUSH BX
DEC BX
CALL FACT ; CALL FACTORIAL
PROCEDURE POP BX
MUL BX
RET ; RETURN CALLED PROGRAM
LOOP2:
MOV AX, 01 ; INITIALIZE AX REGISTER TO 01
RET ; RETURN CALLED PROGRAM
FACT ENDP ; END FACTORIAL PROCEDURE
END ; END PROGRAM

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


14
COA Lab Manual

School of Computer Science & Engineering (Sandip University, Sijoul, Madhubani)


15

You might also like