Nothing Special   »   [go: up one dir, main page]

S4 EC Microprocessor Lab Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

COCHIN UNIVERSITY COLLEGE OF

ENGINEERING,KUTTANAD

EC DIVISION

MICROPROCESSOR LAB MANUAL

0
CONTENTS
I. Introduction to DEBUG ………….. 1
DEBUG program
DEBUG command list
Details of Commands
Questions
II. 8086 Programming using DEBUG ………….. 6
(i). Block move of data
(ii). Addition of 16 bit and 32 bit binary numbers
(iii). Subtraction of 16 bit and 32 bit binary numbers
(iv). Sum of array elements
III. Introduction to MASM ...…………. 11
IV. 8086 Programming using MASM ………….. 13
(i). Display a string
(ii). Input a character and display it in screen
(iii). Addition of two single digit numbers
(iv). Largest and Smallest in a given series
(v). Count even and odd numbers
(vi). Sorting an array in Ascending/Descending
(vii). Scan for a character in an array
(viii). Reverse a string
(ix). Addition of two two-digit numbers
(x). BCD Addition and Subtraction
(xi). Multiplication and Division of Binary Numbers
(xii). Code conversions (Binary-BCD)
(xiii). Square root of a number
(xiv). LCM and GCD
(xv). Fibonacci series
(xvi). Prime numbers
V. Familiarization of 8086 Microprocessor kit ……….. 17
VI. Question Bank ………… 21
VII. 8086 Instruction Set Summary ………… 25

1
I. Introduction to DEBUG
Aim: - To familiarize with the DEBUG program commands, to examine and modify the contents of the memory, to assemble
8086 with ASSEMBLER commands, and to execute 8086 instructions and programs with the trace and GO command.

DEBUG program
The DEBUG is a program supplied with MS-DOS. Its main function is to provide a suitable debugging environment for the 8086
assembly language under the IBM –PC system. The DEBUG offers a good platform for trouble shooting, executing and
observing the results of the assembly language programs. Its features including ability to examine and change the contents of
memory location or CPU registers, single stepping etc.
Familiar with the debugger is very important for assembly language programming, as it is nearly the closest channel between the
programmer and the computer. DEBUG accepts the number as hexadecimal number. Hence there is no need to specify the
format. It is case insensitive also.
Opening DEBUG Program
Go to Start-> Run. Open CMD →OK and type the prompt C: / > DEBUG and hit enter.
Then „-‟ dash (DEBUG prompt) followed by a cursor blinking appears. A valid command is accepted by using the Enter key.
DEBUG command list

_? displays a list of DEBUG commands as given below.


