You are on page 1of 103

INSTRUCTIONS TO THE STUDENTS

1. Students are required to attend all labs.

2. Students will work in a group of two in hardware laboratories and


individually in computer laboratories.

3. While coming to the lab bring the lab manual cum observation book, record
etc.

4. Take only the lab manual, calculator (if needed) and a pen or pencil to the
work area.

5. Before coming to the lab, prepare the prelab questions. Read through the
lab experiment to familiarize yourself with the components and assembly sequence.

6. Utilize 3 hours time properly to perform the experiment and noting down the
readings. Do the calculations, draw the graph and take signature from the
instructor.

7. If the experiment is not completed in the prescribed time, the pending work
has to be done in the leisure hour or extended hours.

8. You will be expected to submit the completed record book according to the
deadlines set up by your instructor.

9. For practical subjects there shall be a continuous evaluation during the


semester for 25 sessional marks and 50 end examination marks.

10. Of the 25 marks for internal, 15 marks shall be awarded for day-to-day
work and 10 marks to be awarded by conducting an internal laboratory test.

1
2
1. INTRODUCTION TO 8086, MASM/TASM

This chapter is intended to serve as an introduction to the programming and


some features of 8086 microprocessor. The users are requested to read 8086
architecture and organization of 8086 for better understanding.

The 8086 programming model includes general purpose registers, segment


registers, flag register, base and pointer registers whose functions are briefly given
below

SEGMENT REGISTERS:

Code segment register – CS – stores the base address of code segment.


Stack segment register – SS – stores the base address of the stack.
Data segment register – DS – stores the base address of the data.
Extra segment register – ES – stores the base address of the extra segment.

INDEX REGISTERS:

Source index register – SI – stores the base address of the source data.
Destination index register – DI – stores the base address of the destination data.

POINTER REGISTERS:

Instruction pointer – IP – stores the address of next instruction.


Stack pointer – SP – stores the address at the top of the stack.
Base pointer – BP – stores the base address.

GENERAL PURPOSE REGISTERS:

Accumulator – AX – used in all arithmetic instructions.


Base register – BX – used to store base addresses while programming.
Counter register – CX – used as counter during programming.
Destination register – DX - used to store base addresses while programming.
Extended accumulator – DX: AX – used in some arithmetic instructions.
All these 16 bit registers can also be used as a pair of 2 8-bit registers.

FLAG REGISTER:

The flag register in 8086 is of 16 bit wide in which only 9 bits are used as flags and
the other bits are in don’t care condition. For complete flag format the users are
requested to refer to the books, here only the functions of each flags are briefly
given in order to be helpful while programming.
A flag is a flip-flop, which is set or reset after an operation according to the
data conditions of the result in the accumulator and other registers.

1. Zero flag – Z: The flag is set to 1 when the result is zero, otherwise it is reset.
2. Carry flag (barrow) – CY: If an arithmetic operation results in a carry, the CY
flag is set, otherwise it is reset.
3. Sign flag – S: The sign flag is set if the MSB bit of the result is one, otherwise

3
it is reset.
4. Parity flag – P : If the result has an even number of 1s, the flag is set, for odd
number of 1s the flag is reset.
5. Direction flag – D: This flag selects increment or decrement mode for the DI
and/or SI registers during string instructions. If D=1, the registers are
automatically decremented; if D=0, the registers are automatically
incremented.
6. Overflow flag – O: Overflow occurs when signed numbers are added or
subtracted. An overflow indicates that the result has exceeded the capacity of
the machine.
7. Trap flag – T: The trap flag enables trapping through an on chip debugging
feature.
8. Interrupt flag – I: The interrupt flag controls the operation of INTR input pin.
If I=1 INTR is enabled otherwise it is disabled.
9. Auxiliary carry flag – AC: The auxiliary carry holds the carry( half carry) after
addition or barrow after subtraction between bit positions 3 and 4 of the
result. This bit is tested in special instructions like DAA and DAS.

INSTRUCTION SET OF 8086

An instruction is a command to the microprocessor to perform a given task on


specified data. Each instruction has two parts: one is task to be performed, called
the operation code (opcode) and the second is the data to be operated on, called the
operand. The entire group of instructions, called the instruction set, determines what
function the microprocessor can perform.

The 8086 instructions can be classified into following categories depending on


their functions.

DATA TRANSFER INSTRUCTIONS:


This group of instructions copies the data from a location called source to
another location called destination, without modifying the contents of the source. The
one more specialty of this group is they will not effect any of the flags in the flag
register. The data transfer may be between registers, memory location and a
register, immediate data and memory or register and between I/O device and the
accumulator.

ARITHMETIC INSTRUCTIONS:
These instructions perform arithmetic operations such as addition,
subtraction, increment and decrement. The flags are affected by this group of
instructions depending on the results they produce but some special instructions will
not effect flags.

LOGICAL, SHIFTOR ROTATE INSTRUCTIONS:


These instructions perform various logical operations such as AND, OR, NOT,
compare etc. These instructions will also effect flags.

BRANCHING INSTRUCTIONS:
This group of instructions alters the sequence of program execution either
conditionally or unconditionally. Flags are generally used to generate conditions in
case of 1st type of branch instructions.
MACHINE CONTROL INSTRUCTIONS:

4
These instructions control machine functions such as halt, interrupt and do
nothing etc.

STRING INSTRUCTIONS:
These instructions special and serve the purpose of operations on strings.

MASM/TASM

EDITOR
An editor is a program, which allows you to create a file containing the assembly
language statements for your program. As you type in your program, the editor
stores the ASCII codes for the letters and numbers in successive RAM locations.
When you have typed in all of your programs, you then save the file on a floppy of
hard disk. This file is called source file. The next step is to process the source file
with an assembler. In the MASM assembler, you should give your source file name
the extension, .ASM

ASSEMBLER
An assembler program is used to translate the assembly language mnemonics for
instructions to the corresponding binary codes. When you run the assembler, it reads
the source file of your program the disk, where you saved it after editing on the first
pass through the source program the assembler determines the displacement of
named data items, the offset of labels and puts this information in a symbol table.
On the second pass through the source program, the assembler produces the binary
code for each instruction and inserts the offset etc that is calculated during the first
pass. The assembler generates two files on floppy or hard disk. The first file called
the object file is given the extension. OBJ. The object file contains the binary codes
for the instructions and information about the addresses of the instructions. The
second file generated by the assembler is called assembler list file. The list file
contains your assembly language statements, the binary codes for each instructions
and the offset for each instruction. In MASM assembler, MASM source file name ASM
is used to assemble the file. Edit source file name LST is used to view the list file,
which is generated, when you assemble the file.

LINKER
A linker is a program used to join several object files into one large object file and
convert to an exe file. The linker produces a link file, which contains the binary
codes for all the combined modules. The linker however doesn’t assign absolute
addresses to the program, it assigns is said to be relocatable because it can be put
anywhere in memory to be run. In MASM, MLINK source filename is used to link the
file.

DEBUGGER
A debugger is a program which allows you to load your object code program into
system memory, execute the program and troubleshoot are debug it the debugger
allows you to look at the contents of registers and memory locations after your
program runs. It allows you to change the contents of register and memory locations
after your program runs. It allows you to change the contents of register and
memory locations and return the program. A debugger also allows you to set a break
point at any point in the program. If you inset a breakpoint the debugger will run the
program up to the instruction where the breakpoint is set and stop execution. You

