You are on page 1of 58

Lab Manual

for
CSE 334 (Microprocessor and Assembly Language Lab)
Credit: 1, Contact hour: 2 Hours Per week

Department of Computer Science & Engineering


Varendra University
Rajshahi, Bangladesh

Page 1 of 58
Varendra University
Department of Computer Science and Engineering

CSE 334
Microprocessor and Assembly Language
Laboratory

Student ID
Student Name
Section
Name of the Program
Name of the
Department

Page 2 of 58
Index
SL Page
I INSTRUCTIONS FOR LABORATORY
II COURSE SYLLABUS
III PSEUDO CODES & PROGRAMMING CODE FOR LAB
EXPERIMENTS
1 Introduction of 8086 Microprocessor Architecture
and Emulator
2 Simple branching and jump operation I

3 Simple branching and jump operation II

4 Comparison and branching

5 Compound comparison

6 Looping

7 Multiplication and division operation

8 Array and Stack

9 Logic operation

10 Shift and Rotation operation and Test

11 General problem.

12 Final Lab Examination,


Quiz, viva voce

Page 3 of 58
Page 4 of 58
INSTRUCTIONS FOR LABORATORY

 The experiments are designed to illustrate about different principles, paradigm and
features of Assembly language.

 Students should come with thorough preparation for the experiment to be conducted.
 Students should come with proper dress code.
 Students will not be permitted to attend the laboratory unless they bring the practical Record
fully completed in all respects pertaining to the experiment conducted in the
previous class.

 Work quietly and carefully (the whole purpose of experimentation is to develop program in
Assembly language) and equally share the work with your partners.

 Be honest in developing and representing your program. If a particular program output


appears wrong repeat the program carefully.

 All presentations of programs and outputs should be neatly and carefully done.
 If you finish early, spend the remaining time to complete the laboratory report writing.
Come equipped with calculator and other materials related to lab works.

 Handle instruments with care. Report any breakage or faulty equipment to the Instructor.
 Shutdown your computer you have used for the purpose of your experiment before leaving
the Laboratory

Page 5 of 58
Varendra University
Department of Computer Science and Engineering
COURSE SYLLABUS
1 Faculty Faculty of Science & Engineering

2 Department Department of CSE

3 Program B.Sc. in Computer Science and Engineering

4 Name of Course Microprocessor and Assembly Language Lab Laboratory

5 Course Code CSE 334


6 Trimester and Summer , 2019
Year

7 Pre-requisites CSE 324, CSE 124


8 Status Core Course

9 Credit Hours 1

10 Section 13A

11 Class Hours Tuesday 2:00-4:00

12 Class Location SEL Lab (Room: Engg Annex 304)

13 Name (s) of
Academic Krishna Chandro Ray
staff /
Instructor(s)
14 Contact krishna@vu.edu.bd

15 Office Room: 103, Engg Annex Building, Talaimari.

16 Counseling Hours Tuesday 10:30am-12:00pm


Wednesday 1:30pm-3:00pm

17 Text Book Assembly Language Programming and Organization of the IBM


PC by Ytha Yu, Charles Marut

18 Reference 1. www.stackoverflow.com
2. Tutorial on GUI development step by step

19 Equipment & Aids


1. Lab Sheet

Page 6 of 58
2. Text Book
3. Emu 8086 emulator

20 Course Rationale Concepts of assembly language and the machine representation


of instructions and data of a modern digital computer are
presented. Students will have the opportunity to study machine
addressing, stack operations, subroutines, and programmed and
interrupt driven I/O. Also, basic concepts of machine
organization are studied. This will include computer architecture
at the register level and micro-operation components of
instructions. Students will utilize the Intel 8086-80586
instruction set and will perform programming exercises in MS-
DOS mode

21 Course Description Assembly Language is designed for undergraduate students


majoring in Computer Science and Technology, and is a major
elective course. The undergraduate students who choose
Assembly Language are required to master programming
language; The implementation of the program and the work
progress of computer can be closely linked by mastering the
corresponding of these two languages, directly reflecting the
inherent characteristics of the assembly language, which means
it is the combination that can easily unify “program” and
“machine”. Give the differences in microarchitecture through
further explanation of the different assembly code, and it can
provide pilot knowledge for some follow-up courses, such as
Compiler Principles, Operating System, Computer Architecture,
as well as an understanding of the role and position of various
courses for students from the perspective of the whole system.

22 Course Objectives By the end of the semester, you will be able to:
•Edit, compile, execute, and debug an assembler program.
•Write a syntactically and semantically correct assembler
program.
•Use a subroutine library within an assembler program.
•Manipulate standard data types and other forms of data within
an assembler program.
•Implement conditional and looping structures within an
assembler program.
•Create and use assembly subroutines.
•Implement and manipulate standard data structures within an
assembler program.
•Create and use assembly macros.
•Use conditional assembly and other directives.

Page 7 of 58
23 Learning Outcomes After the completion of this course, a successful student will be
able to do the following:
a.Know the major classes of programming languages with their
characteristics.
b.Perform conversions between binary, octal/hexadecimal, and
decimal number systems and perform the basic arithmetic
operations in these number systems.
c.Be able to describe the assembly level machine organization
including: the main memory, the CPU, the I/O systems, the
system interconnection, the secondary storage, the clock, and
interrupts with their function.
d.Understand memory organization, memory segmentation and
boundary alignments.
e.Represent an absolute address in selector/offset form and
compute an absolute address from a selector/offset address..