Assemble A [address]
Compare C Range address
Dump D [Range]
Enter E Address [List]
Fill F Range list
Go G [=Address] [Addresses]
Hex H Value1 Value2
Input I port
Load L [Address] [Drive][First sector] [Number]
Move M Range address
Name N [path name] [arglist]
Output O port byte
Proceed P [=Address] [Number]
Quit Q
Register R [Register]
Search S range list
Trace T [=Address] [Value]
Unassemble U [range]
Write W [Address] [Drive][First sector] [Number]
Allocate expanded memory XA [#Pages]
Deallocate expanded memory XD [#Handle]
Map expanded memory pages XM [L page] [P page] [handle]
Display expanded memory status XS

2
Some of these commands will be necessary to debug the assembly language programs that we write. When debug
command is issued, the state of the 8086 microprocessor is initiated with registers AX,BX,CX,DX,BP,SI,DI and the flags are
reset to zero, IP is initiated with 0100H and SP is loaded with FFEEH.
Details of Commands
1. The Dump or Display command:-
This command is used to examine the content of a memory location or a block of consecutive memory locations. By
default, the content of the Data Segment is displayed. But the contents of other segments can be displayed by
specifying the address in the form Base address: offset. The different formats of the dump command are as follows.
(a) _D [Starting address ][Length]
*Square brackets are used to indicate different elements of the command.
It is optional to specify the length. If not specified, the contents of 128 bytes locations starting from the address
„staring address‟ offset to the data segment will be displayed.
Eg. (1) _D 2000 The data in 128 locations from DS: 0000 are displayed, 16 bytes in a line.

(2)_D 0000 3 The contents of 4 locations will be displayed, since any count starts from zero.
(3)_D 128 bytes will be displayed as contents of the memory, beginning at the end of the last address
displayed.
(b) _D [Starting address] [ Ending address]
Eg. _D 0000 0002 The contents of only 3 bytes locations (of address 0000 to 0002) will be displayed.

2. The Enter command:-


This command helps to enter data into the memory locations. By default, the content of the Data Segment is edited. But
the contents of other segments can be edited by specifying the address in the form Base address: offset. The format of
the Enter command is as follows.
_E [Address] [List]
Eg. (1) _E 0200 0A 0B 0C 0D 0E 0F The 6 bytes 0A, 0B, 0C, 0D, 0E, 0F (all in hex) are entered into locations
starting from 0200.
(2) _E 0200 “ABCDEF” The ASCII values of A, B, C, D, E, F (6 bytes in hex) are entered into
locations starting from 0200.
(3) _E 0200 The present content of location 0200 will be displayed, and the value can be
enter here. Use the Space bar to edit consecutive memory locations.
To verify the data have been entered, check using the „D‟ command.

3
3. The Fill command:-
This command is used to fill a block of consecutive memory locations with the same data. The different formats of
the Fill command are as follows.
(a) _F [Starting address] [Ending address] [Data]
Eg. (1) _F 0200 020C 22 The data 22 is stored in whole range of locations from 0200 to 020C
(2) _F 0200 020C “hi”
(b) _F [Starting address] [Length] [Data]
Eg. (1) _F 0200 Lc 22 The data 22 is replicated 12 (C H) times starting from the address 0200
(2) _F 0200 Lc “hi”

4. The Move command :-


This command used to copy a block of data from one part of memory to another location in the same segment. The
format of this command is
_M [Starting address] [Ending address] [Destination address]
Eg. _M 0100 001F 0200 The contents of memory locations starting from 0100 to 001F is copied to the memory
locations starting from 0200 to 021F.
5. The Search command:-
This command searches memory for characters in a list. The default register is the DS register. If the characters are
found, the addresses are shown; otherwise, there is no response.
The format is
_S [starting address] [length] [data]
Eg. _S 0100 L24 „C‟ If the character „C‟ is found, it will show the corresponding addresses.
6. The Compare command:-
This command compares two areas in memory. The default register is the DS register. The different formats of the
Compare command are as follows.
(a) _C [Start of ‘from’ Address] [End of ‘from’ address][Start of ‘to’ address]
Eg. _C 0100 010f 0160
(b) _C [Start of ‘from’ address][Length of byte area] [Start of ‘to’ address]
Eg. C 0200 L24 0400
Each time unequal elements are found, the address and contents of that byte in both blocks are displayed. If the
contents are same, no data and address is displayed.

7. The Register command:-


This gives the contents of the registers at the particular time. Used to examine and modify the contents of internal
registers of 8086. The format is
_R [Register]
Here the command is R optionally followed by the register name. Execution of this register command causes the
current value of the register to be displayed. If the register name is not used then contents of all the registers are
displayed.

4
Eg. _R AX shows the content of AX. The examine register command is not yet complete. Note the colon(:) followed
by the cursor. We can now press the enter key to complete the command, leaving the register content unchanged, or
enter new value for AX following the colon and hit the enter key.
Eg. _R
The set/reset statuses of the flags are

Overflow Direction Interrupt Sign Zero Aux. Carry Parity Carry


Set OV DN EI NG ZR AC PE CY
Reset NV UP OI PL NZ NA PO NC

8. Assemble command:-
This command is used to write program lines in the debugger itself, execute it and view the result. Once the program
is typed in, it can be assembled and run.
_ A [Starting address]
„Starting address‟ is the address at which the machine code of the first instruction of the program is to be stored. If the
starting address is not specified, the default address is 0100H.
Eg. _A This shows CS:IP value, IP=0100
_A 0200 This gives CS:IP value, IP=0200
The instruction to be assembled must be typed in following this address, and when the enter key is pressed, the instruction
gets assembled into machine code, stored in memory, and the starting address of the next instruction is displayed.

9. The Unassemble command:-


This command unassembles the instructions. The different formats of the „U‟ command are as follows.
(a) _U [Starting address] [Ending address]
Eg. _U 100 110 This unassembled the mnemonics stored in the address locations from 0100 H to 0110H.
(b) _U [Starting address] [Length]
Eg. _U 100 Lc This will un assemble 12 bytes (length c) of memory beginning at address 0100. Length is
obtained by subtracting beginning address from the address following the last instruction.
10. The Trace command:-
This command executes one or more instructions from the current CS: IP location or an optional address if specified.
The contents of the registers are shown after each instruction is executed. Check the contents of the data registers AX
and BX using „r‟ command.
A simple program example is given below
_A 100
0ACF:0100 MOV AL, FE
MOV BL, 01
ADD AL, BL
INT 20
Enter „T‟ command at DEBUG prompt and now check the contents of AX, and BX. Again enter „T‟ and note the
contents. Both AL and BL will contain the bytes you specified. Again enter „T‟ and note the contents. Now AL should
contain the sum.

5
To execute more than one instruction use the command „T‟ followed by the number of instructions to be executed. For
example, using _T2 shows the execution of two instructions with corresponding register contents and flag status.
11. The Go command:-
This command executes the program in memory. You can specify a starting address and a break point, causing the
program to stop at a given address. This is used for executing a program. General format is
_G [Starting address] [Breakpoint address]
The breakpoint address is the address of the end of the program segment that is, the address of the instruction at which
execution is to stop. After the execution, the complete internal state of the system is displayed. A simple program
example is given below
_A 100

0ACF:0100 MOV AX, 00FF


MOV BX, 0001
ADD AX, BX
MOV [0200], AX
INT 20

_G 100 The program starting at location 100h will be executed, and you‟ll see the following message on the screen.
„Program terminated normally.‟
_G 100 102
In this case the program will stop after executing the first instruction. This is what is called setting breakpoints. You
can set break points at various locations in your memory to debug any errors.
12. The Quit command
_Q Quitting from the DEBUG.

Questions:-
1. Load the data 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF in consecutive memory locations starting from 200.
2. Load FF in all memory locations between 100 to 11F.
3. Compare a block of data located from address DS: 100 through DS: 10F to equal sized block of data starting from
address DS: 200.
4. Search the memory from 100 through 10F for CC.
5. Move the block of data in memory starting from address DS: 200 through DS: 20F to the address range DS: 300
through DS: 30F.

6
II. 8086 Programming using DEBUG

Program (i):- Block move of data

Aim:- To write a program to move a block of memory from one location to other location. 10 numbers are stored
in memory locations starting from 1100H must be moved to 1400H onwards.

Program:-
Address Label Opcode & Operand Comments
(CS:IP)
0AFF:0100 MOV SI,1100 ;source address in SI
0AFF:0103 MOV DI,1400 ;destination address in DI
0AFF:0106 CLD ;clear DF for auto increment of SI & DI
0AFF:0107 MOV CX,000A ;length of data in CX
0AFF:010A NEXT: LODSB ;load first no. into AL from 1100H
0AFF:010B STOSB ;store byte from AL to 1400H
0AFF:010C LOOP 010A (NEXT) ;repeat above two steps until CX=0
0AFF:010E INT 20 ;stop

Procedure
1. Enter the program in memory locations starting from 0100H.
2. To enter the data, edit the memory locations using the command „e‟.
3. Check the registers using command „r‟.
4. For executing the program use command „g‟.
5. Check the result in memory using command„d‟.

Result

INPUT & OUTPUT: CARRY 00


i) INPUT 1 4283
INPUT 2 2931 Memory Address Content
SUM 6BB4 2000 83

7
2001 42 Memory Address Content
2500 31 2000 83
2501 29 2001 42
3000 B4 2002 00
3001 6B 2003 FF
3002 00 2500 31
2501 29
2502 FF
2503 01
3000 B4
3001 6B
3002 FF
3003 00
3004 01

ii) INPUT 1 FF004283


