Professional Documents
Culture Documents
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.
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
SEGMENT REGISTERS:
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:
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.
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.
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.
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).
6
2.1 MULTI BYTE ADDITION
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:
8
2.2 MULTI BYTE SUBTRACTION
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:
10
2.3 8 BIT MULTIPLICATION (UNSIGNED)
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:
11
EXERCISE:
12
2.4 16 BIT MULTIPLICATION (UNSIGNED)
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:
13
EXERCISE:
14
2.5 8 BIT DIVISION(UNSIGNED)
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:
16
2.6 16 BIT DIVISION(UNSIGNED)
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:
17
EXERCISE:
18
2.7 8-BIT MULTIPLICATION (SIGNED)
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:
20
2.8 8-BIT DIVISION (SIGNED)
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:
22
2.9 ASCII ADDITION
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:
23
EXERCISE:
24
2.10 ASCII SUBTRACTION
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:
25
EXERCISE:
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.
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
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:
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
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:
32
EXERCISE:
1. How can we differentiate between a positive number and a negative number?
33
3.2 PACKED TO UNPACKED BCD
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:
35
3.3 BCD to ASCII CONVERSION
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:
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
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:
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
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:
41
EXERCISE:
42
4.3 SORTING(ASCENDING)
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)
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
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
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
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.
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:
54
EXERCISE PROGRAMS:
55
5.1 READING KEYBOARD WITH ECHO
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:
56
EXERCISE:
57
5.2 READING KEYBOARD WITHOUT ECHO
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:
58
EXERCISE:
59
5.3 DISPLAYING A CHARACTER
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:
61
5.4 DISPLAYING A STRING
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:
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:
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
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:
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
70
EXERCISE:
71
2. 8279 – KEYBOARD/DISPLAY INTERFACING -1
APPARATUS:
1. 8086 TRAINER KIT
2. 8279 STUDY CARD
3. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
.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
APPARATUS:
4. 8086 TRAINER KIT
5. 8279 STUDY CARD
6. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
.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
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
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
APPARATUS:
1 8051 Microcontroller Kit
2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
OBSERVATIONS:
Input: [9000h] =
[9001h] =
Output: [9002h] =
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:
OBSERVATIONS:
EXERCISE:
1.2 SUBTRACTION
85
APPARATUS:
1 8051 Microcontroller Kit
2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
OBSERVATIONS:
Input: [9000h] =
[9001h] =
Output: [9002h] =
EXERCISE:
1.3 MULTIPLICATION
86
APPARATUS:
1 8051 Microcontroller Kit
2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
OBSERVATIONS:
Input: [9000h] =
[9001h] =
Output: [9002h] =
[9003h] =
EXERCISE:
1.4 DIVISION
87
APPARATUS:
1 8051 Microcontroller Kit
2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
OBSERVATIONS:
Input: [9000h] =
[9001h] =
Output: [9002h] =
[9003h] =
EXERCISE:
2. DATA TRANSFER
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:
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)
(b)
(c)
OBSERVATIONS:
(a)
90
(b)
(c)
RESULT:
A value is copied into RAM locations using various addressing modes and
observed the differences.
EXERCISE
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
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
EXERCISE:
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
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
EXERCISE:
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:
EXERCISE:
EXERCISE PROGRAMS:
94
95
Expected Questions from Microprocessors:-
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.
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