24 Teaching Methods Lecture, , Problem Solving, Brainstorming, Project, Q/A, Presentation

25 Topic Outline

Topics Or CL Reading
Class Activities
Assignments Os Reference

Introduction of
8086
Problem Solving.
1-2 Microprocessor Question Answer
Architecture and
Emulator

Simple branching and


Problem Solving.
3-4 jump operation I
Question Answer

Simple branching and


Problem Solving.
5-6 jump operation II
Question Answer

Comparison and Implementation,


6-8 branching Problem Solving.
Question Answer

9-10 Implementation,
Compound comparison Problem Solving.

Page 8 of 58
Question Answer

Implementation,
11-12 Looping Problem Solving.
Question Answer

Multiplication and Implementation,


13-14 division operation Problem Solving.
Question Answer
Implementation,
15-16 Array and Stack Problem Solving.
Question Answer

Implementation,
17-18 Logic operation Problem Solving.
Question Answer

Shift and Rotation Implementation,


19-20 operation and Test Problem Solving.
Question Answer

Implementation,
21-22 General problem. Problem Solving.
Question Answer

Problem Solving,
Final Lab Examination, Multiple Choice
23-24
Quiz, viva voce Question Answer,
Viva

Page 9 of 58
Assessment type Marks

Attendance (10%)

Lab Quiz (30%)

Lap Report (LR) (10%)


Assessment Continuous
26 (10%)
Methods assessment
Lab Test (LT) (10%)

Lab Final (LF) (20%)

Viva voce (10%)

Total (100%)
Grading System:

Numerical Grade Letter Grade Grade Point


80 % and above A+ (A Plus) 4.00
75% to less than 80 % A (A Regular) 3.75
70 % to less than 75% A- (A Minus) 3.50
Grading
27 65% to less than 70% B+ (B Plus) 3.25
Policy
60% to less than 65% B (B Regular) 3.00
55% to less than 60% B- (B Minus) 2.75
50% to less than 55% C+ (C Plus) 2.50
45% to less than 50% C (C Regular) 2.25
40% to less than 45% D (D Regular) 2.00
Less than 40% F (Failure) 0.00

1. 1. Lab Reports
Report on previous Experiment must be submitted before the beginning of new
experiment. A bonus may be obtained if a student submits a neat, clean and complete
lab report.
2. 2. Examination
Additional There will be a lab exam at the end of the semester that will be closed book.
28 Course 3. 3. Unfair means policy
Policies In case of copying/plagiarism in any of the assessments, the students involved will
receive zero marks. Zero Tolerance will be shown in this regard. In case of severe
offences, actions will be taken as per university rule.
4. 4. Counseling
Students are expected to follow the counseling hours posted. In case of
emergency/unavoidable situations, students can e-mail me to make an appointment.

Page 10 of 58
Students are regularly advised to check the piazza course page for updates/materials.
5. 5. Policy for Absence in Class/Exam
If a student is absent in the class for anything other than medical reasons, he/she will
not receive attendance. If a student misses a class for genuine medical reasons,
he/she must apply with the supporting documents (prescription/medical report).
He/she will then have to follow the instructions given by the instructor for makeup.
In case of absence in the mid/final exam for medical grounds, the student must also
get his/her application forwarded by the head of the department before a make-up
exam can be taken. It is recommended that the students inform the instructor
beforehand through mail if they feel that they will miss a class/evaluation due to
medical reasons.

29 Additional a. Academic Calendar summer 2019:


Info http://vu.edu.bd/notice/details/1379
b. Academic Information and Policies:
http://vu.edu.bd/program/bachelor-of-science-in-computer-science-and-engineering
c. Grading and Performance Evaluation:
http://vu.edu.bd/program/bachelor-of-science-in-computer-science-and-engineering

Page 11 of 58
Lab 1:
Introduction of 8086 Microprocessor Architecture and Emulator
Emu8086 combines an advanced source editor, assembler, disassembler, software emulator
(Virtual PC) with debugger.

Visual interface is very easy to work with. You can watch registers, flags and memory while
your program executes. Arithmetic & Logical Unit (ALU) shows the internal work of the central
processor unit (CPU).

Emulator runs programs on a Virtual PC, this completely blocks your program from accessing
real hardware, such as hard-drives and memory, since your assembly code runs on a virtual
machine, this makes debugging much easier.

EMU8086 - Microprocessor Emulator is extremely helpful for those who just begin to study
assembly language. It compiles the source code and executes it on emulator step by step.

Figure: Interface of emu8086

Where to start?

1. Click code examples and select Hello, world. A code example with many comments
should open. All comments are green and they take up about 90% of all text, so don't be
scared by this tiny "Hello Word" code. The compiled executable is only about 100 bytes
long, because it uses no interrupts and has only one loop for color highlighting the text.
All other code is straight-forward and writes directly to video memory.

Page 12 of 58
2. To run this example in the emulator, click emulate (or press F5). The program then
attmepts to assemble and save the executable to c:\emu8086\MyBuild. If the assembler
succeeds in creating the file, the emulator will also automatically load it into memory.