INPUT 2 01FF2931
SUM 00FF6BB4
CARRY 01

9
Program (ii):- Addition of 16 bit and 32 bit binary numbers
Aim:- To write a program to add (a) two 16 bit numbers (b) two 32 bit numbers
The numbers are at memory locations 2000H and 2500H; and the result should at 3000H onwards.
Program (a):- Addition of 16 bit binary numbers
Address Label Opcode & Operand Comments
(CS:IP)
0AFF:0100 MOV DI,3000 ; destination address in DI
0AFF:0103 MOV SI,2000 ; address of first no. in SI
0AFF:0106 MOV BX,2500 ; address of second no. in BX
0AFF:0109 CLC
0AFF:010A MOV AX,[SI] ;load first no. into AX
0AFF:010C ADC AX,[BX] ;add numbers and store result in AX
0AFF:010E MOV [DI],AX ;sum is stored at 3000H
0AFF:0110 INC DI
0AFF:0111 INC DI
0AFF:0112 JNC 0118 (END) ;if no carry go to END
0AFF:0114 MOV AL,01H
0AFF:0116 MOV [DI],AL ;carry is stored at 3002H
0AFF:0118 END: INT 20

Program (b):- Addition of 32 bit binary numbers


Address Label Opcode & Operand Comments
(CS:IP)
0AFF:0100 MOV DI,3000 ; destination address in DI
0AFF:0103 MOV SI,2000 ; address of first no. in SI
0AFF:0106 MOV BX,2500 ; address of second no. in BX
0AFF:0109 MOV CL,02 ;two words
0AFF:010B CLC
0AFF:010C BACK: MOV AX,[SI] ;load first no. into AX
0AFF:010E ADC AX,[BX] ;add numbers and store result in AX
0AFF:0110 MOV [DI],AX ;sum is stored
0AFF:0112 INC DI
0AFF:0113 INC DI
0AFF:0114 INC SI
0AFF:0115 INC SI
0AFF:0116 INC BX
0AFF:0117 INC BX
0AFF:0118 LOOP 010C (BACK) ;if CL ≠ 0 go to BACK
0AFF:011A JNC 0120 (END)
0AFF:011C MOV AL,01H
0AFF:011E MOV [DI],AL ;carry (MSB) is stored at 3004H
0AFF:0120 END: INT 20

Procedure
1. Enter the program in memory locations starting from 0100H.
2. To enter the data, edit the memory locations 2000H, 2500H using command „e‟.
3. Check the registers using command „r‟.
4. For executing the program use command „g‟.
5. Check the result at memory locations 3000H onwards using command„d‟.

Result:- Program to add two 16 bit numbers (4 digits) and two 32 bit numbers(8 digits) with 8086 microprocessor was executed.

10
Program (iii):- Subtraction of 16 bit and 32 bit binary numbers
Aim:- Write a program to subtract (a) two 16 bit numbers (b) two 32 bit numbers
The numbers are at memory locations 2000H and 2500H; and the result should at 3000H onwards.

Program (iv):- Sum of array elements


Aim:- Write a program to get the sum of all elements in an array of numbers. The length of array is given in
1100H and the array starts from 1101H. The result should at 1200H and 1201H.

11
III. Introduction to MASM
Aim: - To familiarize with the MASM assembler and important DOS interrupts.

MASM: - MASM is Microsoft‟s Macro Assembler. Assembler is a program, which translates symbolic
instructions (mnemonics) into machine language instructions. When code is written in assembly language, it is
easy if we can use labels (names) for memory locations. All constants and variables are given names so that they
can be referred by name. Managing and utilizing these labels (symbols) efficiently reflects the quality of an
assembler. Assemblers that support macros are called Macro Assembler. A macro is a name given to a sequence
of instruction lines.
MASM is an x86 high-level assembler for DOS and Microsoft Windows. It supports a wide variety of macro
facilities and structured programming idioms, including high-level functions for looping and procedures. The
16- Bit version of MASM runs under DOS and 32 bit version runs under Windows.
The sequence of program execution using MASM is given below.
1. Create Source File:- An editor is a program which allows you to create a file containing the assembly
language statements for your program. This file is called a source file. Open an editor, type the program and
save it with extension .asm in the BIN of MASM 611. Command to create a source file
C:\MASM\BIN> Edit filename. asm
2. Assembling:- The next step is to process the source file with an assembler. When you run the assembler, it
reads the source file of your program. On the first pass through the source program, the assembler
determines the displacement of named data items, the offset labels, etc. 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 offsets, etc. that it calculated during first pass.
C:\MASM\BIN > Masm filename. asm
The Assembler only finds syntax errors : It will not tell you whether program does what it is supposed to do.
To determine whether your program works, you have to run the program and test it.
3. Linking:- Next step is to process the object file with linker.
C:\MASM\BIN>LINK filename. obj This will give
Run File [Filename1.exe] : “filename1.exe”
List file [nul.map]: NUL
Libraries [.lib]: library name
Definitions File [nul.def]:
A Linker is a program used to join several object files into one layer object file.
On IBM PC – type Computers, You must run the LINK program on your .OBJ file even if it contains only one
assembly module. The linker produces a link file with the .EXE extension (an execution file).
4. Execute the program:-
Next Run C:\MASM\BIN> filename

DOS Interrupts: - DOS stands for Disk Operating System and is often used as shorthand for MD-DOS
(Microsoft DOS). It provides many functions for the access of Input/output devices, memory, files and process
control services. Software interrupts can be directly activated by the assembler invoking the number

