MPMC Lab Manual
MPMC Lab Manual
This is to certify that this book is the Bonafide record of jobs done by Mr./Miss
of Roll No:
B. Tech 3rd Year Ⅰ Semester Electronics & Communication Engineering Course,
studying this college during the academic year 2024-25.
It is also certified that all the jobs mentioned in this record are completedby the
candidate him/herself in the MICRO PROCESSOR AND MICROCONTROLLER lab
of the J.N.T.U.H. College of Engineering, Rajanna Sircilla
INDEX
INTRODUCTION
The Microsoft Macro Assembler (MASM) is an 8086(x86) assembler that uses the INTEL syntax for
MS DOS and Microsoft Windows. The earlier versions were released in the year 1981. Turbo Assembler
(TASM) is also an assembler package developed by Borland which runs on and produces code for 16-
bit or 32-bit x86 MS DOS or Microsoft Windows. These software’s provide the assembly language
tools to program the 8086 processor-based systems.
To program the x86 processor using in MASM certain concepts are very important. They arereserved
words, identifiers, predefined symbols, constants, expressions, operators, registersand statements.
Reserved Words:
A reserved word has a special meaning fixed by the language. This must be used under certainspecial
conditions. These reserved words are
• Instructions, which corresponds to operations the processor can execute.
• Directives, which give commands to the assembler.
• Attributes, which provide a value for a field, such as segment alignment.
• Operators, which are used in expressions.
MASM reserved words are not case sensitive except for predefined symbols. The assembly generates
an error if you use a reserved word as a variable.
For example: The following operands are reserved words. Reserved words are not case sensitive.
$ DWORD PASCAL SWORD
? FAR QWORD SYSCALL
@B FAR16 REAL4 TBYTE
@F FORTRAN REAL8 VARARG
ADDR FWORD REAL 16 WORD
BASIC NEAR SBYTE ZERO?
BYTE NEAR16 SDWORD
C OVERFLOW SIGN?
CARRY? PARITY STDCALL
Predefined Symbols: Unlike most MASM reserved words, predefined symbols are case sensitive.
@CatStr* @Environ* @Model*
@Code @fardata @SizeStr*
@CodeSize @fardata? @stack*
@Cpu @FileCur* @SubStr*
@CurSeg @FileName @Time*
@data @InStr* @Version
@DataSize @Interface* @WordSize
@Date @Line @Model*
Registers:
AL CX EAX SP
AX DH EBP SS
BH DI EBX ST
BL DL ECX TR3*
BP DR0 EDI TR4*
BX DR1 EDX TR5*
CH DR2 ES TR6
CL DR3 ESI TR7
Identifiers:
An identifier is a name that you invert and attach to a definition. Identifiers can be symbols
representing variables, constants, procedure names, code labels, segment names and user
defined data types such as structures, unions, records and types defined with TYPEDEF.
Identifiers longer than 247 characters generate an error.
• The first character of the identifier can be an alphabetic character (A - Z) or any of
these four characters. They are @ _ $ ?
• The other characters in the identifier can be any of the characters listed above or a
decimal digit(0 - 9).
Predefined Symbols:
The assembler includes a number of predefined symbols (also called predefined equates). These
symbols can be used at any point in the code to represent the equate value. For example: The
predefined equate @FileName represents the base name of the current file. If the current source
file is TASK.ASM, the value of the @FileName is TASK.
Integer Constants and Constant Expressions:
An integer constant is a series of one or more numerals followed by an optional radix specifier.
For example, in the following statements:
mov ax,25
mov bx,0B3
the number 25 and 0B3H are integer constants.
Operators:
Operators are used in expressions. The assembler evaluates the expressions that containsmore
than one operator according to the following rules:
• Operations in parenthesis are performed before adjacent operations.
• Binary operations of highest precedence are performed first.
• Operations of equal precedence are performed from left to right.
• Unary Operations of equal precedence are performed right to left.
Examples of the operators are: +, - (unary), &, *, /, %(MOD), SHL, SHR, +, - (binary), EQ, NE,
LT, LE, GT, GE, NOT, AND, OR, XOR, OPATTR, SHORT, TYPE.
Data Types;
JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
6
program. Some debuggers allow to stop the program after each instruction so thatyou
can check or alter the memory and register contents. This is called Single Step.
Debug. A debugger also allows to set a breakpoint, the debugger will run the program
up to the instruction where the breakpoint is put and then stop the execution.
6. Emulator: An emulator is a mixture of hardware and software. It is usually used to test
and debug the hardware and software of an external system such as the prototype ofa
microprocessor-based instrument.
Assembler Directives:
Assembler Directives are the directions to the assembler which indicate how an operand or
section of the program is to be processed. These are also called pseudo operations which
are not executable by the microprocessor. The various directives are explained below.
1. ASSUME: The ASSUME directive is used to inform the assembler the name of the
logical segment it should use for a specified segment.Ex:ASSUME DS:DATA tells
the assembler that for any program instruction which refers to the data segment it
should use the logical statement called DATA.
2. DB: Define Byte. It is used to declare a byte variable or set aside one or more storage
locations of type byte in memory. For
example, CURRENT_VALUE DB 36H tells the assembler to reserve one byte of
memory for a variable named CURRENT_VALUE and put the value 36H in that
memory location when the program is loaded into RAM.
3. DW: Define Word. It tells the assembler to define a variable of type word or to
reserve storage locations of type word in memory.
4. DD: Define Double Word. This directive is used to declare a variable of type double
word or restore memory locations which can be accessed as type double word
5. DQ: Define Quadword. This directive is used to tell the assembler to declare a
variable word in length or to reserve four words of storage in memory.
6. DT: Define Ten bytes. It is to inform the assembler to define a variable which is 10
bytes in length or to reserve 10 bytes of storage in memory.
7. EQU: Equate. It is used to give a name to some value or symbol. Every time the
assembler finds the given name in the program, it will replace the name with the
value or symbol we have equated with that name.
8. ORG: Originate. The ORG statement changes the starting offset address of the data.
It allows to set the location counter to a desired value at any point in the program.
For example, the statement ORG 3000H tells the assembler to set the location
counter to 3000H.
9. PROC: Procedures. It is used to identify the start of a procedure or subroutine.
10. END: End program. This directive indicates the assembler that is the end of the
program module. The assembler ignores any statements after the END directive.
11. ENDP: End Procedure. It indicates the end of the procedure (subroutine) to the
assembler.
12. ENDS: End Segment. This directive is used with the name of the segment to
indicate the end of the logical statement. Ex
: CODE SEGMENT : Start of logical significant containing code.
COD
EENDS: End of the segment named code.
Experiment no. 1
PROGRAM FOR 16-BIT ARITHMETIC OPERATIONS FOR 8086(USING
VARIOUS ADDRESSING MODES)
ADDITION:
a) Code:
assume cs:code
code segment
mov
ax,0ABCDH
mov
bx,0ABCDHadd
ax,bx
int 03H
code ends
end
Result:
a) Code:
data segment
num1 dW 1111H
num2 dW 2222H
res dW ?
data ends
assume cs:code,ds:data
code segment
movax,data
movds,ax
mov ax,num1
mov bx,num2
add ax,bx
movres,ax
int 03H
code ends
end
Result:
Subtraction:
Code:
assume cs:code
code segment
mov ax,2222H
mov bx,1111H
sub ax,bx
int 03H
code ends
end
Result:
Multiplication:
Code:
assume cs:code
code segment
mov ax,2222H
mov bx,1111H
mulbx
int 03H
code ends
end
Result:
Division:
Code:
assume cs:code
code segment
mov ax,2222H
mov bx,1111H
div bx
int 03H
code ends
end
Result:
EXPERIMENT NO.2
ASSUME CS:CODE,ES:EXTRA
CODE SEGMENT
MOVAX,EXTRA
MOV ES,AX
MOV DI,OFFSET SUM
XOR AX,AX
MOV AX,2222H
MOV CX,AX
MOV BX,1111H
ADD AX,BX
CLD
STOSW
XOR AX,AX
XOR DX,DX
MOV AX,CX
SUB AX,BX
STOSW
XOR AX,AX
MOV AX,C
MUL BX
STOSW
MOV BP,AX
MOV AX,DX
STOSW
INT 03H
CODE ENDS
EXTRA SEGMENT
SUM DW 01H DUP(?)
EXTRA ENDS
END
EXPERIMENT NO.3
ALP TO DIVIDE A 32-BIT UNSIGNED NUM BY A 16-BIT UNSIGNED
NUM AND STORE THE RESULT IN STACK SEGMENT
ASSUME CS:CODE,SS:STACK
CODE SEGMENT
MOV AX,STACK
MOV SS,AX
MOV BP,OFFSET QUOTIENT
MOV SP,BP
XOR AX,AX
MOV AX,2000H /* TAKE THE DIVISOR VALUE IN BX THAT DOESN'TLEAD
TO DIVIDE OVERFLOW */
MOV DX,4000H
MOV BX,8000H
DIV BX
PUSH AX
PUSH DX
INT 03H
CODE ENDS
STACK SEGMENT
ORG 2000H
QUOTIENT DW 01H DUP(?)
REMAINDER DW 01H DUP(?)
STACK ENDS
END
EXPERIMENT NO.4
ASSUME CS:CODE,DS:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
XOR AX,AX
MOV DX,0003H
L4: MOV CX,DX
MOV SI,OFFSET LIST
L3: XOR AX,AX
MOV AX,[SI+2]
CMP AX,[SI+6]
JC/JNC L1 /* For ascending JC L1,For descending JNC L1*/
JE L2
XCHG [SI+6],AX
XCHG [SI+2],AX
MOV BP,[SI]
XCHG [SI+4],BP
XCHG [SI],BP
JMP L1
L2: MOV DI,[SI]
CMP DI,[SI+4]
JC L1
XCHG DI,[SI+4]
XCHG DI,[SI]
L1: ADD SI,04H
LOOP L3
DEC DX
JNZ L4
INT 03H
CODE ENDS
DATA SEGMENT
LIST DD 0000CD34H,0000AB12H,002344AAH,00549120H
DATA ENDS
END
EXPERIMENT NO.5
ALP TO PICK THE MEDIAN FROM THE GIVEN ARRAY OF NUMBERS
ASSUME CS:CODE,DS:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
XOR AX,AX
MOV DX,0007H
L3: MOV CX,DX
MOV SI,OFFSET LIST
XOR AX,AX
L2: MOV AL,[SI]
CMP AL,[SI+1]
JC L1
JE L1
XCHG [SI+1],AL
XCHG [SI],AL
L1: INC SI
LOOP L2
DEC DX
JNZ L3
MOV SI,OFFSET LIST
MOV BL,02H
MOV AL,[SI+3]
ADD AL,[SI+4]
DIV BL
MOV [SI+8],AX
INT 03H
CODE ENDS
DATA SEGMENT
LIST DB 08H,07H,09H,06H,04H,03H,01H,02H
RESULT DW 01H DUP(?)
DATA ENDS
END
OBSERVE THE RESULT IN DATA SEGMENT
ALP TO PICK THE MEDIAN FROM THE GIVEN ARRAY OF NUMBERS WITH MACHINE
CODE AND ADDRESSES
EXPERIMENT NO.6
ALP TO FIND THE LENGTH OF A GIVEN STRING WHICH TERMINATES WITH A
SPECIAL CHARACTER ($)
ASSUME CS:CODE,ES:EXTRA
CODE SEGMENT
MOV AX,EXTRA
MOV ES,AX
XOR AX,AX
LEA DI,STRING
MOV AL,KEY
CLD
L1: SCASB
JNE L1
MOV AX,DI
DEC AX
INT 03H
CODE ENDS
EXTRA SEGMENT
STRING DB "MICROPROCESSORS","$"
KEY EQU "$"
EXTRA ENDS
END
EXPERIMENT NO.7
ALP TO REVERSE THE STRING AND VERIFY FOR PALINDROME
ASSUME CS:CODE,DS:DATA,ES:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
MOV ES,AX
XOR AX,AX
XOR BX,BX
MOV CX,COUNT
LEA SI,SOURCE
LEA DI,DEST+4
L1: MOV AL,[SI]
MOV [DI],AL
INC SI
DEC DI
LOOP L1
MOV CX,COUNT
LEA SI,SOURCE
LEA DI,DEST
CLD
REPE CMPSB
JNZ L2
MOV BL,0FFH /*RETURN 0FFH IN BL REGISTER FOR PALINDROME */
L2: INT 03H
CODE ENDS
DATA SEGMENT
SOURCE DB "MADAM"
ORG 2000H
DEST DB 0FH DUP(?)
COUNT EQU 0005H
DATA ENDS
END
ALP TO REVERSE THE STRING AND VERIFY FOR PALINDROMEWITH MACHINE CODE
AND ADDRESSES
EXPERIMENT NO.8
ALP TO INSERT A CHARACTER TO THE GIVEN STRING
ASSUME CS:CODE,DS:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
MOV ES,AX
XOR AX,AX
LEA SI,SOURCE
LEA DI,DEST
MOV CX,COUNT1
CLD
REP MOVSB
LEA BX,INSERT
MOV AL,[BX]
STOSB
MOV CX,COUNT2
REP MOVSB
INT 03H
CODE ENDS
DATA SEGMENT
SOURCE DB "TOMJERRY"
INSERT DB "&"
ORG 2000H
DEST DB 0FH DUP(?)
COUNT1 EQU 0003H
COUNT2 EQU 0005
DATA ENDS
END
ALP TO INSERT A CHARACTER TO THE GIVEN STRING WITH MACHINE CODE AND
ADDRESSES
EXPERIMENT NO.9
ALP TO DELETE A CHARACTER FROM THE GIVEN STRING
ASSUME CS:CODE,DS:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
MOV ES,AX
XOR AX,AX
LEA SI,SOURCE
LEA DI,DEST
MOV CX,COUNT1
CLD
REP MOVSB
INC SI
MOV CX,COUNT2
REP MOVSB
INT 03H
CODE ENDS
DATA SEGMENT
SOURCE DB "TOM&JERRY"
ORG 2000H
DEST DB 0FH DUP(?)
COUNT1 EQU 0003H
COUNT2 EQU 0005H
DATA ENDS
END
ALP TO DELETE A CHARACTER FROM THE GIVEN STRINGWITH MACHINE CODE AND
ADDRESSES
EXPERIMENT NO.10
LOGICAL OPERATIONS OF 16-BIT DATA (SOFTWARE)
AIM:TO WRITE A ASSEMBLY LANGUAGE PROGRAM FOR LOGICAL
OPERATIONS OF 16-BIT DATA USING IMMEDIATE ADDRESSING MODE.
COMPONENTS: MASM SOFTWARE, DOS BOX
PROGRAM:
A.AND GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 3214H
MOV BX, 6839H
AND AX, BX
INT O3H
CODE ENDS
END START
B.OR GATE
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX 5472H
MOV BX, 9283H
OR AX, BX
INT 03H
CODE ENDS
END START
C.NOT GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 4286H
NOT AX
INT O3H
CODE ENDS
END START
D.EX-OR GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 1750H
MOV BX, 6573H
XOR AX, BX
INT O3H
CODE ENDS
END START
E.NOR GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 9784H
MOV BX, 4653H
OR AX, BX
NOT AX
INT O3H
CODE ENDS
END START
F.NAND GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 2330H
MOV BX, 3728H
AND AX, BX
NOT AX
INT O3H
CODE ENDS
END START
G.EX-NOR GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 3928H
MOV BX, 4287H
XOR AX, BX
NOT AX
INT O3H
CODE ENDS
END START
RESULT:
AND GATE:
INPUT1:3214H
INPUT2: 6879H
OUTPUT: 2010H
OR GATE:
INPUT1: 5472H
INPUT2: 6839H
OUTPUT: D673H
NOT GATE:
INPUT: 4286H
OUTPUT: BD79H
EX-OR GATE:
INPUT1: 1750H
INPUT2: 6573H
OUTPUT: 7223H
NOR GATE:
INPUT1: 9784H
INPUT2: 4653H
OUTPUT: 2828H
NAND GATE:
INPUT1: 2330H
INPUT2: 3728H
OUTPUT: DCDFH
EX-NOR GATE:
INPUT1: 3928H
INPUT2: 4287H
OUTPUT: 8450H
EXPERIMENT NO.11
INTERFACING SEVEN SEGMENT DISPLAY WITH 8051
MAIN:
MOV A,#80H ; Load A with control word for 8255
MOV DPTR,#CNTRL ; Set DPTR to control port address
MOVX @DPTR,A ; Send control word to control port
TMR0_ISR:
CPL P1.0 ; Toggle P1.0 (toggle LED)
JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
34
DELAY:
MOV R0,#7FH ; Load R0 with 127 (outer loop counter)
OLOOP: MOV R1,#FFH ; Load R1 with 255 (inner loop counter)
ILOOP: DJNZ R1,ILOOP ; Decrement R1 and loop if not zero
DJNZ R0,OLOOP ; Decrement R0 and loop if not zero
RET ; Return from subroutine
ORG F000H
DISP: DB 6DH,66H,4FH,5BH,06H,3FH ; Display table for 7-segment display
RESULT :
Hence result observed on trainer kit.
EXPERIMENT NO.12
; Initialization
MOV A,#90H ; Set control word for 8255
MOV DPTR,#CNTRL ; Load control port address into DPTR
MOVX @DPTR,A ; Write control word to control port
; Main loop
START: LCALL SCAN ; Call SCAN subroutine to read keyboard
MOV DPTR,#TSAVE ; Load temporary save location into DPTR
MOVX @DPTR,A ; Save key code
LCALL UPDAT ; Call display update routine
SJMP START ; Repeat the process
BK:
MOV DPTR,#PORTA ; Load Port A address into DPTR
MOVX A,@DPTR ; Read data from Port A
JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
36
CJNE A,#00H,L1 ; Check if any key is pressed
SJMP BK ; If no key, keep checking
L1:
LCALL DELAY ; Debounce delay
MOV DPTR,#PORTA ; Load Port A address again
MOVX A,@DPTR ; Read data from Port A
CJNE A,#00H,L2 ; Check if key is still pressed
SJMP BK ; If not, recheck
L2:
MOV R5,#00H ; Reset key code accumulator
MOV A,#01H ; Enable first row
MOV R7,A ; Save row selection in R7
MOV R6,#00H ; Initialize column tracker R6
REV:
MOV DPTR,#PORTC ; Load Port C address
MOVX @DPTR,A ; Set row selection on Port C
MOV DPTR,#PORTA ; Load Port A address
MOVX A,@DPTR ; Read column data from Port A
CJNE A,#00H,L3 ; Check if key is pressed in current row
SJMP L4 ; If pressed, find the key
L3:
SJMP NEXT ; Otherwise, check next row
L4:
MOV A,R6 ; Add column offset to R6
ADD A,#08H
MOV R6,A ; Save updated column offset in R6
MOV A,R7 ; Rotate row selection
RL A
MOV R7,A ; Update row selection
CJNE A,#08H,L5 ; Check if all rows are scanned
SJMP SCAN ; If done, rescan
L5:
SJMP REV ; Continue scanning in the next row
NEXT:
CLR C ; Clear carry bit
RRC A ; Rotate column bits
JC FND ; If bit set, key found
INC R5 ; Otherwise, increment column
JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
37
SJMP NEXT ; Check next column
FND:
MOV A,R7 ; Get row selection
CJNE A,#01H,L6 ; Determine row number
MOV A,R5 ; Get column code
SJMP L7 ; Combine row and column
L6:
CJNE A,#02H,L8 ; Check for next row
MOV A,R5 ; Add offset for second row
ADD A,#08H
MOV R5,A
SJMP L7 ; Save key code
L8:
MOV A,R5 ; Add offset for third row
ADD A,#10H
MOV R5,A
L7:
RET ; Return from SCAN
RESULT :
Hence result observed on trainer kit.
EXPERIMENT NO.13
CONTROL EQU 2023H ; Address of the control port for the 8255
PORTA EQU 2020H ; Address of Port A
PORTB EQU 2021H ; Address of Port B
PORTC EQU 2022H ; Address of Port C
UPDD EQU 677DH ; Address of the display routine
TEMP EQU 40H ; Temporary memory location for intermediate storage
; Initialize the control port to set Port A as input, Port B and Port C as
output
MOV DPTR, #CONTROL
MOV A, #90H ; Configuration: Port A input, Port B and Port C output
MOVX @DPTR, A ; Write configuration to the control port
GET_NEXT:
MOV TEMP, #00H ; Clear TEMP register
MOV DPTR, #F000H ; Set DPTR to point to memory location F000H
MOVX A, @DPTR ; Read data from external memory
ANL A, #0FH ; Mask the upper nibble (only keep the lower 4 bits)
MOV TEMP, A ; Store the masked value in TEMP
; Reset PC7
MOV A, #0EH ; Clear PC7 (START)
MOVX @DPTR, A
RESULT :
Hence result observed on trainer kit.
EXPERIMENT NO.14
PORTCP EQU 2023H ; Define the address of the 8255 control port
PORTA EQU 2020H ; Define the address of Port A
PORTB EQU 2021H ; Define the address of Port B
PORTC EQU 2022H ; Define the address of Port C
DELAY EQU 684EH ; Define a delay constant (not directly used here)
BEGIN:
; Generate a low state for the square wave
MOV A, #00H ; Load 00H (minimum value) into the accumulator
LCALL SUBR ; Call SUBR to output the value to both DACs
; Repeat indefinitely
LJMP BEGIN ; Jump back to BEGIN for continuous square wave
generation
SUBR:
; Output the current value of A to both DACs
MOV DPTR, #PORTA ; Set DPTR to point to Port A
MOVX @DPTR, A ; Output the value of A to Port A (DAC 1)
MOV DPTR, #PORTB ; Set DPTR to point to Port B
MOVX @DPTR, A ; Output the value of A to Port B (DAC 2)
MOV R0, #06H ; Load R0 with 06H (outer loop counter for delay)
SB2: MOV R1, #FFH ; Load R1 with FFH (inner loop counter for delay)
SB1: NOP ; No operation (short delay)
DJNZ R1, SB1 ; Decrement R1 and loop to SB1 if not zero
DJNZ R0, SB2 ; Decrement R0 and loop to SB2 if not zero
RESULT :
Hence result observed on trainer kit
EXPERIMENT NO.15
0100 6 MAIN:
15
; as A to F
21
011A 23 SEND:
0121 22 27 RET
28
29
0122 30 uart_init:
31
0138 22 43 ret
45 end
NAME T Y P E V A L U E ATTRIBUTES
L0 . . . . . . . . C ADDR 0118H A
TI . . . . . . . . B ADDR 0098H.1 A
RESULT :
Hence result observed on trainer kit.