5
can then examine register and memory contents to see whether the results are
correct at that point. In MASM, the filename is used to debug the file.

DEBUGGER FUNCTIONS:
1. Debugger allows to look at the contents of registers and memory locations.
2. We can extend 8-bit register to 16-bit register which the help of extended register
option.
3. Debugger allows setting breakpoints at any point with the program.
4. The debugger will run the program up to the instruction where the breakpoint is
set and then stop execution of program. At this point, we can examine registry and
memory contents at that point.

COMMANDS TO EXECUTE A GIVEN ALP.

1. ASSMEBLINIG : masm <file name.asm> <Enter>


2. LINKING : link <file name.obj> <Enter>
3. DEBUGGING : debug <file name.exe> <Enter>

DEBUGGER COMMANDS

DUMP: To see the specified memory contents D memory location first address last
address (While displays the set of values stored in the specified range, which is given
above)
Eg: d 0100 0105 <cr>
Display the contents of memory locations from 100 to 105(including).

ENTER: To enter data into the specified memory locations(s).


E memory location data data data data data …<cr>
Eg: e 1200 10 20 30 40 ….
Enters the above values starting from memory locations 1200 to 1203, by loading 10
into 1200,20 into 1201 and soon.

GO: To execute the program


G address <cr>: executes from current IP to the address specified
G first address last addresses <cr>: executes a set of instructions specified between
the given addresses.

QUIT: To exit from the debugger.


Q <cr>
REGISTER: Shows the contents of Registers
R register name
Eg: r ax Shows the contents of register.

TRACE: To trace the program instruction by instruction.


T = 0100 <cr>: traces only the current instruction. (Instruction specified by IP)
T = 0100 02 <cr>: Traces instructions from 100 to 101, here the second argument
specifies the number of instructions to be traced.

UNASSEMBLE: To unassembled the program.


Shows the opcodes along with the assembly language program.
U 100 <cr>: unassembled 32 instructions starting from 100th location.
U 0100 0109 <cr>: unassebles the lines from 100 to 104

6
2.1 MULTI BYTE ADDITION

AIM: To write a program to add two multi byte numbers.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
NUM1 DD 11223344H
NUM2 DD 55667788H
RES DD 00000000H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV SI,OFFSET NUM1
MOV DI,OFFSET NUM2
MOV BX,OFFSET RES
MOV CX,03
SUB AX,AX
MOV AL,[SI]
MOV DL,[DI]
ADD AL,DL
MOV [BX],AL
BACK: INC SI
INC DI
INC BX
MOV AL,[SI]
MOV DL,[DI]
ADC AL,DL
MOV [BX],AL
LOOP BACK
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: NUM1=

NUM2=

OUTPUT: RES=

RESULT:
Multi byte addition is performed and results are observed using MASM.

7
EXERCISE:

1. Why is add with carry instruction adc is used in the loop?


2. What is the purpose served by BX register?
3. Why addition is done with AL register why not with AX?
4. What is the other instruction which can be used instead of MOV SI,offset num1?

8
2.2 MULTI BYTE SUBTRACTION

AIM: To write a program to subtract two multi byte numbers.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
NUM2 DD 55667788H
NUM1 DD 11223344H
RES DD 00000000H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV SI,OFFSET NUM2
MOV DI,OFFSET NUM1
MOV BX,OFFSET RES
MOV CX,03
SUB AX,AX
MOV AL,[SI]
MOV DL,[DI]
SUB AL,DL
MOV [BX],AL
BACK: INC SI
INC DI
INC BX
MOV AL,[SI]
MOV DL,[DI]
SBB AL,DL
MOV [BX],AL
LOOP BACK
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: NUM1=

NUM2=

OUTPUT: RES=

RESULT:

Multi byte subtraction is performed and results are observed using MASM

9
EXERCISE:

1. Why is subtract with carry instruction is used in the loop?


2. What is the purpose served by BX register?
3. Why subtraction is done with AL register why not with AX?
4. What is the other instruction which can be used instead of MOV DI, offset NUM2?

10
2.3 8 BIT MULTIPLICATION (UNSIGNED)

AIM: To write a program to multiply two 8-bit unsigned numbers.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
NUM1 DB 0FFH
NUM2 DB 0AAH
RESULT DB 00
RESULT1 DB 00
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, NUM1
MOV BL, NUM2
MUL BL
MOV RESULT, AL
MOV RESULT1, AH
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: NUM1=

NUM2=
OUTPUT: RES=

RES1=

RESULT:

8-bit unsigned multiplication is performed and results are observed using


MASM.

11
EXERCISE:

1. AL and BL are used for multiplying why not AX & BX?


2. Instead of using MOV BL is it not possible to MUL num2?
3. What is the instruction used for signed multiplication?

12
2.4 16 BIT MULTIPLICATION (UNSIGNED)

AIM: To write a program to multiply two 16-bit unsigned numbers.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
NUM1 DW 0FFFFH
NUM2 DW 0FFFFH
RESULT DW 00
RESULT1 DW 00
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,NUM1
MOV BX,NUM2
MUL BX
MOV RESULT,AX
MOV RESULT1,DX
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: NUM1=

NUM2=
OUTPUT: RESULT=

RESULT1=
RESULT:

16-bit Multiplication is performed and results are observed using MASM.

13
EXERCISE:

1. Why AL & BL are not used in this program?


2. If result exceeds 32 bit, where is it stored?

14
2.5 8 BIT DIVISION(UNSIGNED)

AIM: To write a program to perform division on two 8-bit unsigned numbers.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
NUM1 DB 0FFH
NUM2 DB 0AAH
QUOTIENT DB 00
REMAINDER DB 00
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,0
MOV DX,0
MOV AL,NUM1
MOV BL,NUM2
DIV BL
MOV QUOTIENT,AL
MOV REMAINDER,AH
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: NUM1=

NUM2=

OUTPUT: QUOTIENT=

REMAINDER=

RESULT:

Division of two 8-bit numbers is performed and results are observed using
MASM.

15
EXERCISE:

1. Why is the registers DX & AX made zero in the above program?


2. Where is the remainder in 8 bit division?
3. Where is the quotient in 8 bit division?
4. Which interrupt is used when a divide overflow error occurs?

16
2.6 16 BIT DIVISION(UNSIGNED)

AIM: To write a program to perform division on two 16-bit unsigned numbers.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
NUM1 DW 0FFFFH
NUM2 DW 0AAAAH
QUOTIENT DW 00
REMAINDER DW 00
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,0
MOV DX,0
MOV AX,NUM1
MOV BX,NUM2
DIV BX
MOV QUOTIENT,AX
MOV REMAINDER,DX
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: NUM1=

NUM2=

OUTPUT: QUOTIENT=

REMAINDER=

RESULT:

16-bit division is performed and results are observed using MASM.

17
EXERCISE:

1. What happens if DX register contains a nonzero value before DIV instruction?


2. What is the instruction used for signed division?
3. In the above program instead of DIV BX is it possible to use DIV num2?

18
2.7 8-BIT MULTIPLICATION (SIGNED)

AIM: To write a program to multiply two 8-bit signed numbers.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
NUM1 DB 0A5H
NUM2 DB 20H
RES DW 00H
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
SUB AX,AX
MOV AL,NUM1
MOV BL,NUM2
IMUL BL
MOV RES,AX
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: NUM1=

NUM2=

OUTPUT: RES=

RESULT:

8-bit signed multiplication is performed and results are observed using MASM.

19
EXERCISE:

1. What is the difference between IMUL and MUL?


2. What is the use of instruction CBW?
3. What is the use of instruction CWD?

20
2.8 8-BIT DIVISION (SIGNED)

AIM: To write a program to perform division on two 8-bit signed numbers.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
NUM1 DB 0D5H
NUM2 DB 20H
QUO DB 0H
REM DB 0H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
XOR AX,AX
MOV AL,NUM1
CBW
MOV BL,NUM2
IDIV BL
MOV QUO,AL
MOV REM,AH
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: NUM1=

NUM2=

OUTPUT: QUO=

REM=
RESULT:
8-bit signed division is performed and results are observed using MASM.

21
EXERCISE:

1. What is the purpose of XOR AX,AX?


2. What is the difference between IDIV and DIV?
3. What is the use of instruction CBW & CWD?

22
2.9 ASCII ADDITION

AIM: To write a program to perform ASCII addition.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
IP1 DB '9',0DH,0AH
IP2 DB '6',0DH,0AH
RES DB 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
XOR AX,AX
MOV AL,IP1
ADD AL,IP2
AAA
MOV RES,AL
MOV AH,4CH
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT: IP1=

IP2=

OUTPUT: RES=

RESULT:

ASCII addition is performed and results are observed using MASM.

23
EXERCISE:

1. What is the purpose of ASCII addition?


2. What is the instruction used for ASCII addition?
3. Why do we make use of instruction ORL AX,3030H ?
4. Why is aaa after addition?

24
2.10 ASCII SUBTRACTION

AIM: To write a program to perform ASCII subtraction.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
IP1 DB '9',0DH,0AH
IP2 DB '6',0DH,0AH
RES DB 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
XOR AX,AX
MOV AL,IP1
SUB AL,IP2
AAS
MOV RES,AL
MOV AH,4CH
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT: IP1=

IP2=

OUTPUT: RES=

RESULT:

ASCII subtraction is performed and results are observed using MASM.

25
EXERCISE:

1. What is the purpose of ASCII subtraction?


2. What is the instruction used for ASCII subtraction?
3. Why do we make use of instruction ORL AX,3030H ?
4. Why is aas after addition?

26
EXERCISE PROGRAMS

27
3.1.1 SUM OF DIGITS OF A GIVEN 16-BIT NUMBER

AIM: To write a program to find the sum of digits of a given 16-bit number 16-Bit
number should be given at ds:2000, and result will be available at ds:3000h.

APPARATUS: Computer system installed with MASM

PROGRAM:

CODE SEGMENT

ASSUME CS:CODE

START:
MOV AX,DS:2000H
MOV SI,0010H
MOV DX,0000H
MOV BX,0
MOV CX,0004H
NEXT:DIV SI
ADD BX,DX
MOV DX,0000H
LOOP NEXT
MOV DS:3000H,BX
INT 3

CODE ENDS
END START

OBSERVATIONS:

INPUT: DS:2000H =

OUTPUT: DS:3000H =

RESULT:

Sum of digits of a given 16-bit number is performed and results are observed using
MASM.

28
EXERCISE:
1. What is the logic used to find sum of digits of a given number?
2. What a LOOP instruction would do in the above program?

29
3.1.2 CHECK WHETHER A GIVEN 16-BIT NUMBER IS EVEN OR
ODD

AIM: To write a program to check whether a given 16-bit number is even or odd.

Note: 16-Bit number should be given at ds:2000, and result will be available
at ds:3000h. If the number is even, store ffffh at ds:3000h, and if it is odd, store
1111h at ds:3000H

APPARATUS: Computer system installed with MASM

PROGRAM:

CODE SEGMENT

ASSUME CS:CODE

START:
MOV AX,DS:2000H
MOV BX,0002H
MOV CX,0000H
DIV BX
CMP DX,CX
JE EVEN_NUM
MOV DS:3000H,1111H
JMP EXIT
EVEN_ NUM:MOV DS:3000H,0FFFFH
EXIT:INT 3

CODE ENDS
END START

OBSERVATIONS:

INPUT: DS:2000H =

OUTPUT: DS:3000H =

RESULT:

Checking whether a given 16-bit number is even or odd is performed and


results are observed using MASM.

30
EXERCISE:
1. How can we differentiate between an even number and an odd number?

31
3.1.3 CHECK WHETHER A GIVEN 16-BIT NUMBER IS POSITIVE
OR NEGATIVE

AIM: To write a program to check whether a given 16-bit number is positive or


negative.
Note: 16-Bit number should be given at ds:2000, and result will be available
at ds:3000h. If the number is positive, store ffffh at ds:3000h, and if it is negative,
store 1111h at ds:3000h

APPARATUS: Computer system installed with MASM

PROGRAM:

CODE SEGMENT

ASSUME CS:CODE

START:
MOV AX,DS:2000H
ROL AX,1
JC NEG_NUM
MOV DS:3000H,0FFFFH
JMP EXIT
NEG_NUM:MOV DS:3000H,1111H
EXIT:INT 3

CODE ENDS
END START

OBSERVATIONS:

INPUT: DS:2000H =

OUTPUT: DS:3000H =

RESULT:

Checking whether a given 16-bit number is positive or negative is performed


and results are observed using MASM.

32
EXERCISE:
1. How can we differentiate between a positive number and a negative number?

33
3.2 PACKED TO UNPACKED BCD

AIM: To write a program to convert a packed BCD number to unpacked BCD


number.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
BCDIP DB 56H
UBCDOP DW 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
XOR AX,AX
MOV AL, BCDIP
MOV DL,AL
AND AL,0F0H
MOV CL,4
ROR AL,CL
MOV BH,AL
AND DL,0FH
MOV BL,DL
MOV UBCDOP,BX
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: BCDIP=

OUTPUT: UBCDOP=

RESULT:
Conversion of packed BCD to unpacked BCD is performed and results are
observed using MASM.

34
EXERCISE:

1. What is the purpose of the instruction ROR AL, CL?


2. What is the purpose of the instruction AND AL, 0FH & AND AL,0F0H in the
program.?
3. What is the expansion of UPBCD?
4. What is the use of DAA instruction?
5. What is the reason for packing unpacked BCD?
6. What is common between unpacked BCD and ASCII?

35
3.3 BCD to ASCII CONVERSION

AIM: To write a program to convert a BCD number to its equivalent ASCII


number.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
BCDIP DB 56H
ASCOP DW 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
XOR AX,AX
MOV AL, BCDIP
MOV DL,AL
AND AL,0F0H
MOV CL,4
ROR AL,CL
MOV BH,AL
AND DL,0FH
MOV BL,DL
ADD BX,3030H
MOV ASCOP,BX
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: BCDIP=

OUTPUT: ASCOP=

RESULT:

Conversion of BCD to ASCII is performed and results are observed using


MASM.

36
EXERCISE:
1. What is the difference between adding 30h and OR 30H to a BCD number to
conversion to ASCII?
2. Why unpacking is necessary during the conversion?
3. What is the ASCII character for symbol A?
4. What is the ASCII character for symbol zero ‘0’?

37
EXERCISE PROGRAMS:

38
4.1 BLOCK TRANSFER

AIM: To write a program to transfer a block of characters from one place to


another place using string instructions.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
SRC DB 'EMPTY VESSELS MAKE MUCH NOISE',24H
DATA ENDS
EXTRA SEGMENT
DST DB 12 DUP(0)
EXTRA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,EXTRA
MOV ES,AX
MOV SI,OFFSET SRC
MOV DI,OFFSET DST
CLD
MOV CX,29
REP MOVSB
NOP
MOV AH,4CH
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT: SRC=