12
corresponding to the desired interrupts with the INT instruction. Interrupts 20 to 3F are used by the DOS. Each
interrupt provides access to a particular DOS function.
DOS Interrupt 21H
Important function calls of interrupt type 21H are given below.
(a) Read the keyboard with echo
MOV AH, 01H
INT 21H
It reads the character from keyboard and its ASCII value in AL register. The key pressed is also echoed in
the screen.
(b) Read the keyboard without echo
MOV AH, 08H
INT 21H
It reads the character from keyboard and its ASCII value in AL register. The key pressed is not echoed in
the screen
(c) Write a character to the standard display unit
MOV DL, 32H
MOV AH, 02H
INT 21H
Displays a character whose ASCII value is stored in DL register. In this case, displays the number 2 on the
monitor.
(d) Display a character string on the screen
MOV AH, 09H
INT 21H
The logical address DS : DX should point to the beginning of the string. The memory content will be
displayed until the termination character $ reaches.
(e) Exit program
MOV AH, 4CH
INT 21H

Result:- Familiarized with the MASM assembler and important DOS interrupts.

13
IV. 8086 Programming using MASM
Program (1). Display a string
Aim:- Write an assembly language program to display the string “HELLO”, “RAINBOW”
Program:-
.model small
.Data Segment
Msg1 db 'HELLO$'
Msg2 db 0AH, 0DH,”RAINBOW$'
Data ends
.Code Segment
Start:
mov ax, data
mov ds, ax
lea dx, Msg1
mov ah,09h
int 21h
lea dx, Msg2
mov ah,09h
int 21h
mov ah,4ch
int 21h
Code ends
End start

Result:-

Program (2). Input a character and display it


Aim:- Write an assembly language program to input a character and display it on the next line.
Program:-
.model small
.Data Segment
Msg1 db “Input a character$”
Msg2 db 0AH, 0DH,”The character is$”
Data ends
.Code Segment
Start:
mov ax, data
mov ds, ax
lea dx, Msg1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl, al
lea dx, Msg2
mov ah,09h
int 21h
mov dl, bl
mov ah,02h
int 21h
mov ah,4ch
int 21h
Code ends
End start

Result:-

14
Program (3). Addition of two single digit numbers
Aim:- Write an assembly language program to add two single digit numbers. Accept both numbers from
keyboard and the sum should be displayed.
Program:-
assume cs:code,ds:data
data segment
m1 db 0ah,0dh,'enter the first number$'
m2 db 0ah,0dh,'enter the second number$'
msg3 db 0ah,0dh,'sum:$'
msg4 db 0ah,0dh,'carry:$'
data ends
code segment
start:
mov ax,data
mov ds,ax
lea dx,m1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl,al
lea dx,m2
mov ah,09h
int 21h
mov ah,01h
int 21h
clc
add al,bl
aaa
mov ah,00h
adc ah,30h
add al,30h
mov bx, ax
lea dx,m3
mov ah,09h
int 21h
mov dl,bl
mov ah,02h
int 21h
lea dx,m4
mov ah,09h
int 21h
mov dl,bh
mov ah,02h
int 21h
mov ah,4ch
int 21h
code ends
end start

Program (4). Addition of two two-digit numbers


Aim:- Write an assembly language program to add two two-digit numbers. Accept both numbers from keyboard
and the sum should be displayed.
Program:-
data segment
msg1 db 'enter the first number:$'
msg2 db 0ah,0dh,'enter the second number:$'
sum db 0ah,0dh,'sum is:$'
data ends
code segment
assume cs:code,ds:data

15
start:
mov ax,data
mov ds,ax
mov ah,09h
lea dx,msg1
int 21h
mov ah,01h
int 21h
sub al,30h
mov cl,04h
shl al,cl
mov bh,al
mov ah,01h
int 21h
sub al,30h
add al,bh
mov bh,al
mov ah,09h
lea dx,msg2
int 21h
mov ah,01h
int 21h
sub al,30h
mov cl,04h
shl al,cl
mov ch,al
mov ah,01h
int 21h
sub al,30h
add al,ch
add al,bh
daa
mov bl,al
mov ah,09h
lea dx,sum
int 21h
mov al,bl
and al,0f0h
mov cl,04h
shr al,cl
add al,30h
mov dl,al
mov ah,02h
int 21h
and bl,0fh
add bl,30h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h
code ends
end start

Program (5). Subtraction of two single digit numbers


Aim:- Write an assembly language program to subtract two single digit numbers. Accept both numbers from
keyboard and the difference should be displayed.
Program:-
assume cs:code,ds:data
data segment
m1 db 0ah,0dh,'enter the first number$'
m2 db 0ah,0dh,'enter the second number$'

16
m3 db 0ah,0dh,'difference is$'
data ends
code segment
start:
mov ax,data
mov ds,ax
lea dx,m1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl,al
lea dx,m2
mov ah,09h
int 21h
mov ah,01h
int 21h
clc
sub al,bl
aas
add al,30h
mov bl,al
lea dx,m3
mov ah,09h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h
code ends
end start

Program (6). Largest and Smallest in a given series


Aim:- Write an ALP to find the (a)largest (b) smallest
of given series of numbers between 0 and 9.
Largest:-
(a) assume cs:code,ds:data
data segment
list db 5,2,6,8,3
m1 db 0ah,0dh,"the no.s are 5,2,6,8,3$"
m2 db 0ah,0dh,"the largest no. is $"
count equ 04h
smallest db,01h
data ends
code segment
start:
mov ax,data
mov ds,ax
lea dx,m1
mov ah,09h
int 21h
lea dx,m2
mov ah,09h
int 21h
mov si,offset list
mov cl,count
mov al,[si]
again:cmp al,[si+1]
jnl next

17
mov al,[si+1]
next:inc si
dec cl
jnz again
mov si,offset largest
mov [si],al
add al,30h
mov dl,al
mov ah,02h
int 21h
mov ah,4ch
int 21h
code ends
end start

(b) Smallest:- Change the message as m2 db 0ah,0dh,"the smallest no. is $" and change the instructions
(jnl next) as (jl next) and (mov si,offset largest) as (mov si,offset smallest).

Program (7). Count even and odd numbers