3. You can then click single step (or press F8) to step through the code one instruction at a
time, observing changes in registers and the emulator screen. You can also click step
back (or press F6) to see what happens when reversing those changes.

4. There are many ways to print "Hello,World" in assembly language, and this certainly isn't
the shortest way. If you click examples and browse c:\emu8086\examples, you'll find
HelloWorld.asm which assembles into only a 30-byte executable. Unlike the previous
example which carries out each step by itself, this one is much smaller because it uses a
built-in interrupt function of the operating system to write to the display.

The integrated 8086 assembler can generate console programs that can be executed on any
computer that runs x86 machine code (Intel/AMD architecture)

The architecture of the 8086 Intel microprocessor is called "Von Neumann architecture" after the
mathematician who conceived of the design.

NOTE: A CPU can interpret the contents of memory as either instructions or data; there's no
difference in the individual bytes of memory, only the way in which they're arranged. Because of
this, it's even possible for programs to re-write their own instructions, then execute the
instructions they've changed.

Execution Unit (EU):

Page 13 of 58
Execution unit receives program instruction codes and data from the BIU, executes them and
stores the results in the general registers. It can also store the data in a memory location or send
them to an I/O device by passing the data back to the BIU. This unit, EU, has no connection with
the system Buses. It receives and outputs all its data through BIU.

ALU (Arithmetic and Logic Unit) : The EU unit contains a circuit board called the
Arithmetic and Logic Unit. The ALU can perform arithmetic, such as, +,-,×,/ and logic such as
OR, AND, NOT operations.
Registers : A register is like a memory location where the exception is that these are
denoted by name rather than numbers. It has 4 data registers, AX, BX, CX, DX and 2 pointer
registers SP, BP and 2 index registers SI, DI and 1 temporary register and 1 status register
FLAGS .

AX, BX, CX and DX registers has 2 8-bit registers to access the high and low byte data registers.
The high byte of AX is called AH and the low byte is AL. Similarly, the high and low bytes of
BX, CX, DX are BH and BL, CH and Cl, DH and DL respectively. All the data, pointer, index
and status registers are of 16 bits. Else these, the temporary register holds the operands for the
ALU and the individual bits of the FLAGS register reflect the result of a computation.

Bus Interface Unit:

As the EU has no connection with the system Busses, this job is done by BIU. BIU and EU are
connected with an internal bus. BIU connects EU with the memory or I/O circuits. It is
responsible for transmitting data, addresses and control signal on the busses.
Registers : BIU has 4 segment busses, CS, DS, SS, ES. These all 4 segment registers holds
the addresses of instructions and data in memory. These values are used by the processor to
access memory locations. It also contain 1 pointer register IP. IP contains the address of the next
instruction to executed by the EU.
Instruction Queue : BIU also contain an instruction queue. When the EU executes
instructions, the BIU gets up to 6 bytes of the next instruction and stores them in the instruction
queue and this process is called instruction prefetch. This is a process to speed up the processor.
Also when the EU needs to be connected with memory or peripherals, BIU suspends instruction
prefetch and performs the needed operations.

** Simple program to show “Hello world” message

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB 'Hello World!$'

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

Page 14 of 58
LEA DX,STR1
MOV AH,9
INT 21H

MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

;Title:- Input Two Number & Print them In Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P ;PRINT str
INT 21H
ENDM

.MODEL SMALL
.STACK 100H

.DATA
str1 DB "Please Enter First Number: $"
str2 DB "Please Enter Second Number: $"
str3 DB "Your Given First Number is: $"
str4 DB "Your Given Second Number is: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
PRINT str1
MOV AH,1
INT 21H
MOV BL,AL

CALL New_Line

PRINT str2
MOV AH,1
INT 21H
MOV CL,AL
CALL New_Line

PRINT str3

Page 15 of 58
MOV AH,2
MOV DL,BL
INT 21H

CALL New_Line

PRINT str4
MOV AH,2
MOV DL,CL
INT 21H

MOV AH,4CH
INT 21H

ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2 ;CALL New_Line
MOV DX,13
INT 21H
RET
New_Line ENDP

END MAIN

Lab 2:

Simple branching and jump operation I

The absolute value of a positive number is just the number itself, and the absolute value of a
negative number is its opposite. The absolute value of 0 is 0 .
i. Write an assembly language program to replace a number with its absolute value.

Page 16 of 58
.MODEL SMALL
.STACK 100H
.DATA
;STR1 DB -5

.CODE
MAIN PROC
MOV AX,-5

CMP AX,0
JNL END_IF
NEG AX
END_IF:

ADD AL,48
MOV AH,2
MOV DL,AL
INT 21H

MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

ii. Write an assembly language program to read two single digit numbers and show the
sum. (sum not more than 9)

.MODEL SMALL
.STACK 100H
.DATA
A DB 'ENTER THE NUMBER: $'

Page 17 of 58
A1 DB 0DH,0AH,'YOUR RESULT IS: $'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

LEA DX,A
MOV AH,9
INT 21H
MOV AH,1
INT 21H
MOV BL,AL

MOV DL,0DH
MOV AH,2
INT 21H
MOV DL,0AH
INT 21H