OUTPUT: DST=

RESULT:

Block transfer is performed and results are observed using MASM.

39
EXERCISE:
1. If the DF=1, will the SI and DI register decremented?
2. The destination memory is pointed by which register combination?
3. The source is pointed to by which register combination?

40
4.2 STRING REVERSAL

AIM: To write a program to reverse a given string.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
STRING1 DB 'EMPTY'
STRLEN EQU ($-STRING1)
STRING2 DB 5 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV BX,OFFSET STRING1
MOV SI,BX
MOV DI,OFFSET STRING2
ADD DI,STRLEN
CLD
MOV CX,STRLEN
A1: MOV AL,[SI]
MOV ES:[DI],AL
INC SI
DEC DI
LOOP A1
;REP MOVSB
;NOP
MOV AH,4CH
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT: STRING1=

OUTPUT: STRLEN=

STRING2=

RESULT:

String reversal is performed and results are observed using MASM.

41
EXERCISE:

1. Why BX register is added with ‘5’?


2. Why MOVS instruction is not used?
3. What is the function of LODS and STOS instructions?

42
4.3 SORTING(ASCENDING)

AIM: To write a program to sort a given list of numbers in ascending order.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
LIST DB 12H, 34H, 21H, 56H, 32H
COUNT EQU 5
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV DI, OFFSET LIST
MOV CL, COUNT
DEC CL
INC DI
LOOP1:MOV DL,CL
LOOP2:MOV AL,[DI]
CMP AL,[DI +1]
JNC Proceed
XCHG AL,[DI+1]
MOV [DI],AL
PROCEED: INC DI
LOOP LOOP2
NOP
MOV CL,DL
LOOP LOOP1
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: LIST:

OUTPUT: LIST(SORTED):

RESULT:
Sorting of a given list of numbers is performed and results are observed using
MASM.

43
EXERCISE:
1. What is the sorting technique used in above program?
2. Are there any other ways to sort a list?

44
4.4 SORTING(DESCENDING)

AIM: To write a program to sort a given list of numbers in descending order.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
LIST DB 12H, 34H, 21H, 56H, 32H
COUNT EQU 5
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV DI, OFFSET LIST
MOV CL, COUNT
DEC CL
INC DI
LOOP1:MOV DL,CL
LOOP2:MOV AL,[DI]
CMP AL,[DI +1]
JC Proceed
XCHG AL,[DI+1]
MOV [DI],AL
PROCEED: INC DI
LOOP LOOP2
NOP
MOV CL,DL
LOOP LOOP1
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT: LIST:

OUTPUT: LIST(SORTED):

RESULT:
Sorting of a given list of numbers is performed and results are observed using
MASM.

45
EXERCISE:
1. What is the sorting technique used in above program?
2. Are there any other ways to sort a list?

46
4.5 STRING INSERTION

AIM: To write a program to insert a word in the given sentence.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
STRING1 DB 'EMPTY VESSELS MORE NOISE$'
STRLEN EQU ($-STRING1)
DATA ENDS
EXTRA SEGMENT
STRING2 DB STRLEN+5 DUP(0)
EXTRA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START:
MOV AX,DATA
MOV DS,AX
MOV SI,OFFSET STRING1
MOV DI,OFFSET STRING2
CLD
MOV CX,14
REP MOVSB
MOV DL,5
BACK: MOV AH,01
INT 21H
STOS STRING2
DEC DL
JNZ BACK
MOV CX,11
REP MOVSB
NOP
MOV AH,4CH
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT: NUM1=

NUM2=

OUTPUT: RES=

RESULT:
String insertion is performed and results are observed using MASM.

47
EXERCISE:
1. Why register ‘DI’ is loaded with 5?
2. What is the function of rep movsb?
3. What is the purpose of mov ah,01h / int 21h?

48
4.6 STRING DELETION

AIM: To delete a word from the given sentence.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
STRING1 DB 'EMPTY VESSELS MAKE MORE NOISE$'
STRLEN EQU ($-STRING1)
DATA ENDS

EXTRA SEGMENT
STRING2 DB STRLEN-5 DUP(0)
EXTRA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,EXTRA
MOV ES,AX
MOV SI,OFFSET STRING1
MOV DI,OFFSET STRING2
CLD
MOV CX,13
REP MOVSB
CLD
MOV SI,18
MOV CX,12
REP MOVSB
MOV AH,4CH
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT: STRING1=

STRLEN=

OUTPUT: STRING2=

RESULT:
String deletion is performed and results are observed using MASM.

49
EXERCISE:
1. What is the purpose of string length?
2. What does ‘equ’ stands for?
3. What is the purpose of label start after the end directive?

50
4.7 LENGTH OF THE STRING

AIM: To write a program to find the length of the given string.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
STRING1 DB 'EMPTY VESSELS MAKE MORE NOISE$'
STRLEN EQU ($-STRING1)
RES DB 0
CORT DB 'STRLENGTH FOUND CORRECT$'
INCORT DB 'STRLENGTH FOUND INCORRECT$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
SUB CL,CL
MOV BL,STRLEN
MOV SI,OFFSET STRING1
BACK: LODSB
INC CL
CMP AL,'$'
JNZ BACK
MOV RES,CL
CMP CL,BL
JZ CORRECT
MOV DX,OFFSET INCORT
MOV AH,09
INT 21H
CORRECT:MOV DX,OFFSET CORT
MOV AH,09
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT: STRING1=

STRLEN=

OUTPUT: RES=
RESULT:
Length of a string is performed and results are observed using MASM.

51
EXERCISE:
1. What is the operation performed by the instruction cmp al,$ ?
2. What is function 09h / int 21h performed?
3. Why SI is not been incremented is the program?

52
4.8 STRING COMPARISION
AIM: To write a program to compare two strings.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
STRING1 DB 'EMPTY'
STRLEN EQU ($-STRING1)
NOTSFUL DB 'STRINGS ARE UNEQUAL$'
SFUL DB 'STRINGS ARE EQUAL$'
DATA ENDS
EXTRA SEGMENT
STRING2 DB 'EMPTY'
EXTRA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,EXTRA
MOV ES,AX
MOV SI,OFFSET STRING1
MOV DI,OFFSET STRING2
CLD
;MOV CX,LENGTH STRING1
MOV CX,STRLEN
REP CMPSB
JZ FORW
MOV AH,09H
MOV DX,OFFSET NOTSFUL
INT 21H
JMP EXITP
FORW:MOV AH,09H
MOV DX,OFFSET SFUL
INT 21H
EXITP: NOP
MOV AH,4CH
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT: STRING1 =
STRING2 =
STRLEN =
OUTPUT:
RESULT:
String comparison is performed and results are observed using MASM.

53
EXERCISE:

1. What is the significance of CLD?


2. How does CMPSB perform the comparison?

54
EXERCISE PROGRAMS:

55
5.1 READING KEYBOARD WITH ECHO

AIM: To write a program to read the keyboard with echo.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
CHAR DB 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AH,01H
INT 21H
MOV CHAR, AL
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:

Reading a keyboard is performed and results are observed using MASM.

56
EXERCISE:

1. Write a brief note on DOS interrupts.


2. What does AH register hold when INT 21H is called?

57
5.2 READING KEYBOARD WITHOUT ECHO