Aim:- Write an assembly language program to count the number of odd & even numbers in the given series.
assume cs:code,ds:data
data segment
m1 db 0ah,0dh,"the numbers are 1,4,9,7,6,3,$"
m2 db 0ah,0dh,"no. of odd is $"
m3 db 0ah,0dh,"no.of even is $"
list db 1,4,9,7,6,3
count equ 06h
data ends
code segment
start:mov ax,data
mov ds,ax
lea dx,m1
mov ah,09h
int 21h
lea dx,m2
mov ah,09h
int 21h
mov si,offset list
mov cl,count
mov ax,0000h
mov bx,0000h
mov dx,0000h
again:mov al,[si]
ror ax,01
jnc odd
inc bl
jmp next
odd:inc dl
next:add si,01
dec cl
jnz again
add dl,30h
mov ah,02h
int 21h
lea dx,m3
mov ah,09h
int 21h
add bl,30h
mov dl,bl
mov ah,02h
int 21h

18
mov ah,4ch
int 21h
code ends
end start

Program (8). Sorting an array in Ascending/Descending


Aim:- Write an assembly language program to sort the array in (a) ascending order (b)descending order
Program
(a) Ascending:-
assume cs:code,ds:data
data segment
list db 5,2,6,7,3,8
m1 db "the numbers are 5,2,6,7,3,8$"
m2 db 0ah,0dh,"the sorted order is$"
count equ 06h
data ends
code segment
start:
mov ax,data
mov ds,ax
mov bl,count-1
lea dx,m1
mov ah,09h
int 21h
lea dx,m2
mov ah,09h
int 21h
again0:mov cl,bl
mov si,offset list
again1:mov al, [si]
cmp al,[si+1]
jl pr1
xchg [si+1],al
xchg [si],al
pr1:inc si
loop again1
dec bl
jnz again0
lea di,offset list
mov cl,count
next:mov dl,[di]
add dl,30h
mov ah,02h
int 21h
inc di
loop next
mov ah,4ch
int 21h
code ends
end start

(b) Descending:- Change the instruction (jl pr1) as (jnl pr1).

Program (9). Scan for a character in an array


Aim:- Write an ALP to scan for a character in an array.

19
Program (10). Reverse a string
Aim:- Write an ALP to reverse a string.
assume cs:code1,ds:data1
data1 segment
msg db 0ah,0dh,"enter the string:$"
string db 20,0,20 dup("$")
msg2 db 0ah,0dh,"the string in reversed order is:$",0ah,0dh
data1 ends
code1 segment
start:mov ax,seg data1
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
lea dx,string
mov ah,0ah
int 21h
mov bx,0000h
mov cx,bx
mov cl,string+1
lea si,string+2
again:mov ax,0001h
and al,[si]
jz skip
inc bx
skip:inc si
loop again
lea dx,msg2
mov ah,09h
int 21h
mov cx,0000h
mov cl,string+1
dec si
do:
mov dl,[si]
mov ah,02h
int 21h
dec si
loop do
mov ah,4ch
int 21h
code1 ends
end start
Program (11). Even and Odd
Aim:- Write an assembly language program to check the number is even or odd.
Program:-
assume cs:code,ds:data
data segment
m1 db 0ah,0dh,"enter the number$"
m2 db 0ah,0dh,"no. is odd$"
m3 db 0ah,0dh,"no.is even$"
data ends
code segment
start:mov ax,data
mov ds,ax
lea dx,m1
mov ah,09h
int 21h
mov ah,01h
int 21h

20
sub al,30h
ror al,01h
jnc even1
lea dx,m2
mov ah,09h
int 21h
jmp end1
even1: lea dx,m3
mov ah,09h
int 21h
end1: mov ah,4ch
int 21h
code ends
end start

Program (12). Palindrome


Aim:- Write an ALP to check the given string is palindrome or not.
Program:-
assume cs:code,ds:data
data segment
msg db"enter a string:$"
msg1 db 0dh,0ah,"the string is pallindrome:$"
msg2 db 0dh,0ah,"the string is not pallindrome:$"
array db 20 dup(?)
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,00h
mov cx,00h
lea si,array
mov ah,09h
mov dx,offset msg
int 21h
first:
mov ah,01h
int 21h
cmp al,0dh
jz loop1
mov[si],al
inc cx
inc si
jmp first
loop1:
mov di,offset array
dec si
loop2:
mov al,[si]
cmp al,[di]
jne npali
inc di
dec si
dec cx
jnz loop2
je pali
npali: mov ah,09h
lea dx,msg2

21
int 21h
jmp exit
pali: mov ah,09h
lea dx,msg1
int 21h
exit: mov ah,4ch
mov al,00h
int 21h
code ends
end start

Program (13). Case Conversion


Aim:- Write a program to convert the case of the string from lower case to uppercase.
Program:-
assume cs:code,ds:data
data segment
string db "8086 microprocessor programming$"
data ends
code segment
start:
mov ax,data
mov ds,ax
lea bx,string
mov cl,31
next:
mov ah,[bx]
cmp ah,61h
jb nochange
cmp ah,7ah
ja nochange
and ah,0dfh
mov [bx],ah
nochange:
inc bx
loop next
lea dx,string
mov ah,09h
int 21h
mov ah,4ch
int 21h
code ends
end start

Program (14). Fibonacci series


Aim:- Write an ALP to generate Fibonacci series of first 10 numbers.

Program (15). Prime numbers


Aim:- Write an ALP to generate first 10 prime numbers.

22
V. Interfacing
Interfacing to 8086 and programming to control stepper motor.
AIM: Write an Assembly Language Program to rotate the Stepper Motor in clockwise as well
as anti-clockwise direction.
APPARATUS: 8086 Trainer kit, Stepper, Motor Interface Card, Stepper Motor, Power supply.
PROCEDURE:-
1. Connect the 26 core FRC connector to the 8086 trainer at connector no CN4 and the interface module.
2. Connect the power mate connector to the interface module and the other side of the connector to the power
supply. The connections to the power supply are given below.
Connections: (power supply)
Black & Red: Gnd.
Blue & Green: +5V
3. 5- Way power mate is wired to the motor. This power mate is to be inserted into the male socket provided on
the interface. Care should be taken such that, below given code for the particular colored wire coincides with
the code on the interface.
A- GREEN
C- RED & WHITE
B- GREEN & WHITE
D- RED
VDD- BLACK & WHITE.
4. After the completion of the program and connections enter the program as given in the listing below.
G0< STARTING ADDRESS< ENTER (on the key board of trainer).
Program to rotate in clockwise direction
MOV AL,80
MOV DX,0FFC6
OUT DX
MOV BX,02
MOV CX,00FF
MOV AL,77
MOV DX,0FFC4
OUT DX
CALL DELAY
MOV AL,0BB
MOV DX,0FFC4
OUT DX
CALL DELAY
MOV AL,0DD
MOV DX,0FFC4
OUT DX
CALL DELAY
MOV AL,0EE
MOV DX, 0FFC4
OUT DX
CALL DELAY
LOOP A1
DEC BX
JNZ A2
Program to rotate in Anti clockwise direction
MOV AL,80
MOV DX,OFFC6
OUT DX
MOV BX,0002
MOV CX,00FF
MOV AL,0EE
MOV DX,0FFC4
OUT DX
CALL DELAY
MOV AL,0DD
MOV DX,0FFC4
OUT DX
CALL DELAY