LEA DX,A
MOV AH,9
INT 21H

MOV AH,1
INT 21H

ADD BL,AL

LEA DX,A1
MOV AH,9
INT 21H

SUB BL,48

MOV AH,2
MOV DL,BL
INT 21H

MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

Page 18 of 58
Lab 3:
Simple branching and jump operation II

i. Write an assembly language program to read a single digit number and show “pass”
or “fail” according to threshold value.
.MODEL SMALL
.STACK 100H
.DATA
A DB "ENTER INPUT NUMBER IS : $"
A1 DB 0DH,0AH, "YOUR RESULT IS : PASS $"
A2 DB 0DH,0AH, "YOUR RESULT IS: FAIL $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

LEA DX,A
MOV AH,9
INT 21H

MOV AH,1
INT 21H
MOV BL,AL

CMP BL,52
JNLE LABEL

MOV AH, 9
LEA DX,A2
INT 21H

JMP DISPLAY

LABEL:

MOV AH, 9
LEA DX,A1
INT 21H

DISPLAY:
MOV AH,4CH
INT 21H

MAIN ENDP

Page 19 of 58
END MAIN

ii. Write an assembly language program to read a single digit number and show the
grade “A+” , “A”, or “Fail”.

.MODEL SMALL

.STACK 100H

.DATA

A1 DB "ENTER INPUT NUMBER IS: $"


A2 DB 0DH,0AH,"RESULT IS: A+ $"
A3 DB 0DH,0AH,"RESULT IS: A $"
A4 DB 0DH,0AH,"RESULT IS: Fail $"

.CODE

MAIN PROC

MOV AX,@DATA
MOV DS,AX

LEA DX,A1
MOV AH, 9
INT 21H

MOV AH,1
INT 21H
MOV BL,AL

CMP BL,55
JNGE LABEL

CMP BL,57
JNLE LABEL

MOV AH, 9
LEA DX,A2
INT 21H

Page 20 of 58
;MOV AH, 2
;MOV DL,BL
;INT 21H

JMP DISPLAY

LABEL:

CMP BL,52
JNGE LABEL1

CMP BL,54
JNLE LABEL1

MOV AH, 9
LEA DX,A3
INT 21H

;MOV AH,2
;MOV DL,BL
;INT 21H

JMP DISPLAY
LABEL1:

MOV AH, 9
LEA DX,A4
INT 21H

DISPLAY:
MOV AH,4CH
INT 21H

MAIN ENDP

END MAIN

iii. ;Title:- Take Class Test Number(0-10) as Input and Show Their Grade & GPA in
Assembly Language

Page 21 of 58
;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA

;I am Just Assume This Values, You Can Edit as Your Wish

STR1 DB "Grade: A/A+ & GPA: 4.00$" ;If Class Test Number 9 or 10
STR2 DB "Grade: B & GPA: 3.00$" ;If Class Test Number 8
STR3 DB "Grade: C & GPA: 2.00$" ;If Class Test Number 7
STR4 DB "Grade: D & GPA: 1.00$" ;If Class Test Number 6
STR5 DB "Grade: F & GPA: 0.00$" ;If Class Test Number 5 or below
STR6 DB "Give Class Test Number: $"
ARR DB 10 DUP (?)

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

MOV SI,0

INPUT:
MOV AH,1
INT 21H

MOV ARR[SI],AL
INC SI

MOV BL,AL
CMP BL,0DH
JE START

JMP INPUT

START:
CMP SI,2
JG A

MOV CL,ARR[0]
SUB CL,48

CMP CL,9
JGE A

Page 22 of 58
CMP CL,8
JE B

CMP CL,7
JE C

CMP CL,6
JE D

CMP CL,5
JLE F

A:
CALL New_Line
PRINT STR1
JMP END

B:
CALL New_Line
PRINT STR2
JMP END

C:
CALL New_Line
PRINT STR3
JMP END

D:
CALL New_Line
PRINT STR4
JMP END

F:
CALL New_Line
PRINT STR5
JMP END

END:
MOV AH,4CH
INT 21H
ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2
MOV DX,13
INT 21H
RET
ENDP

Page 23 of 58
Lab 4:
Comparison and branching
i. Write an assembly language program to read two single digit numbers and show the
largest number or equal.

.MODEL SMALL

.STACK 100H

.DATA

A1 DB 0DH,0AH,"ENTER INPUT NUMBER IS: $"


A2 DB 0DH,0AH,"BIGGEST NUMBER IS: $"
A3 DB 0DH,0AH,"YOUR INPUT NUMBER IS: EQUAL $"

.CODE

MAIN PROC

MOV AX,@DATA
MOV DS,AX

LEA DX,A1
MOV AH,9
INT 21H

MOV AH,1
INT 21H
MOV BX,AX

LEA DX,A1
MOV AH,9
INT 21H

MOV AH,1
INT 21H

MOV CX,AX

CMP BX,CX
JLE BIG

LEA DX,A2
MOV AH,9
INT 21H

MOV AH,2
MOV DX,BX
INT 21H
JMP DISPLAY

Page 24 of 58
BIG:
CMP BX,CX
JE EQUAL

LEA DX,A2
MOV AH,9
INT 21H