AIM: To write a program to read the keyboard without echo.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
CHAR DB 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AH,08H
INT 21H
MOV CHAR, AL
INT 3
CODE ENDS
END START

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:

Reading a keyboard is performed and results are observed using MASM.

58
EXERCISE:

1. Write a brief note on DOS interrupts.


2. What does AH register hold when INT 21H is called?

59
5.3 DISPLAYING A CHARACTER

AIM: To write a program to displaying a given string.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
CHAR DB ‘*’
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AH, 02H
MOV DL,CHAR
INT 21H
MOV AX, 4C00H
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:

Displaying a character on screen is performed and results are observed using MASM.

60
EXERCISE:

1. Write a brief note on DOS interrupts.


2. What does AH register hold when INT 21H is called?

61
5.4 DISPLAYING A STRING

AIM: To write a program to displaying a given string.

APPARATUS: Computer system installed with MASM

PROGRAM:

DATA SEGMENT
MESSAGE DB 10, 13,’HAPPY NEW YEAR’, 10, 13,’$’
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET MESSAGE
MOV AH, 09H
INT 21H
MOV AX, 4C00H
INT 21H
CODE ENDS
END START

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:

Displaying a string on screen is performed and results are observed using MASM.

62
EXERCISE:
1. Write a brief note on DOS interrupts.
2. What does AH register hold when INT 21H is called?

63
EXERCISE PROGRAMS:

64
65
1. 8255 – PPI INTERFACING -1

AIM: configure 8255A such that port A and port B as an output ports .Execute the
program at 0000:2000h

APPARATUS:

1. 8086 TRAINER KIT


2. 8255 STUDY CARD
3. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:

ADDRESS OP-CODES LABELS MNEMONICS COMMENTS

0000:2000 BA 46 FF MOVW DX, 0FF46 ; INITIALIZE 8255


0000:2003 B0 80 MOVB AL, 80 ; PORTS AS O/P
0000:2005 EE OUTB DX, AL
0000:2006 B0 55 MOVB AL, 55 ; OUTPUT DATA AT
0000:2008 BA 40 FF RPT: MOVW DX, 0FF40 ; PORT A
0000:200B EE OUTB DX, AL
0000:200C F6 D0 NOTB AL ; INVERT THE DATA AND
0000:200E BA 42 FF MOVW DX, 0FF42 ; OUTPUT THIS
0000:2011 EE OUTB DX, AL ; VALUE AT PORT B
0000:2012 B9 00 00 MOVW CX, 0
0000:2015 E2 FE LOOP 2015 ; INTRODUCE DELAY
0000:2017 E2 FE LOOP 2017 ; AND REPEAT
0000:2019 E9 EC FF JMP RPT (2008)

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:
8086 Interfacing with 8255 is done and results are observed.

66
EXERCISE:

67
8255 – PPI INTERFACING -2

AIM: Configure 8255A such that port A as an output and port B as an input.
Execute the program at 0000:2000h.

APPARATUS:

1. 8086 TRAINER KIT


2. 8255 STUDY CARD
3. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:

ADDRESS OP-CODES LABELS MNEMONICS COMMENTS

0000:2000 BA 46 FF MOVW DX, 0FF46 ; INITIALIZE 8255


0000:2003 B0 82 MOVB AL, 82 ; PORT A AS OUTPUT
0000:2005 EE OUTB DX, AL ; PORT B AS INPUT
0000:2006 BA 42 FF RPT: MOVW DX, 0FF42 ; READ VALUE FROM
0000:2009 EC INB AL, DX ; PORT B
0000:200A F6 D0 NOTB AL ; INVERT THE DATA
0000:200C BA 40 FF MOVW DX, 0FF40 ; AND OUTPUT THIS
0000:200F EE OUTB DX, AL ; VALUE AT PORT A
0000:2010 E9 F5 FF JMP RPT(2006) ; REPEAT PROCESS

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:

8086 Interfacing with 8255 is done and results are observed.

68
EXERCISE:

69
8255 – PPI INTERFACING -3

AIM: Configure 8255A such that port A as an input and port B as an output.
Execute the program at 0000:2000H.

APPARATUS:

1. 8086 TRAINER KIT


2. 8255 STUDY CARD
3. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:

ADDRESS OP-CODES LABELS MNEMONICS COMMENTS

0000:2000 BA 46 FF MOVW DX, 0FF46 ; INITIALIZE 8255


0000:2003 B0 90 MOVB AL, 90 ; PORT B AS OUTPUT
0000:2005 EE OUTB DX, AL ; PORT A AS INPUT
0000:2006 BA 40 FF RPT: MOVW DX, 0FF40 ; READ VALUE FROM
0000:2009 EC INB AL, DX ; PORT A
0000:200A BA 42 FF MOVW DX, 0FF42 ; OUTPUT THE SAME
0000:200D EE OUTB DX, AL ; VALUE AT PORT B
0000:200E E9 F5 FF JMP RPT (2006) ; REPEAT PROCESS

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:

8086 Interfacing with 8255 is done and results are observed.

70
EXERCISE:

71
2. 8279 – KEYBOARD/DISPLAY INTERFACING -1

AIM: To interface keyboard/display with 8086 microprocessor and display a given


sentence on the display board.(Left Entry)

APPARATUS:
1. 8086 TRAINER KIT
2. 8279 STUDY CARD
3. ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

CMDREG EQU 0FFEBH


DATAREG EQU 0FFE9H

.8086
.MODEL TINY
.STACK 32
.DATA
.CODE

ORG 2000H
START:
MOV AX,CS
MOV DS,AX
MOV AL,10H ; ENCODED SCAN-8CHAR 8 BIT LEFT ENTRY
MOV DX,CMDREG
OUT DX,AL
MOV AL,090H ;WRITE RAM AUTO INCREMENT
OUT DX,AL
MOV CX,08
CLEAR:MOV AL,00
MOV DX,DATAREG
OUT DX,AL
LOOP CLEAR
BACK: MOV DX,CMDREG
IN AL,DX ; READ THE COMMAND R4EGISTER TO GET THE 8279 STATUS
AND AL,07 ; NUMBER OF KEYS PRESSED IS IN THE LOWER 3 BITS
MASK ;THESE AND CHECK IF NOT ZERO. IF ZERO NO KEY
PRESSED
JZ BACK
MOV BX,OFFSET SSCHARLUT
MOV AL,040H ; READ THE FIRST RAM ADDRESS OF FIFO
OUT DX,AL
MOV DX,DATAREG ;
IN AL, DX
AND AL,01FH
XLAT ; CONVERT THE KEY READ TO THE SS CODE
MOV DX,DATAREG
OUT DX,AL ; DISPLAY AT THE CURRENT DIGIT POSITION

72
JMP BACK
SSCHARLUT:
SS0 DB 3FH ;0
SS1 DB 6H ;1
SS2 DB 5BH ;2
SS3 DB 4FH ;3
SS4 DB 66H ;4
SS5 DB 6DH ;5
SS6 DB 7DH ;6
SS7 DB 07H ;7
SS8 DB 7FH
SS9 DB 6FH
SSA DB 77H
SSB DB 7CH
SSC DB 39H
SSD DB 5EH
SSE DB 79H
SSF DB 71H
END START

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:
8086 Interfacing with 8279 is done and results are observed.

73
EXERCISE:
1. How many pins does 8279 IC have?
2. How many scan lines are available on 8279?
3. How many row-sense pins are there on 8279?
4. How many registers are there in 8279?
5. What is the purpose of command & data registers?