23
MOV AL,0BB
MOV DX,0FFC4
OUT DX
CALL DELAY
MOV AL,077
MOV DX,0FFC4
OUT DX
CALL DELAY
LOOP A1
DEC BX
JNZ A2
DELAY PROGRAM:
MOV AX,0500
NOP
NOP
DEC AX
JNZ A3
RET

RESULT: An operation to interface Stepper Motor with 8086 Microprocessor performed.

STEPPER MOTOR INTERFACE


DATA SEGMENT
PORTA EQU 120H
PORTB EQU 121H
PORTC EQU 122H
CWRD EQU 123H
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, 80H ; initialize 8255, port a as o/p port
MOV DX, CWRD
OUT DX, AL
MOV DX, PORTA
MOV AL, 88H ; load initial bit pattern
OUT DX, AL ; output on port a
UP: CALL DELAY
ROL AL, 01H ; rotate left to get exitation sequence of 11,22,44,88
OUT DX, AL
JMP UP
DELAY: MOV CX, 0FFFFH ; delay can be adjusted to get different speeds
UP2: MOV BX, 0FFH
UP1: DEC BX
JNZ UP1
DEC CX
JNZ UP2
RET
MOV AH, 4CH
INT 21H
CODE ENDS
END START

24
VI. Question Bank
PART – A (Program)
1a) Write an ALP to show the byte and word transfers in different addressing modes.
1b) Write an ALP to transfer a given block of data word from source memory to destination memory without overlap.
1c) Write an ALP to transfer a given block of data word from source memory to destination memory with overlap.
1d) Write an ALP to interchange two blocks of data.

2a) Write an ALP to add / subtract two16 bit numbers.


2b) Write an ALP to add / subtract two32 bit numbers.
2c) Write an ALP to add / subtract two32 bit numbers using DD Directive.
2d) Write an ALP to multiply two 16 bit unsigned / signed numbers and display.
2e) Write an ALP to divide two 8 bit numbers (signed and unsigned)
2f). Write an ALP to divide two 16 bit numbers(signed and unsigned)

3a)Write an ALP to add/subtract/ multiply/divide two ASCII numbers.


3b) Write an ALP to convert 16 bit binary No to BCD.
3c) Write an ALP to convert BCD No to binary.
3d) Write an ALP to find square and cube of an 8 bit number .
3e) Write an ALP to find LCM of a 16 bit No.
3f) Write an ALP to find the GCD of two 16 bit unsigned integers.
3g) Write an ALP to find the factorial of an 8 bit number.

4a) Write an ALP to check if the number is positive or negative.


4b) Write an ALP to check if the given number is even or odd.
4c) Write an ALP to check number of ones and zeroes in the given data.
4d). Write and Alp to check if the given 16 bit data is a palindrome (bitwise).
4e). Write and Alp to check if the given 16 bit data is a palindrome (nibble-wise).

5a) Write an Alp to add / subtract „N‟ 16 bit numbers and display the result.
5b)Write an ALP to find the largest of „N‟ 16 bit numbers and display the result.
5c) Write an ALP to find the smallest of „N‟ 16 bit numbers and display the result.
5d) Write an ALP to sort the given set of 16 bit unsigned integers in ascending order using bubble sort algorithm.

6a) Write an ALP to transfer a given source string to destination using string instructions.
6b) Write an ALP to reverse a string.
6c) Write an ALP to search for a character in a string.
6d) Write an ALP to check if the given string is a palindrome or not.

7a) Write an ALP to read a character from a keyboard with and without echo.
7b) Write an ALP to read a string of characters from the keyboard and display.
7c) Write an ALP to create a new file.
7d) Write an ALP to read the contents of a file.
7e) Write an ALP to write a new file.

8a) Write an ALP to read the system date.


8b)Write an ALP to set the system date.
8c) Write an ALP to read the system time.
8d) Write an ALP to set the system time.

9a) Write an ALP to control the speed of a stepper motor & to drive the stepper motor interface to rotate the motor in clockwise
and anticlockwise directions.