MOV AH,2
MOV DX,CX
INT 21H
JMP DISPLAY

EQUAL:
LEA DX,A3
MOV AH,9
INT 21H

DISPLAY:
MOV AH,4CH
INT 21H

MAIN ENDP

END MAIN

ii. Title:- Take Three Input Numbers and Find The Largest Number among them in
Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

PRINT1 MACRO P
MOV AH,9
LEA DX,P ;PRINT str
INT 21H
ENDM

Page 25 of 58
PRINT2 MACRO P
MOV AH,2
MOV DL,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H

.DATA
str1 DB "Please Enter First Number: $"
str2 DB "Please Enter Second Number: $"
str3 DB "Please Enter Third Number: $"
str4 DB "Maximum Number is: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT1 Str1
MOV AH,1
INT 21H
MOV BL,AL

CALL New_Line

PRINT1 Str2
MOV AH,1
INT 21H
MOV BH,AL

CALL New_Line

PRINT1 Str3
MOV AH,1
INT 21H
MOV CL,AL

CALL New_Line

CMP BL,BH
JG MAX1

Page 26 of 58
;CMP BL,CL

CMP BH,CL
JG MAX3

PRINT1 str4
PRINT2 CL
MOV AH,4CH
INT 21H

MAX1:
CMP BL,CL
JG MAX2

PRINT1 str4
PRINT2 CL
MOV AH,4CH
INT 21H

MAX2:
PRINT1 str4
PRINT2 BL
MOV AH,4CH
INT 21H

MAX3:
PRINT1 str4
PRINT2 BH
MOV AH,4CH
INT 21H

MOV AH,4CH
INT 21H

Page 27 of 58
ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2 ;CALL New_Line
MOV DX,13
INT 21H
RET
ENDP

END MAIN

iii. ;Input three numbers and Find Minimum value

PRINT1 MACRO P
MOV AH,9
LEA DX,P ;PRINT str
INT 21H
ENDM

PRINT2 MACRO P
MOV AH,2
MOV DL,P
INT 21H
ENDM

Page 28 of 58
.MODEL SMALL
.STACK 100H

.DATA
str1 DB "Please Enter First Number: $"
str2 DB "Please Enter Second Number: $"
str3 DB "Please Enter Third Number: $"
str4 DB "Minimum Number is: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT1 Str1
MOV AH,1
INT 21H
MOV BL,AL

CALL New_Line

PRINT1 Str2
MOV AH,1
INT 21H
MOV BH,AL

CALL New_Line

PRINT1 Str3
MOV AH,1
INT 21H
MOV CL,AL

CALL New_Line

CMP BL,BH
JL MIN1

;CMP BL,CL

CMP BH,CL
JL MIN3

Page 29 of 58
PRINT1 str4
PRINT2 CL
MOV AH,4CH
INT 21H

MIN1:
CMP BL,CL
JL MIN2

PRINT1 str4
PRINT2 CL
MOV AH,4CH
INT 21H

MIN2:
PRINT1 str4
PRINT2 BL
MOV AH,4CH
INT 21H

MIN3:
PRINT1 str4
PRINT2 BH
MOV AH,4CH
INT 21H

MOV AH,4CH
INT 21H

ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2 ;CALL New_Line

Page 30 of 58
MOV DX,13
INT 21H
RET
ENDP

END MAIN

Lab 5:
Compound comparison
;Title:- Input a Chracter and check Capital or Small or Special Character in Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P ;PRINT str
INT 21H
ENDM

.MODEL SMALL
.STACK 100H

.DATA
str1 DB "Please Enter a Chracter: $"
str2 DB "It is a Capital Letter: $"
str3 DB "It is a Small Letter: $"
str4 DB "It is not any Alphabet It is a Number or Special Chracter: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT str1
MOV AH,1
INT 21H
MOV BL,AL

CALL New_Line

CMP BL,65

JGE LEVEL1

PRINT str4
MOV AH,4CH
INT 21H

Page 31 of 58
LEVEL1:
CMP BL,90

JLE LEVEL2

CMP BL,97

JGE LEVEL3

PRINT str4
MOV AH,4CH
INT 21H

LEVEL2:
PRINT str2
MOV AH,4CH
INT 21H

LEVEL3:
PRINT str3
MOV AH,4CH
INT 21H

MOV AH,4CH
INT 21H

ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2 ;CALL New_Line
MOV DX,13
INT 21H
RET
ENDP

END MAIN

;Title:- Input a Character and check Capital or Small or Number or Special Character in Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P

Page 32 of 58
INT 21H
ENDM

.MODEL SMALL
.STACK 100H

.DATA
str1 DB "Please Enter a Chracter: $"
str2 DB "It is a Capital Letter $"
str3 DB "It is a Small Letter $"
str4 DB "It is Number$"
str5 DB "It is a special Chracter$"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT str1

MOV AH,1
INT 21H
MOV BL,AL

CALL New_Line

CMP BL,48

JGE Level1

Print str5

MOV AH,4CH
INT 21H

Level1:
CMP BL,57

JGE Level2

PRINT str4
MOV AH,4CH
INT 21H

Level2:
CMP BL,65
JGE LEVEL3

print str5
MOV AH,4CH
INT 21H

Level3:
CMP BL,90

Page 33 of 58
JGE Level4