74
8279 – KEYBOARD/DISPLAY INTERFACING -2

AIM: To interface keyboard/display with 8086 microprocessor and display a given


sentence on the display board.(Right Entry)

APPARATUS:
4. 8086 TRAINER KIT
5. 8279 STUDY CARD
6. ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

CMDREG EQU 0FFEBH


DATAREG EQU 0FFE9H

.8086
.MODEL TINY
.STACK 32
.DATA
.CODE

ORG 2000H
START:
MOV AX,CS
MOV DS,AX
MOV AL,0H ; ENCODED SCAN-8CHAR 8 BIT LEFT ENTRY
MOV DX,CMDREG
OUT DX,AL
MOV AL,090H ;WRITE RAM AUTO INCREMENT
OUT DX,AL
MOV CX,08
CLEAR: MOV AL,00
MOV DX,DATAREG
OUT DX,AL
LOOP CLEAR
BACK: MOV DX,CMDREG
IN AL,DX ; READ THE COMMAND R4EGISTER TO GET THE 8279 STATUS
AND AL,07 ; NUMBER OF KEYS PRESSED IS IN THE LOWER 3 BITS
MASK ;THESE AND CHECK IF NOT ZERO. IF ZERO NO KEY
PRESSED
JZ BACK
MOV BX,OFFSET SSCHARLUT
MOV AL,040H ; READ THE FIRST RAM ADDRESS OF FIFO
OUT DX,AL
MOV DX,DATAREG
IN AL, DX
AND AL,01FH
XLAT ; CONVERT THE KEY READ TO THE SS CODE
MOV DX,DATAREG
OUT DX,AL ; DISPLAY AT THE CURRENT DIGIT POSITION

75
JMP BACK
SSCHARLUT:
SS0 DB 3FH ;0
SS1 DB 6H ;1
SS2 DB 5BH ;2
SS3 DB 4FH ;3
SS4 DB 66H ;4
SS5 DB 6DH ;5
SS6 DB 7DH ;6
SS7 DB 07H ;7
SS8 DB 7FH
SS9 DB 6FH
SSA DB 77H
SSB DB 7CH
SSC DB 39H
SSD DB 5EH
SSE DB 79H
SSF DB 71H
END START

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:
8086 Interfacing with 8279 is done and results are observed.

76
EXERCISE:

1.

77
3. 8259 – PROGRAMMABLE INTERUPT CONTROLLER

AIM: To interface Programmable Interrupt Controller with 8086 microprocessor.

APPARATUS:
1. 8086 TRAINER KIT
2. 8259 STUDY CARD
3. ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

ORG 1000H
MOV AL,17H
OUT 0C0H, AL
MOV AL,08H
OUT 0C2H, AL
MOV AL,01H
OUT 0C2H, AL
MOV AL,FEH
OUT 0C2H, AL
STI
HERE: JMP HERE
MOV AL,20H
LOOP 0C0H,AL
INT 02H

Interrupt Vector:-
0000:0200 00h
0000:0021 12h
0000:0022 00h
0000:0023 00h

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:
8086 Interfacing with 8279 is done and results are observed.

78
EXERCISE:
1.

79
4. 8251 – USART

AIM: To interface USART (Universal Synchronous Asynchronous Receiver


Transmitter) with 8086 microprocessor.

APPARATUS:
1 8086 TRAINER KIT
2 8251 STUDY CARD
3 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

TRANSMITTER END:

ORG 1000H
MOV AL,36H
OUT 0CEH, AL
MOV AL,10H
OUT 0C8H, AL
MOV AL,00H
OUT 0C8H, AL
MOV AL,4EH
OUT 0C2H, AL
MOV AL,37H
OUT 0C2H, AL
LOOP1:IN AL,0C2H
AND AL,04H
JZ LOOP1
MOV AL,41H
OUT 0C0H,AL
INT 02H

RECEIVER END:

ORG 1200H
MOV AL,36H
OUT 0CEH, AL
MOV AL,10H
OUT 0C8H, AL
MOV AL,00H
OUT 0C8H, AL
MOV AL,4EH
OUT 0C2H, AL
MOV AL,37H
OUT 0C2H, AL
LOOP2:IN AL,0C2H
AND AL,04H
JZ LOOP2
IN AL,0C0H
MOV BX,I500H

80
MOV [BX],AL
INT 02H

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:
8086 Interfacing with 8279 is done and results are observed.

EXERCISE:

81
EXERCISE PROGRAMS:

82
83
1.1 8-BIT ADDITION

AIM: To perform addition of two 8-bit hex numbers stored in consecutive


memory locations and store the result in the next memory location.

APPARATUS:
1 8051 Microcontroller Kit
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

CLC C ;Clear carry flag


MOV DPTR,#9000
MOVX A,@DPTR
MOV B,A ;First data in B
INC DPTR
MOVX A,@DPTR ;Second data in A
ADD A,B ;sum in A
INC DPTR
MOVX @DPTR,A ;Result in [9002h]
END: SJMP END ;Halt

OBSERVATIONS:
Input: [9000h] =
[9001h] =
Output: [9002h] =

RESULT: Addition of two 8-bit numbers stored at consecutive memory locations is


performed on 8051 microcontroller and the result is stored at the next memory
location.

EXERCISE:

16-BIT ADDITION

AIM: To perform addition of two 16-bit hex numbers using immediate addressing
and store the result in memory location.

84
APPARATUS:
1 8051 Microcontroller Kit
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

CLC C ;Clear carry flag


MOV A,#LSB1
ADDC A,#LSB2
MOV DPTR,#9001 ;First data in B
MOVX @DPTR,A
MOV A,#MSB1 ;Second data in A
ADDC A,#MSB2 ;sum in A
INC DPTR
MOVX @DPTR,A ;Result in [9002h]
END: SJMP END ;Halt

OBSERVATIONS:

Example: DATA1 = 1234h


DATA2 = 5678h
Output: [9000h] =
[9001h] =

RESULT: Addition of two 16-bit numbers is performed on 8051 microcontroller and


the result is stored in memory.

EXERCISE:

1.2 SUBTRACTION

AIM: To perform subtraction of two 8-bit hex numbers stored in consecutive


memory locations and store the result in the next memory location.

85
APPARATUS:
1 8051 Microcontroller Kit
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

CLC C ;Clear carry flag


MOV DPTR,#9001
MOVX A,@DPTR
MOV B,A ;Second data in B
DEC DPTR
MOVX A,@DPTR ;First data in A
SUBB A,B ;Difference in A
INC DPTR
INC DPTR
MOVX @DPTR,A ;Result in [9002h]
END: SJMP END ;Halt

OBSERVATIONS:

Input: [9000h] =
[9001h] =
Output: [9002h] =

RESULT: Subtraction of two 8-bit numbers stored at consecutive memory locations


is performed on 8051 microcontroller and the result is stored at the next memory
location.

EXERCISE:

1.3 MULTIPLICATION

AIM: To perform multiplication of two 8-bit hex numbers stored in consecutive


memory locations and store the result in the next memory location.

86
APPARATUS:
1 8051 Microcontroller Kit
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

CLC C ;Clear carry flag


MOV DPTR,#9001
MOVX A,@DPTR
MOV B,A ;Second data in B
DEC DPTR
MOVX A,@DPTR ;First data in A
MUL AB ;Difference in A
INC DPTR
INC DPTR
MOVX @DPTR,A ;Result in [9002h]
MOV B,A ; and [9003h]
MOVX @DPTR,A
END: SJMP END ;Halt