25
PART – B (Viva)
1. What is a Microprocessor? Microprocessor is a program-controlled device, which fetches the instructions from
memory, decodes and executes the instructions. Most Micro Processor are single- chip devices.
2. Give examples for 8 / 16 / 32 /64 bit Microprocessors? - 8-bit Processor - 8085 / Z80 / 6800; 16-bit Processor - 8086 /
68000 / Z8000; 32-bit Processor - 80386 / 80486; 64 bit processor -Pentium, Pentium pro, Pentium II, Xeon, Pentium
III, and Pentium IV.
3. Why 8086 processor is called an 16 bit processor? - Because 8086 processor has 16 bit ALU.
4. What does microprocessor speed depend on? - The processing speed depends on DATA BUS WIDTH.
5. Is the address bus unidirectional? - The address bus is unidirectional because the address information is always given
by the Micro Processor to address a memory location of an input /output devices.
6. Is the data bus is Bi-directional? - The data bus is Bi-directional because the same bus is used for transfer of data
between Micro Processor and memory or input / output devices in both the direction.
7. What is the disadvantage of microprocessor? - It has limitations on the size of data. Most Microprocessor does not
support floating-point operations.
8. What is the difference between microprocessor and microcontroller? - In Microprocessor more op-codes, few bit
handling instructions. But in Microcontroller: fewer op-codes, more bit handling Instructions, and also it is defined as a
device that includes micro processor, memory, & input / output signal lines on a single chip.
9. What is meant by LATCH? - Latch is a D- type flip-flop used as a temporary storage device controlled by a timing
signal, which can store 0 or 1. The primary function of a Latch is data storage. It is used in output devices such as LED,
to hold the data for display.
10. Why does microprocessor contain ROM chips? - Microprocessor contain ROM chip because it contain instructions to
execute data.
11. What is the difference between primary & secondary storage device? - In primary storage device the storage capacity is
limited. It has a volatile memory. In secondary storage device the storage capacity is larger. It is a nonvolatile memory.
Primary devices are: RAM / ROM. Secondary devices are: Floppy disc / Hard disk.
12. Difference between static and dynamic RAM? - Static RAM: No refreshing, 6 to 8 MOS transistors are required to
form one memory cell, Information stored as voltage level in a flip flop. Dynamic RAM: Refreshed periodically, 3 to 4
transistors are required to form one memory cell; Information is stored as a charge in the gate to substrate capacitance.
13. What is interrupt? - Interrupt is a signal send by external device to the processor so as to request the processor to
perform a particular work.
14. Define Opcode and Operand.
15. What are the main two parts of 8086 internal architecture.(BIU,EU)
16. Name the registers in BIU (CS, DS, ES, SS, IP)
17. Name the registers in EU.( AX, BX, CX, DX, SP, BP, SI, DI)
18. What is the size of flag register? Name the conditional and control flags of 8086.
19. Can you perform 32 bit operation with 8086? How?
20. Whether 8086 is compatible with Pentium processor?
21. While accepting no. from user why u need to subtract 30 from that?
22. What is cache memory? - Cache memory is a small high-speed memory. It is used for temporary storage of data &
information between the main memory and the CPU (center processing unit). The cache memory is only in RAM.
23. What is called Scratch pad of computer? - Cache Memory is scratch pad of computer.
24. How is the real memory segmented? What is the advantage of segmentation.
25. Name the default segment and offset register combinations.
26. What is the relocatable program?
27. Name the three main addressing modes in 8086.
28. Explain MOV AL, „A‟ MOV AX, NUMBER MOV [BP], DL MOV CH,[1000] MOV[BX+SI],SP
MOV ARRAY[SI],BL MOV DH,[BX+DI+10H]
29. What is an intersegment and intrasegment jump.
30. Differentiate near and short jumps (+_32k and +127to_128 bytes)
31. Differentiate near and far jumps.
32. Differentiate push and pop instructions.
33. Explain PUSH word ptr [BX] POP F JMP TABLE [BX]
34. Explain: ASSUME, DB, DD, DW, DQ, END
35. Give the opcode format for 8086 instructions. (op(1-2b),(mode,reg,rem),(displacement-0-2b))

