Professional Documents
Culture Documents
MPMC Lab Programs 2020-21
MPMC Lab Programs 2020-21
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.
NOTE : 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.
NOTE: 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)
FOR EXAMPLE
. MODEL SMALL
. STACK size of stack ; define stack
. DATA ; define data segment
------Define variables
(or)
. EXIT 0
END
Machine language programs are programs that the computer can understand and execute
directly. Assembly language instructions match machine language instructions, but are written
using character strings so that they are more easily understood. and High-level language
instructions are much closer to the English language and are structured.
Ultimately, an assembly language or high level language program must be converted into
machine language by programs called translators. If the program being translated is in assembly
language, the translator is referred to as an assembler, and if it is in a high level language the
translator is referred to as a compiler or interpreter.
EDITOR: An editor is a program, which allows you to create a file containing the assembly
language statements for your program.
ASSEMBLER: An assembler program is used to translate the assembly language Mnemonic
instructions to the corresponding binary codes. The second file generated by assembler is called
the assembler List file.
LINKER: A Linker is a program used to join several object files in to one large object file. The
linkers produce link files with the .EXE extension.
DEBUGGER: If your program requires no external hardware, then you can use a debugger to
run and debug your program. A debugger is a program, which allows you to load your object
code program into system memory, execute the program, and troubleshoot or “debug” it.
ASSEMBLER DIRECTIVES:
An assembler is a program used to convert an assembly language program into the
equivalent machine code modules. The assembler decides the address of each label and
substitutes the values for each of the constants and variables. It then forms the machine code for
mnemonics and data in assembly language program.
A macro is a group of instructions that performs one task, just as a procedure. The
difference is that a procedure is accessed via a CALL instruction, while a macro is inserted in the
program at the point of usage as a new sequence of instructions.
MODE 0 : In this mode, all ports function as simple I/O ports without hand shaking.
MODE 1 : This mode is handshake mode where by port A and port B use the bits
Port C as handshake signals.
MODE 2 : Only port A can be initialized in mode 2. In this mode port A can be used for
Bidirectional handshake data transfer. Port B can be initialized in mode 0 or
mode1.
ESA 86/88-2 operating in the serial mode can be connected to either CRT terminal or
host computer system. When computer system is the controlling element it must be executing the
driver software to communicate with ESA 86/88-2.
XT86 is a package which allows the user to establish a communication link between ESA
86/88-2 system and a computer system. The link is established between asynchronous serial
ports of the computer and ESA 86/88-2.A suitable RS232-C cables have to be used for
connecting the kit to the computer system.
User can develop assembly language programs on the computer system, cross- assemble
them using a suitable cross assembler to generate object code files and then use XT86 to
download these object code files into the trainer kit for execution. User can terminate XT86 and
return control to DOS by typing Alt + X. XT86 also allows uploading of data from the memory
of the kit to the computer. The data so uploaded is same in a disk file.
DEBUG is a utility program that allows a user to load an 80x 86 programs in to memory
and execute it step by step. DEBUG displays the contents of all processor registers after each
instruction executes, allowing user to determine if the code is performing the desired task.
DEBUG only displays the 16-bit portion of the general purpose registers. Code view is capable
of displaying the entire 32 bits. DEBUG is a very useful debugging tool. We will use DEBUG to
step through number of simple programs, gaining familiarity with DEBUG commands as we do.
DEBUG contains commands that can display and modify memory, assemble instructions,
disassemble code already placed into memory, trace through single or multiple instructions, load
registers with data, and do much more.
DEBUG loads into memory like any other program, in the fist available slot. The
memory space used by DEBUG for the user program begins after the end of DEBUG code. If an
.EXE or. COM file were specified, DEBUG would load the program according to the accepted
conventions.
D:\MASM\DEBUG PROG.EXE
DEBUG uses a minus as its command prompt, so you should see a “-”appear on display.
To get a list of some commands available with DEBUG is:
• T trace (step by step execution)
• U un assemble
• D Dump
• G go (complete execution)
• H Hex
E.g.: to execute the program file PROG.ASM use the following procedure:
MASM PROG.ASM
LINK PROG.OBJ
DEBUG PROG.EXE
Experiment No: 01
Aim: Write and execute an Assemble Language Program using 8086 processor to find the
16 bit Arithmetic Operation.
Program:
a) 16 Bit Addition
Label Program
.model small
.code
mov ax,1234h
mov bx,5678h
add ax,bx
int 03h
end
1234h
5678h
68a c
-------------
b) 16 Bit Subtraction
Label Program
.model small
.code
mov ax,abcdh
mov bx,5678h
sub ax,bx
int 03h
end
c) 16 Bit Multiplication
Label Program
.model small
.code
mov ax,4123h
mov bx,1234h
mul bx-ax*bx
int 03h
end
d) 16 Bit Division
Label Program
.model small
.code
mov ax,7894h
mov bl,0abh
Div blax/bl
int 03h
end
Different methods:
a) 16 Bit Addition
Label Program
.model small
.code
mov si,2500h
mov ax,[si]
mov bx,[si+2]
add ax,bx
int 03h
end
Ax=3412
Bx=cdab
b) 16 Bit Subtraction
Label Program
.model small
.code
mov si,2500h
mov ax,[si]
mov bx,[si+2]
sub ax,bx
int 03h
end
AX=1234h
BX=5678h
c) 16 Bit Multiplication
Label Program
.model small
.code
mov si,2500h
mov ax,[si]
mov bx,[si+2]
mul bx
int 03h
end
d) 16 Bit Division
Label Program
.model small
.code
mov si,2500h
mov ax,[si]
mov dx,[si+2]
mov bx,[si+4]
Div bx
int 03h
end
AX=1234h
DX=5678h
K Naveen Kumar, Asst.Prof 14
ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual
BX=ABCDh
Experiment No: 02
Aim: Write and execute an Assemble Language Program using 8086 processor to sort the
8-bit numbers in Ascending order.
Program:
Label Program 2504 12h/ff
.model small 2503 Abh/ff/12/ab
2502 01h/ff/ab/89
.code
2501 89h/ff/01/12
mov ch, 04h 2500 Ffh/89/01
back1: mov si,2500h
N=inputs=5
mov cl,04h Counter=N-1=comparisons=cl=4/3/2/1/0
back: mov al,[si] Iterations counter=N-1=ch=4/1
cmp al,[si+1]
jc nxt jnc
xchg al,[si+1]
xchg al,[si]
nxt: inc si
dec cl
jnz back
dec ch
jnz back1
int 03h
end
Result: The sorting of 8-bit ascending order is performed for a given set of numbers.
Experiment No: 03
Aim: Write and execute an Assemble Language Program using 8086 processor to sort the
8-bit numbers in Descending order.
Program:
Label Program
.model small
.code
mov ch, 04h
back1: mov si,2500h
mov cl,04h
back: mov al,[si]
cmp al,[si+1]
jnc nxt
xchg al,[si+1]
xchg al,[si]
nxt: inc si
dec cl
jnz back
dec ch
jnz back1
int 03h
end
Result: The sorting of 8-bit descending order is performed for a given set of numbers.
Experiment No: 04
Aim: Write and execute an Assemble Language Program using 8086 processor to sort the
16-bit numbers in Ascending order.
Program:
Label Program
.model small
.code
mov ch,04h
back1: mov si,2500h
mov cl,04h
back: mov ax,[si]
cmp ax,[si+2]
jc nxt
xchg ax,[si+2]
xchg ax,[si]
nxt: inc si
inc si
dec cl
jnz back
dec ch
jnz back1
int 03h
end
Result: The sorting of 16-bit ascending order is performed for a given set of numbers.
Experiment No: 05
Aim: Write and execute an Assemble Language Program using 8086 processor to sort the
16-bit numbers in Descending order.
Program:
Label Program
.model small
.code
mov ch,04h
back1: mov si,2500h
mov cl,04h
back: mov ax,[si]
cmp ax,[si+2]
jnc nxt
xchg ax,[si+2]
xchg ax,[si]
nxt: inc si
dec cl
jnz back
dec ch
jnz back1
int 03h
end
Result: The sorting of 16 bit descending order is performed for a given set of numbers.
Experiment No: 06
Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Largest number from a given string.
Program:
Label Program
.model small
.code
mov ch,04h
mov si,2000h
back: mov ax,[si]
cmp ax,[si+2]
jc nxt
xchg ax,[si+2]
xchg ax,[si]
nxt: inc si
inc si
dec ch
jnz back
int 03h
end
Result: The Largest Numbers is been found from a given set of numbers.
Experiment No: 07
Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Smallest number from a given string.
Program:
Label Program
.model small
.code
mov ch,04h
mov si,2000h
back: mov ax,[si]
cmp ax,[si+2]
jnc nxt
xchg ax,[si+2]
xchg ax,[si]
nxt: inc si
inc si
dec ch
jnz back
int 03h
end
Result: The Smallest Numbers is been found from a given set of numbers.
Experiment No: 08
Aim: Write and execute an Assemble Language Program using 8086 processor to
separate the given numbers and into even and odd numbers and store the result in two
different locations.
Program:
Label Program
.model small
.code
mov cx,000ah
mov si,1000h
mov di,1010h
mov bx,1020h
back: mov al,[si]
mov ah,al
rcr al,01
jc odd1
mov [di],ah
inc di
jmp xyz
odd1: mov [bx],ah
inc bx
xyz: inc si
loop back
int 03h
end
Result: The Sorting and Separation of Even and Odd numbers had been performed.
Experiment No: 09
Aim: Write and execute an Assemble Language Program using 8086 processor to
separate the given numbers and into positive and negative numbers and store the result in
two different locations.
Program:
Label Program
.model small
.code
mov cx,0ah
mov si,1000h
mov di,1010h
mov bx,1020h
back: mov al,[si]
mov ah,al
rcl al,01
jc neg1
mov [di],ah
inc di
jmp xyz
neg1: mov [bx],ah
inc bx
xyz: xyz:inc si
loop back
int 03h
end
Result: The Sorting and Separation of Positive and Negative numbers had been performed.
Experiment No: 10
Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Length of the given String
Program:
Label Program
.model small
.data
str db "Microprocessor",0
.code
mov ax,@data
mov ds,ax
mov si,offset str
xor cx,cx
back: mov al,[si]
cmp al,00h
jz xx
inc cx
inc si
jmp back
xx: int 03h
end
Experiment No: 11
Aim: Write and execute an Assemble Language Program using 8086 processor to read a
string from Keyboard and insert in between a given string.
Program:
Label Program
assume cs:code, ds:data
data segment
org 0020h
stg db"nmr college",00h
org 0040h
rst db 25h dup(00)
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,offset stg
mov di,offset rst
mov cx,04h
back: mov al,[si]
mov [di],al
inc si
inc di
loop back
again: mov ah,01h
int 21h
cmp al,'$'
jz next
mov [di],al
inc di
jmp again
next: mov al,[si]
cmp al,00h
jz xx
mov [di],al
inc si
inc di jmp
next int
xx: 03h code
ends
end start
Experiment No: 12
Aim: Write and execute an Assemble Language Program using 8086 processor to Delete
the string from the string given.
Program:
Label Program
assume cs:code,ds:data
data segment
org 0020h
stg db"nmr engg
college",00h
org 0040h
rst db 25h dup(00)
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,offset stg
mov di,offset rst
mov cx,04h
back: mov al,[si]
mov [di],al
inc si
inc di
loop back
Experiment No: 13
Aim: Write and execute an Assemble Language Program using 8086 processor to find
whether a given number is Prime or Not
Program:
Label Program
.model small
.data
Org 2000h
str1 db "prime",0
str2 db "not prime",0
Org 0000h
rst db 0ah
.code
mov ax,@data
mov ds,ax
mov al,09h
mov bl,al
mov cl,al
back: dec bl
cmp bl,01h
jz next
mov ah,00h
mov al,cl
div bl
cmp ah,00h
jz again
jmp back
again: mov si,offset str2
mov di,offset rst
jmp back1
next: mov si,offset str1
mov di,offset rst
back1: mov al,[si]
mov [di],al
cmp al,00h
jz xx
inc si
inc di
jmp back1
xx: int 03h
end
Result: The given number is examined through ALP and is displayed whether the given number
is a Prime or Not.
Experiment No: 14
Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Sum of ‘n’ natural numbers.
Program:
Label Program
.model small
.code
xor bx, bx
mov dh, 05h
mov si, 2000h
bak: mov al, [si]
mov ah, 00h
adc al, bl
inc bl
inc si
dec dh
jne bak
int 03h
end
Experiment No: 15
Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Average of ‘n’ numbers given.
Program:
Label Program
.model small
.code
mov si, 2000h
mov cx, 05h
xor ax, ax
bak: add al, [si]
inc si
jnc next
inc ah
loop bak
next: mov [si], al
mov [si+1], ah
div bx
int 03h
end
INTERFACING
Experiment No: 16
Aim: Interface a LED trainer kit to 8086 microprocessor and write a program to display
the necessary pattern.
cmp al,00h
jnz back1
jmp again
delay: mov cx,07ffh
xx: loop xx
ret
int 03h
end
Result: The required pattern has been displayed in the LED display
Experiment No: 17
Aim: Interface a Stepper Motor along with signal driver trainer kit to 8086
microprocessor and write a program to rotate the stepper motor in clock wise and anti
clock wise direction.
mov cx,800
mov al,88h
mov dx,0ffe0h
back1: out dx,al
rol al,01
call delay
dec cx
jnz back1
jmp again
delay: push cx
mov cx,02ffh
l1: loop l1
pop cx
ret
int 03h
end
Result: The Clock wise and Anti Clock wise rotation of the Stepper motor has been observed.
Experiment No: 18
Aim: Interface a DAC trainer kit to 8086 microprocessor and write a program to display
the necessary pattern.
b) Triangle Signal
Label Program
.model small
.code
org 2000h
mov al,80h
mov dx,0ffe6h
out dx,al
rpt: rpt:mov al,00h
mov dx,0ffe0h
back: back:out dx,al
inc al
cmp al,0ffh jne
back back1:out
back1: dx,al dec al
cmp al,00h
jne back1
jmp rpt
int 03h
end
d) Square Signal
Label Program
.model small
.code
org 2000h
mov al,80h
mov dx,0ffe6h
out dx,al
back: mov al,00h
mov dx,0ffe0h
out dx,al
call delay
mov al,0ffh
out dx,al
call delay
jmp back
delay: mov cx,0ffh
l1: loop l1
ret
int 03h
end
Result: The Ramp, Triangle, Square and Saw Tooth Waveforms are observed in the CRO.
MICROCONTROLLER
Experiment No: 19
Aim: Write and execute an Assemble Language Program using 8051 micro controller for
16-bit arithmetic operations
Program:
a) Addition
Label Program
Org 000h
mov a, # 0fdh
mov b, # 0a0h
add a,b
end
b) Subtraction
Label Program
Org 000h
mov a, # 0fdh
mov b, # 0a0h
sub a,b
end
c) Multiplication
Label Program
Org 000h
mov a, # 12h
mov b, # 030h
mul ab
end
d) Division
Label Program
Org 000h
mov a, # 20h
mov b, # 02h
div ab
end
Experiment No: 20
Aim: Write and execute an Assemble Language Program using 8051 micro controller for
addition of ‘n’ natural numbers.
Program:
Label Program
Org 000h
mov a, # 00h
mov r0, #00h
mov r1, #10h
again: inc r0
add a, r0
DJNZ r1, again
end
Experiment No: 21
Aim: Write and execute an Assemble Language Program using 8051 micro controller to
toggle all the bits of port1 by sending 55h and AAh continuously. Add a time delay
between each data transmission to port1.
Program:
Label Program
Org 000h
again: mov a, # 055h
mov p1, a
lcall delay
cpl a
lcall delay
sjmp again
Experiment No: 22
Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave of 50% duty cycle on p1.5 by using Timer 0.
Program:
Label Program
Org 000h
mov tmod, # 01h
back: mov th0, #0ffh
mov tl0, #0f2h
cpl p1.5
acall delay
sjmp back
Result: Square wave with 50% duty cycle has been generated.
Experiment No: 23
Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave of 33% duty cycle on p1.5 by using Timer 0.
Program:
Label Program
Org 000h
clr p1.5
mov tmod, # 01h
back: mov th0, #0ffh
mov tl0, #0f2h
cpl p1.5
acall delay
Result: Square wave with 50% duty cycle has been generated.
Experiment No: 24
Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave with Ton = 5ms.
Program:
Label Program
Org 000h
mov tmod, # 01h
back: mov th0, #0eeh
mov tl0, #00h
cpl p1.5
acall delay
sjmp back
Calculation:
= 1.085us
Experiment No: 25
Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave with Ton = 3ms and Toff= 10ms
Program:
Label Program
Org 000h
mov tmod, # 01h
back: mov th0, #0f5h
mov tl0, #33h
cpl p1.5
acall delay
mov th0, #0dbh
mov tl0, #ffh
cpl p1.5
acall delay
sjmp back
delay: setb tr0
here: jnb tf0, here
crl tr0
clr tf0
ret
end
Result: Square wave for Ton= 3ms, and Toff= 10ms has been generated.
Experiment No: 26
Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave in mode 2.
Program:
Label Program
Org 000h
mov tmod, # 20h
mov th1, #05h
setb tr1
back: jnb tf1, back
cpl p1.2
clr tf1
ret
end
Result: Square wave using mode 2 has been generated and verified.
Experiment No: 27
Aim: Write and execute an Assemble Language Program using 8051 micro controller to
transfer a character ‘Y’ at 9600 baud rate continuously and also send a character ‘N’
through port 0 which is connected to a display device
Program:
Label Program
Org 000h
mov tmod, # 20h
mov th1, #0fdh
mov scon, # 50h
setb tr1
clr ti
again: mov sbuf, #’Y’
here: jnb ti, here
clr ti
mov p0, #’N’
sjmp again
end
Result: Serial transmission of a character trough UART and also through port has been
performed.
Experiment No: 28
Aim: Write and execute an Assemble Language Program using 8051 micro controller to
transfer a string at 9600 baud rate continuously.
Program:
Label Program
Org 2000h
str: db “hello world”, 0
Org 000h
mov tmod, # 20h
mov th1, #0fdh
mov scon, # 50h
setb tr1
mov dptr, #str
back: clr a,
movc a, @a+dptr
jz last
lcall tran
sjmp back
last: sjmp $
tran: mov sub, a
jnb ti, $
clr ti
inc dptr
ret
end
Result: Serial transmission of a string trough UART and also through port has been performed.
Experiment No: 29
Aim: Write and execute an Assemble Language Program using 8051 micro controller to
interface a LCD to display necessary string.
Program:
Label Program
Org 8000h
mov a, #80h
mov dptr, #0e803h
movx @dptr, a
mov dptr, #8100h
again: clr a
movc a, @a+dptr
jz data1
acall cmd
acall delay
sjmp again
movx @dptr, a
mov @dptr, #0e801h
mov a, # 04h
movx @dptr, a
mov a, # 00h
movx @dptr, a
pop dph
pop dpl
inc dptr
ret
acall delay
sjmp data1
final: sjmp $
Org 8100h
db 30h, 30h, 30h,
38h,01h,
02h,06h,0eh,80h, 00h
db “MP&MC Lab”,00h
end
Result: The given string is displayed by interfacing LCD to 8051 micro controller.