OBSERVATIONS:

Input: [9000h] =
[9001h] =
Output: [9002h] =
[9003h] =

RESULT: Multiplication of two 8-bit numbers stored at consecutive memory


locations is performed on 8051 microcontroller and the result is
stored at the next memory location.

EXERCISE:

1.4 DIVISION

AIM: To perform multiplication of two 8-bit hex numbers stored in consecutive


memory locations and store the result in the next memory location.

87
APPARATUS:
1 8051 Microcontroller Kit
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

CLC C ;Clear carry flag


MOV DPTR,#9001
MOVX A,@DPTR
MOV B,A ;Second data in B
DEC DPTR
MOVX A,@DPTR ;First data in A
DIV AB ;Difference in A
INC DPTR
INC DPTR ;Quotient in
MOVX @DPTR,A ; [9002h] and
MOV B,A ;Remainder in
MOVX @DPTR,A ; [9003h]
END: SJMP END ;Halt

OBSERVATIONS:

Input: [9000h] =
[9001h] =
Output: [9002h] =
[9003h] =

RESULT: Division of two 8-bit numbers stored at consecutive memory locations is


performed on 8051 microcontroller and the result is stored at the next memory
location.

EXERCISE:

2. DATA TRANSFER

AIM: To Transfer a block of data from internal ROM to external RAM

APPARATUS:

88
1 8051 TRAINER KIT
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

ORG 0000H
START: MOV A,#00
MOV SP,#07H
MOV R3,#11
MOV DPTR,#200H
PUSH DPL
PUSH DPH
REP: MOV DPTR,#MESSAGE
MOV R2,A
MOVC A,@A+DPTR
POP DPH
POP DPL
MOVX @DPTR,A
INC DPTR
PUSH DPL
PUSH DPH
INC R2
MOV A,R2
DJNZ R3,REP
MESSAGE: DB "HELLO WORD"
END

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:
Block of data is transferred from ROM to RAM.

EXERCISE:

3. UNDERSTANDING ADDRESING MODES

AIM: To copy the value 55H into RAM memory locations 40H to 41H using
(a) Direct addressing mode,

89
(b) Register indirect addressing mode without a loop, and
(c) with a loop

APPARATUS:
1 8051 TRAINER KIT
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

(a)

MOV A,#55H ;load A with value 55H


MOV 40H,A ;copy A to RAM location 40H
MOV 41H.A ;copy A to RAM location 41H

(b)

MOV A,#55H ;load A with value 55H


MOV R0,#40H ;load the pointer. R0=40H
MOV @R0,A ;copy A to RAM R0 points to
INC R0 ;increment pointer. Now R0=41h
MOV @R0,A ;copy A to RAM R0 points to

(c)

MOV A,#55H ;A=55H


MOV R0,#40H ;load pointer.R0=40H,
MOV R2,#02 ;load counter, R2=3
AGAIN: MOV @R0,A ;copy 55 to RAM R0 points to
INC R0 ;increment R0 pointer
DJNZ R2,AGAIN ;loop until counter = zero

OBSERVATIONS:

(a)

90
(b)

(c)

RESULT:
A value is copied into RAM locations using various addressing modes and
observed the differences.

EXERCISE

4. UNDERSTANDING THE USAGE OF LCALL INSTRUCTION

AIM: To demonstrate the usage of LCALL instruction

91
APPARATUS:
1 8051 TRAINER KIT
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

ORG 0
BACK: MOV A,#55H ;load A with 55H
MOV P1,A ;send 55H to port 1
LCALL DELAY ;time delay
MOV A,#0AAH ;load A with AA (in hex)
MOV P1,A ;send AAH to port 1
LCALL DELAY
SJMP BACK ;keep doing this indefinitely

ORG 300H ;put DELAY at address 300H


DELAY: MOV R5,#0FFH ;R5=255 (FF in hex), counter
AGAIN: DJNZ R5,AGAIN ;stay here until R5 become 0
RET ;return to caller (when R5 =0)
END;

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:

Used LCALL instruction and observed the values of memory pointers

EXERCISE:

5. UNDERSTANDING THE USAGE OF ACALL INSTRUCTION

92
AIM: To demonstrate the usage of ACALL instruction

APPARATUS:
1 8051 TRAINER KIT
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

ORG 0
MOV A,#55H ;load A with 55H
BACK: MOV P1,A ;send 55H to port 1
ACALL DELAY ;time delay
CPL A ;complement reg A
SJMP BACK ;keep doing this indefinitely

ORG 300H ;put DELAY at address 300H


DELAY: MOV R5,#0FFH ;R5=255 (FF in hex), counter
AGAIN: DJNZ R5,AGAIN ;stay here until R5 become 0
RET
END ;end of asm file

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:

Used ACALL instruction and observed the values of memory pointers

EXERCISE:

6. UNDERSTANDING THREE MEMORY AREAS OF 00-FF

AIM: To understand three memory areas of 00-FF

93
APPARATUS:
1 8051 TRAINER KIT
2 ADAPTER, KEYBOARD, CABLES, ETC…

PROGRAM:

ORG 0000H

LJMP START

ORG 200H
START: MOV A,#41H
MOV 20H,A
MOV A,#42H
MOV R0,#20H
MOV @R0,A
MOV A,#43H
MOV 80H,A
MOV A,#44H
MOV R0,#80H
MOV @R0,A
END

OBSERVATIONS:

INPUT:

OUTPUT:

RESULT:

Used the memory areas of Controller and observed the differences.

EXERCISE:

EXERCISE PROGRAMS:

94
95
Expected Questions from Microprocessors:-

1. Who Invented 8086 microprocessor?


2. In which year 8086 microprocessor is invented?

96
3. How many address lines are available on 8086?
4. How many data lines are available on 8086?
5. Why address bus is unidirectional?
6. Whether data bus is unidirectional or bidirectional?
7. What is a bus?
8. If AL=0FFh and ADD AL,01h instruction is executed, what is the status of
status flags?
9. Under what condition bus contention occurs?
10. How can you avoid bus contention?
11. The segment 1234h and offset is 0022h, then the physical address is?
12. If an instruction is accessed by 8086 is 20ms, the time taken by 8088 is?
13. The no. of cycles required by 8086 for writing/reading to/from memory/IO
ports is?
14. Whether 8086 contains internal clock generator?
15. 8086 requires external clock signal with a duty cycle of?
16. In 8086 the lower bank of 8086 contains?
17. When ready pin of 8086 is at logic 0 then wait states are
18. The vectored interrupt in 8086 is?
19. Non vectored interrupt in 8086 is?
20. To restart from the initial state when ‘1’ is placed on 8086 RESET pin, the
duration for which the signal must present is?
21. The rate of transmission in serial mode is?
22. In serial I/O, data transmission takes place using which code?
23. USART converts data from which form to which from?
24. The inputs and outputs of 8251 are compatible with which logic?
25. Whether RS232C is compatible with TTL Logic?
26. If TxD output remains high the 8251 contains which characters?
27. In RS232C, RS stands for?
28. In RS 232C standard uses positive logic or negative logic?
29. Which transmission is used for high speed serial data transmission?
30. Expand DCE and DTE?
31. Which type of ADC is the fastest one?
32. Which type of ADC is the most expensive one?
33. Which type of ADC used DAC inside?
34. How many comparators are required by an 8-bit flash type ADC?