26
36. Explain LES BX LEA AX, DATA LDS DI,LIST
37. Explain how the string instructions are executed.
38. List some string instructions
39. Explain the significance of REP Prefix.
40. Explain XCHG, LAHF, SAHF, XLAT
41. What do you meant by segment override prefix.
42. Explain the following directives. NEAR, FAR, BYTE PTR, ORG, OFFSET, ORG
43. Differentiate END, ENDP, ENDM
44. What are the two basic formats used by assemblers. Where are they used. (Models, full segment definition)- (.model
tiny (64kb), .model small(128 kb), .model huge.
45. Explain ADD BYTE PTR [DI], 3 SBB BYTE PTR [DI], 5 CMP[DI], CH IMUL BYTE PTR [BX]
IDIV SI CWD CBW.
46. Explain DAA, (ONLY ON AL), AAA, AAD, AAM, AAS.
47. Name the logical instructions. How can we invert number .(XOR WITH 1s)
48. Differentiate TEST and CMP, and NOT& NEG, SAR & SHR, RCL & ROL, SCAS & CMPS, REPE&REPNE
49. Which are the flags affected. JA(Z=0 C=0), JB(C=0), JG (Z=0 S=0), JLE( Z=1 S<>0)
50. Explain LOOP, LOOPNE, LOOPE , LOOPZ
51. Differentiate NEAR & FAR CALL, NEAR RET & FAR RET
52. Explain the above pins of 8086 TEST, READY, RESET, BHE/S7, MN/MX, ALE, DT/R, DEN, HOLD, HLDA, S0,
RQ/GT1, LOCK, QS1-QS0.
53. Differentiate between minimum mode and maximum mode of operation. Name the maximum mode and minimum
mode pins.
54. Name the function of 8284
55. How does the RESET function.
56. What is the clock frequency of the 8086.
57. How are the address and data buses are separated in 8086 microprocessor.
58. What are the functions of 74LS373, 245.
59. What is the maximum memory capacity of 8086
60. Name the difference between 8086,8088.
61. Name the difference between 8085 and 8086.
62. Name the types of memory used in microprocessor based system.
63. What is the function of the 8288 controller
64. What are the various signals in a RAM and ROM memories.
65. Name the following. 8255, 8259, 8253, 8257, 8251
66. What is an arithmetic coprocessor, What are its functions. (multiply, divide, add, subtract, square root, calculate partial
tangent, partial arctangent and logarithms)
67. What are the advantages of the 8087 coprocessor. (many times faster than the microprocessor)
68. How can we use the DOS function calls.
69. What is the function of int21 interrupts.
70. Explain PUBLIC and EXTERN statements.
71. Differentiate between MACRO and PROCEDURE.
72. What are the conditional statements used in a MACRO. (REPEAT, WHILE)
73. What are the different methods of reading the keyboard using DOS function calls.
74. How can we use XLAT instruction for look up tables.
75. What are the two methods of interfacing I/O ( memory mapped I/O and I/O mapped I/O)
76. Differentiate between RAM and ROM? - RAM: Read / Write memory, High Speed, Volatile Memory. ROM: Read
only memory, Low Speed, Non Volatile Memory.
77. What is a compiler? - Compiler is used to translate the high-level language program into machine code at a time. It
does not require special instruction to store in a memory, it stores automatically. The Execution time is less compared
to Interpreter.
78. Which processor structure is pipelined? - All x86 processors have pipelined structure.
79. What is flag? - Flag is a flip-flop used to store the information about the status of a processor and the status of the
instruction executed most recently

27
80. What is stack? - Stack is a portion of RAM used for saving the content of Program Counter and general purpose
registers.
81. Can ROM be used as stack? - ROM cannot be used as stack because it is not possible to write to ROM.
82. What is NV-RAM? - Nonvolatile Read Write Memory also called Flash memory. It is also known as shadow RAM.
83. List the address bus width and the memory size of all the processor.
Processor address bus memory size
8086 20 1M
8088 20 1M
80186 20 1M
80286 24 16M
80386 24 16M
80386DX 32 4G
80386EX 26 64M
80486 32 4G
PENTIUM 64 4G
PENTIUM O 32 4G
PENTIUM P 32 4G
PENTIUM 2,3,4 36 64G

84. Explain, maskable, non maskable, vectored, non vectored, software & Hardware Interrupts.
85. What are interrupt vectors. (4 byte no. stored in the first 1024 bytes of memory. There are 256 interrupt vectors. Each
vector contains value of CS & IP, 32 vectors are reserved for present and future. 32 to 255 are available for users.
86. Name the interrupt instructions. ( INT, INT0, INT3)
87. Give significance of INT0, INT3.
88. Give the significance of IRET instruction how is it different from RET. (Like far RET retrieves 6 bytes from stack, two
for IP, two for CS and two for flags.)
89. Explain the operation of real mode interrupt.
90. Explain the protected mode interrupt.
91. 55. Explain how the interrupt flag bit IF and TF are used during an interrupt
92. 56. Name the hardware and soft ware interrupt of 8086, explain about them. (NMI, INTR are hardware interrupts. INT,
INT0, INT3 are the software interrupts)

28
VII. 8086 Instruction Set Summary
(a) Data Transfer Instructions:-
MOV Move byte or word to register or memory
IN, OUT Input byte or word from port, output word to port
LEA Load effective address
LDS, LES Load pointer using data segment, extra segment
PUSH, POP Push word onto stack, pop word off stack
XCHG Exchange byte or word
XLAT Translate byte using look-up table
(b) Logical Instructions:-
NOT Logical NOT of byte or word (one's complement)
AND Logical AND of byte or word
OR Logical OR of byte or word
XOR Logical exclusive-OR of byte or word
TEST Test byte or word (AND without storing)
(c) Shift and Rotate Instructions:-
SHL, SHR Logical shift left, right byte or word by 1 or CL
SAL, SAR Arithmetic shift left, right byte or word by 1 or CL
ROL, ROR Rotate left, right byte or word by 1 or CL
RCL, RCR Rotate left, right through carry byte or word by 1 or CL
(d) Arithmetic Instructions:-
ADD, SUB Add, subtract byte or word
ADC, SBB Add, subtract byte or word and carry (borrow)
INC, DEC Increment, decrement byte or word
NEG Negate byte or word (two's complement)
CMP Compare byte or word (subtract without storing)
MUL, DIV multiply, divide byte or word (unsigned)
IMUL, IDIV Integer multiply, divide byte or word (signed)
CBW, CWD Convert byte to word, word to double word (useful before multiply/divide)
Adjustments after arithmetic operations:
AAA, AAS, AAM, AAD ASCII adjust for addition, subtraction, multiplication, division (ASCII codes 30-39)
DAA, DAS Decimal adjust for addition, subtraction (binary coded decimal numbers)
(e) Transfer Instructions:-
JMP Unconditional jump (short 127/8, near 32K, far between segments)
Conditional jumps :-(+127, -128 range only)
JA (JNBE) Jump if above (not below or equal)
JAE (JNB) Jump if above or equal(not below)
JB (JNAE) Jump if below (not above or equal)
JBE (JNA) Jump if below or equal (not above)
JE (JZ) Jump if equal (zero)
JG (JNLE) Jump if greater (not less or equal)
JGE (JNL) Jump if greater or equal (not less)
JL (JNGE) Jump if less (not greater nor equal)
JLE (JNG) Jump if less or equal (not greater)
JC, JNC Jump if carry set, carry not set
JO, JNO Jump if overflow, no overflow
JS, JNS Jump if sign, no sign
JNP (JPO) Jump if no parity (parity odd)
JP (JPE) Jump if parity (parity even)

29
Loop control:
LOOP Loop unconditional; count in CX, short jump to target address
LOOPE (LOOPZ) Loop if equal (zero), count in CX, short jump to target address
LOOPNE (LOOPNZ) Loop if not equal (not zero), count in CX, short jump to target address
JCXZ Jump if CX equals zero (used to skip code in loop)
(f) Subroutine and Interrupt Instructions:-
CALL, RET Call, return from procedure (inside or outside current segment)
INT, INTO Software interrupt, interrupt if overflow
IRET Return from interrupt
(g) String Instructions:-
MOVS Move byte or word string
MOVSB, MOVSW Move byte, word string
CMPS Compare byte or word string
SCAS Scan byte or word string (comparing to A or AX)
LODS, STOS Load, store byte or word string to AL or AX
Repeat instructions (placed in front of other string operations):
REP Repeat
REPE, REPZ Repeat while equal, zero
REPNE, REPNZ Repeat while not equal (zero)
(h) Processor Control Instructions:-
Flag manipulation:
STC, CLC, CMC Set, clear, complement carry flag
STD, CLD Set, clear direction flag
STI, CLI Set, clear interrupt enable flag
LAHF, SAHF Load AH from flags, store AH into flags
PUSHF, POPF Push flags onto stack, pop flags off stack
Coprocessor, multiprocessor interface:
ESC Escape to external processor interface
LOCK Lock bus during next instruction
Inactive states:
NOP No operation
WAIT Wait for TEST pin activity
HLT Halt processor

30

You might also like