PRINT str2
MOV AH,4CH
INT 21H

Level4:
CMP BL,122
JGE LEVEL5
PRINT str3
MOV AH,4CH
INT 21H

LEVEL5:
PRINT str5
MOV AH,4CH
INT 21H

MOV AH,4CH
INT 21H

ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2
MOV DX,13
INT 21H
RET
ENDP

Blank_Space PROC
MOV AH,2
MOV DX,32
INT 21H
RET
ENDP

END MAIN

Lab 6:
Looping

Page 34 of 58
;Title:- Print 0 to 9 Digit in Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

Print MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H

.DATA
STR1 DB "Printing 0-9: $"

.CODE
MAIN PROC

MOV AX,@DATA
MOV DS,AX

MOV CX,10
MOV BL,48
Print STR1

L1:
MOV AH,2
MOV DL,BL
INT 21H
INC BL
CALL Space

LOOP L1

MOV AH,4CH
INT 21H
ENDM

Space PROC
MOV AH,2
MOV DL,20H
INT 21H
RET
ENDP

;Title:- Print A to Z Letter in Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

Page 35 of 58
PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Printing A-Z: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

MOV BL,41H
MOV CX,26

PRINT STR1

L1:
MOV AH,2
MOV DL,BL
INT 21H
CALL SPACE
INC BL

LOOP L1

MOV AH,4CH
INT 21H
ENDM

SPACE PROC
MOV AH,2
MOV DL,20H
INT 21H
RET
ENDP

;Title:- Print A to Z to A Letter in Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H

Page 36 of 58
.DATA
STR1 DB "Printing A-Z-A: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

MOV CX,51

MOV BL,41H
MOV BH,1

PRINT STR1

L1:
CMP BH,25
JLE L2

MOV AH,2
MOV DL,BL
INT 21H
DEC BL
JMP L3

L2:
MOV AH,2
MOV DL,BL
INT 21H
INC BL
JMP L3

L3:
CALL SPACE
INC BH
LOOP L1

MOV AH,4CH
INT 21H
ENDM

SPACE PROC
MOV AH,2
MOV DL,20H
INT 21H
RET
ENDP

;Title:- Exit The Program When Input will be Capital 'X' or Small 'x' in Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

Page 37 of 58
PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H

.DATA
STR1 DB "Please Enter Inputs: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1

INPUT:

MOV AH,1
INT 21H
MOV BL,AL
CALL SPACE
JMP Capital_X

Capital_X:

CMP BL,58H
JNE Small_x
JMP Exit

Small_x:

CMP BL,78H
JNE INPUT
JMP Exit

Exit:
MOV AH,4CH
INT 21H

ENDM

SPACE PROC
MOV AH,2
MOV DL,20H
INT 21H
RET

Page 38 of 58
ENDP

Lab 7:
Multiplication and division operation
i. ;Title:- Take two input in two digit numbers and find sum in Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Please Enter First Number: $"
STR2 DB "Please Enter Second Number: $"
STR3 DB "Summation is: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1

MOV AH,1
INT 21H
SUB AL,48

MOV BL,10
MUL BL
MOV BH,AL

MOV AH,1
INT 21H
SUB AL,48

ADD BH,AL

Page 39 of 58
CALL New_Line

PRINT STR2
MOV AH,1
INT 21H
SUB AL,48

MUL BL
MOV CL,AL

MOV AH,1
INT 21H
SUB AL,48

ADD CL,AL

ADD CL,BH

CALL New_Line

PRINT STR3

MOV BL,10
MOV AX,0
MOV AL,CL
DIV BL
MOV BL,AL
MOV BH,AH

ADD BL,48
ADD BH,48

MOV AH,2
MOV DL,BL
INT 21H

MOV AH,2
MOV DL,BH
INT 21H

MOV AH,4CH
INT 21H
ENDM

New_Line PROC
MOV AH,2

Page 40 of 58
MOV DL,10
INT 21H

MOV AH,2
MOV DL,13
INT 21H
RET
ENDP

ii. ;Title:- Program For Generating Fibonacci Sequence Till 7th Position in Assembly
Language

;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Fibonacci Sequence Till 7th Position: $"
CNT DB ?
A DB ?
B DB ?
C DB ?
D DB ?

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

MOV BL,0
MOV BH, 1
MOV CX,5
MOV CNT,1

PRINT STR1

START:
CMP CNT,1

Page 41 of 58
JE Print_0

CMP CNT,2
JE Print_1

LOOPS:
ADD BL,BH
MOV B,BL

MOV BL,BH
MOV BH,B

ADD B,48

MOV AH,2
MOV DL,B
INT 21H

CALL SPACE

LOOP LOOPS

JMP END

Print_0:
MOV C,BL
ADD C,48

MOV AH,2
MOV DL,C
INT 21H

INC CNT
CALL SPACE
JMP START

Print_1:
MOV D,BH
ADD D,48

MOV AH,2
MOV DL,D
INT 21H

INC CNT
CALL SPACE

Page 42 of 58
JMP START

END:
MOV AH,4CH
INT 21H
ENDP

SPACE PROC
MOV AH,2
MOV DL,20H
INT 21H
RET
ENDP