97
35. In 8259 if IR3, IR6, IR7 are activated, which interrupt has the highest
priority?
36. Which register in 8259 is used to disable interrupt requests?
37. Which ports are used in BSR mode of 8255?
38. Which port provides hand shaking signals in Mode1 & Mode2 of 8255?
39. What is the IC used for DMA transfer?
40. How many peripherals can be connected to 8237 at any point of time?
41. For bidirectional data transfer, 8255 is operated in which mode?
42. DMA will send a request signal to which pin of 8086?
43. Which instruction is used to return from the interrupt service procedure?
44. What are the ICs MC 1488 and MC 1489?
45. When accessing a memory location shared with a coprocessor, the signal
that prevents the coprocessor from accessing that location is?
46. There are two no. of 2Kx8 memory chips. How to obtain 4Kx8 memory?
47. When the processor has 32 address lines, how much memory can be
interfaced to that processor?
48. Whether Stepper Motor is an AC Motor or DC Motor?
49. Give any application of Stepper Motor in our real life?
50. What do you mean by interfacing?
Expected Questions from Microcontrollers:-
1. Who has introduced MCS-51 family of microcontrollers?
2. MCS-51 family of microcontrollers contains which ICs?
3. What is the difference between MP and MC?
4. Give any Example of Microcontrollers?
5. Is 8051 an 8-bit controller?
6. Why 8051 is an 8-bit controller?
7. What is the on chip ROM capacity of 8051?
8. What is the on chip RAM capacity of 8051?
9. How many IO ports are available on 8051 on chip?
10. How many timers are available on 8051 on chip?
11. Which version of 8051 doesn’t have on chip ROM?
12. Which version of 8051 contains EPROM on chip?
13. 8051 contains which type of ROM?
14. What is the purpose of ROM in 8051?
15. What is the purpose of RAM in 8051?

98
16. Whether ROM is accessible randomly or not?
17. What is the capacity of on chip EPROM on 8751?
18. Can you connect external program memory to 8051?
19. Can you connect external data memory to 8051?
20. What is the capacity of external program memory that can be connected to
8051?
21. What is the capacity of external data memory that can be connected to 8051?
22. How can you access internal program memory?
23. How can you access external program memory?
24. How is it possible to access both internal & external ROM using PC?
25. How can you access internal data memory?
26. How can you access external data memory?
27. Do you require any signal to access external data memory?
28. Do you require any signal to access external program memory?

29. What is the reason behind connecting only 64KB of external program memory?
30. What is the reason behind connecting only 64KB of external data memory?
31. Expand DPTR?
32. Is a DPTR an 8-bit register?
33. Can we access PC as two 8-bit registers?
34. Is there any register in 8086 similar to PC in 8051?
35. Expand SFR?
36. Is PC a special function register?
37. Whether external interrupts are edge triggered or level triggered type?
38. Expand ALE?
39. Expand PSEN?
40. What is the function of PSEN pin?
41. For serial communication the pins of which IO port is used?
42. Which register is used to operate 8051 in different modes?
43. What are the modes of operation of 8051?
44. Whether PCON is a bit addressable SFR?
45. Which port will hold the higher order address information during memory access?
46. Which Io port of 8051 doesn’t have dual function?
47. What is the Architecture of 8051?
48. What is stack?

99
49. What is the function of SP register?
50. The number of clock cycles in one machine cycle of 8051 is?
Key to the Questions on Microprocessors:-
1. Intel Corporation
2. 1974
3. 20 address lines
4. 16 data lines
5. The address bus is unidirectional because the information on the address
bus is always provided by the microprocessor.
6. Data bus is bidirectional.
7. Bus is a collection of signal lines. Generally they carry address, data and
control signals.
8. CF=1, PF=1, AF=1, ZF=1, SF=0 and OF=0
9. Bus contention occurs when two outputs trying to drive the same line.
10. Bus contention can be avoided by using tri-state condition which isolates one
of the outputs.
11. 12362h.
12. 40ms.
13. 4 clock cycles.
14. No
15. 33% duty cycle for its optimal functioning.
16. Even address locations.
17. Between T3 and T4 states.
18. NMI.
19. INTR.
20. 4 clock cycles.
21. Baud.
22. ASCII.
23. Parallel form to Serial.
24. TTL Logic.
25. No.
26. No data (Stop bits).
27. Recommended Standard.
28. Negative logic.
29. Synchronous transmission.

100
30. DCE stands for Data Communications Equipment and DTE stands for Data
Terminal Equipment.
31. Flash type ADC.
32. Successive Approximation ADC.
33. Successive Approximation ADC.
34. 8 Comparators.
35. IR3.
36. Interrupt Mask Register.
37. Only Port C bits.
38. Port C provides hand shaking signals.
39. 8237 or 8257
40. Four
41. Mode 2
42. HOLD pin.
43. IRET.
44. Voltage translators.

45. LOCK
46. By connecting address lines in serial and data lines parallel
47. 232 = 4GB
48. DC Motor
49. Printers, X-Y plotters, Hard disk/Floppy Disk Drives, etc.,
50. Interfacing means not only connecting the devices but also communicating
between them.

Key to the Questions on Microcontrollers:-

1. Intel Corporation
2. 8031, 8051, 8052, 8751 and 8752 Microcontrollers.
3. MP contains ALU, Control Unit and On chip memory where as
Microcontroller contains MP, ROM, RAM, IO Ports, Counters/Timers on
chip.
4. 8051
5. Yes
6. Because all the internal registers and accumulator are of 8-bit wide and they
can process 8-bit data.

101
7. 4KB
8. 128 bytes
9. 4 no. of 8-bit IO Ports
10. 2 no. of 16-bit Timers/Counters
11. 8031
12. 8751
13. Simple Read Only Memory
14. ROM is used for storing Programs hence it is called as Program Memory.
15. RAM is nothing but Data Memory and is used to store data
16. Yes
17. 4KB
18. Yes
19. Yes
20. 64KB
21. 64KB
22. Program Counter
23. Program Counter
24. Whenever we access external program memory, we use MOVX instruction
which distinguish the internal & external ROM.
25. By means of its address in the program instructions.
26. Data Pointer.
27. Yes. We require Logic ‘0’ on External Access pin.
28. No signal is required to access external program memory.
29. Because PC is a 16-bit register, the maximum memory that can be
interfaced externally is 216 = 64KB only.
30. DPTR is a 16-bit register; the maximum memory that can be interfaced
externally is 216 = 64KB only.
31. Data Pointer
32. DPTR is a 16-bit register, but we can access it as two 8-bit registers DPH &
DPL.
33. No, we can’t access PC as two 8-bit registers.
34. PC is very similar to IP register in 8086.
35. SFR stands for Special Function register.
36. No, PC is the only register which doesn’t come under SFR.
37. They can be programmed as either edge triggered or level triggered.

102
38. Address Latch Enable
39. PSEN stands for Program Store ENable.
40. PSEN is used to store program in external memory.
41. Port 3 pins are used for serial communication.
42. PCON(Power CONtrol) SFR is used.
43. Power Down Mode and Idle Mode.
44. No. PCON is not bit addressable.
45. Port 2 will hold the higher order address information during memory
access.
46. Port 1 pins have no dual functions.
47. The Architecture of 8051is called Harvard Architecture.
48. Stack is an area in internal RAM that is used in conjunction with certain
opcodes to store and retrieve data quickly.
49. SP holds an internal RAM address that is called top of the stack.
50. 12 clock cycles.

103

You might also like