Lab 8:
Array and Stack
i. ;Title:- Input Numbers in Array and Display Them in Assembly Language
;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Enter The Number(1-9): $"
STR2 DB "Enter The Elements(1-9): $"
STR3 DB "Elements are: $"
ARR DB 10 DUP (?)

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1
MOV AH,1
INT 21H
MOV AH,0

SUB AX,48
MOV BX,AX
MOV CX,BX

CALL New_Line

Page 43 of 58
PRINT STR2

MOV SI,1

Input:
MOV AH,1
INT 21H
MOV ARR[SI],AL
INC SI
LOOP Input

MOV SI,1
MOV CX,BX

CALL New_Line
PRINT STR3

Output:
MOV AH,2
MOV DL,ARR[SI]
INT 21H
INC SI
CALL SPACE
LOOP Output

MOV AH,4CH
INT 21H

ENDP

New_Line PROC
MOV AH,2
MOV DL,0AH
INT 21H
MOV AH,2
MOV DL,0DH
INT 21H
RET
ENDP

SPACE PROC
MOV AH,2
MOV DL,20H
INT 21H
RET
ENDP

ii. ;Title:- Input Numbers & PUSH to Stack & POP From Stack in Assembly Language
;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P

Page 44 of 58
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Enter Numbers to Push Stack: $"
STR2 DB "Numbers Are Poping From Stack: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1
MOV BL,1

LOOPS:
MOV AH,1
INT 21H

CMP AL,0DH
JE New_Line

PUSH AX
INC BL
JMP LOOPS

DISPLAY:
POP AX
MOV AH,2
MOV DX,AX
INT 21H

CALL SPACE

DEC BL
CMP BL,1
JE END
JMP DISPLAY

New_Line:
MOV AH,2
MOV DL,0AH
INT 21H

MOV AH,2
MOV DL,0DH
INT 21H

PRINT STR2

Page 45 of 58
JMP DISPLAY

END:
MOV AH,4CH
INT 21H
ENDP

SPACE PROC
MOV AH,2
MOV DL,20H
INT 21H
RET
ENDP

Lab 9:
Logic operation
;Title:- Using Logic Instruction(AND)Take a Lower Case Letter as Input and Convert into Upper Case Letter in
Assembly Language

;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Enter a Small Letter: $"
STR2 DB "Capital Letter is: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1
MOV AH,1
INT 21H

MOV BL,AL
CALL NEW_LINE

AND BL,0DFH

PRINT STR2
MOV AH,2
MOV DL,BL

Page 46 of 58
INT 21H

MOV AH,4CH
INT 21H
ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2
MOV DX,13
INT 21H
RET
ENDP

i. ;Title:- Using Logic Instruction(OR)Take a Upper Case Letter as Input and Convert
into Lower Case Letter in Assembly Language
;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Enter a Capital Letter: $"
STR2 DB "Small Letter is: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1
MOV AH,1
INT 21H

MOV BL,AL
CALL NEW_LINE

OR BL,20H

PRINT STR2
MOV AH,2
MOV DL,BL
INT 21H

END:
MOV AH,4CH

Page 47 of 58
INT 21H
ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2
MOV DX,13
INT 21H
RET
ENDP

ii. ;Title:- Using Logic Instruction(XOR) Take Any Case Letter as Input and Convert
into Opposite Case Letter in Assembly Language
;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Enter Any Letter: $"
STR2 DB "You Entered Capital Letter!$"
STR3 DB "You Entered Small Letter!$"
STR4 DB "Capital Letter Will be: $"
STR5 DB "Small Letter Will be: $"
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1
MOV AH,1
INT 21H
MOV BL,AL
CALL NEW_LINE

CMP BL,65

JGE LEVEL1

LEVEL1:
CMP BL,90

JLE CAPITAL

CMP BL,97

Page 48 of 58
JGE SMALL

CAPITAL:
OR BL,20H

PRINT STR2
CALL New_Line
PRINT STR5

MOV AH,2
MOV DL,BL
INT 21H
JMP END

SMALL:
AND BL,0DFH

PRINT STR3
CALL New_Line
PRINT STR4

MOV AH,2
MOV DL,BL
INT 21H

END:
MOV AH,4CH
INT 21H
ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2
MOV DX,13
INT 21H
RET
ENDP

Lab 10:
Shift and Rotation operation and Test

i. ;Title:- Using Logic Instruction(TEST) Take a Number(0-9) as Input and Check


Whether Number is Even or Odd in Assembly Language
;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P

Page 49 of 58
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Number is Even$"
STR2 DB "Number is Odd$"
STR3 DB "Enter a Number(0-9): $"
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR3

MOV AH,1
INT 21H

TEST AL,1
JZ EVEN
JMP ODD

EVEN:
CALL NEW_LINE
PRINT STR1
JMP END

ODD:
CALL NEW_LINE
PRINT STR2

END:
MOV AH,4CH
INT 21H
ENDP

New_Line PROC
MOV AH,2
MOV DX,10
INT 21H
MOV AH,2
MOV DX,13
INT 21H
RET
ENDP

ii. ;Title:- Find Even and Odd Elements in Array in Assembly Language
;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9

Page 50 of 58
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Enter the Number(1-9): $"
STR2 DB "Enter The Array Elements(1-9): $"
STR3 DB "Even Numbers are: $"
STR4 DB "Odd Numbers are: $"
ARR DB 10 DUP (?)

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1
MOV AH,1
INT 21H

XOR AH,AH
SUB AX,48

MOV CX,AX
MOV BL,AL

MOV SI,1

Call New_Line

PRINT STR2

INPUT:
MOV AH,1
INT 21H
MOV ARR[SI],AL
INC SI
LOOP INPUT

CALL NEW_LINE

PRINT STR3

MOV SI,1
XOR CX,CX
MOV CL,0

CHECK:
CMP CL,BL
JE CHECK2

TEST ARR[SI],1

Page 51 of 58
JZ EVEN
INC SI
INC CL
JMP CHECK

EVEN:
MOV AH,2
MOV DL,ARR[SI]
INT 21H
MOV DL," "
INT 21H
INC SI
INC CL
JMP CHECK

CHECK2:
CALL NEW_LINE

PRINT STR4

MOV SI,1
XOR CX,CX
MOV CL,0

CHECK3:
CMP CL,BL
JE END

TEST ARR[SI],1
JNZ ODD

INC CL
INC SI
JMP CHECK3

ODD:
MOV AH,2
MOV DL,ARR[SI]
INT 21H
MOV DL," "
INT 21H
INC SI
INC CL
JMP CHECK3

END:
MOV AH,4CH
INT 21H
ENDP

New_Line PROC
MOV AH,2
MOV DL,0AH
INT 21H

Page 52 of 58
MOV AH,2
MOV DL,0DH
INT 21H
RET
ENDP

iii. ;Title:- Using SHIFT/ROTATE Instruction Take 8 Bits (Only 0,1) as Input And
Reversely Print Them in Assembly Language
;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Enter 8 Bits To Reverse (Only 0,1): $"
STR2 DB "Reversed Bits Are: $"

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1

MOV CX,8
MOV AH,1
LL1:
INT 21H
SHR AL,1
RCR BL,1
LOOP LL1

MOV CX,8
LL2:

SHR BL,1
RCL BH,1
LOOP LL2

CALL New_Line
PRINT STR2

MOV AH,2
MOV CX,8
LL3:

Page 53 of 58
SHR BH,1
JC ONE
MOV DL,48
INT 21H
JMP SKIP

ONE:
MOV DL,49
INT 21H
SKIP:
LOOP LL3

MOV AH,4CH
INT 21H

MAIN ENDP

New_Line PROC
MOV AH,2
MOV DL,0AH
INT 21H

MOV AH,2
MOV DL,0DH
INT 21H
RET
ENDP

Lab 11:
General problem

i. ;Title:- Take Two Inputs and Find How Many Bits Need to Exchange to Convert
Each Other in Assembly Language
;Purpose: Solve Some Easy Problem in Assembly Language

PRINT MACRO P
MOV AH,9
LEA DX,P
INT 21H
ENDM

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB "Enter The First Number: $"

Page 54 of 58
STR2 DB "Enter The Second Number: $"
STR3 DB "Counted Bit Number is: $"
VAR1 DB ?
.CODE

MAIN PROC
MOV AX,@DATA
MOV DS,AX

PRINT STR1

MOV AH,1
INT 21H
SUB AL,48
MOV BL,AL

CALL New_Line

PRINT STR2

MOV AH,1
INT 21H
SUB AL,48
MOV BH,AL

XOR BL,BH

MOV VAR1,0

MOV CX,8

CALL New_Line

PRINT STR3

LL:

TEST BL,1
JZ SR
INC VAR1
SR:
SHR BL,1
LOOP LL

ADD VAR1,48
MOV AH,2

Page 55 of 58
MOV DL,VAR1
INT 21H

MOV AH,4CH
INT 21H

MAIN ENDP

New_Line PROC
MOV AH,2
MOV DL,0AH
INT 21H

MOV AH,2
MOV DL,0DH
INT 21H
RET
ENDP

ii. Write an assembly language program to take sequence of number and push into
stack and show in reverse order.

.MODEL SAMLL
.STACK 100H
.DATA
A DB 'ENTER INPUT NUMBER IS: $'
A1 DB 0DH,0AH, 'YOUR RESULT IS: $'

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

XOR CX,CX

LEA DX,A
MOV AH,9
INT 21H

MOV AH,1
INT 21H

WHILE:

Page 56 of 58
CMP AL,0DH
JE END_WHILE
PUSH AX
INC CX
INT 21H
JMP WHILE

END_WHILE:
LEA DX,A1
MOV AH,9
INT 21H

MOV DL,0DH
MOV AH,2
INT 21H
MOV DL,0AH
INT 21H

JCXZ EXIT

TOP:

POP DX
INT 21H
LOOP TOP

EXIT:

MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

Page 57 of 58
Lab 12:

Lab Final Test

Lab Final Test, demonstration and report submission and viva voce.

Assessment and Marks Distribution

 Attendance and Performance (AP) (10%)


 Capstone Project Presentation (25%)
 Lab Test (LT) (25%)
 Lap Report (LR) (10%)
 Lab Final(LF) (30%)

Krishna Chandro Ray


Lecturer, Dept. of CSE
Varendra University , Rajshahi.

Page 58 of 58

You might also like