MPMC Lab Manual
MPMC Lab Manual
INTRODUCTION TO MASM
The Microsoft Macro Assembler (MASM) is an x86 assembler for MS-DOS and Microsoft
Windows. It supports a wide variety of macro facilities and structured programming idioms, including
high- level functions for looping and procedures. Later versions added the capability of producing
programs for Windows. MASM is one of the few Microsoft development tools that target 16-bit, 32-bit
and is supplied as a 64 bit version ML64.EXE for 64-bit platforms. Versions 5.0 and earlier were MS-
DOS applications. Versions 5.1 and 6.0 were available as both MS-DOS and OS/2 applications. Versions
6.12 to 6.14 were implemented as patches for version 6.11 which converted them from 16 bit MZ
executables to 32 bit PE executable files. All later versions have been 32 bit PE executable files built as
Win32 console mode applications.
The Microsoft Assembler has been in production since 1981 and is upgraded by Microsoft to keep
abreast with operating system needs and processor developments. Prior to Microsoft Assembler, the
abbreviation MASM referred to Meta Assembler. MASM 6.0 was released in 1992 and was the first
version to include high-level programming support (in particular if/endif macros) and a more C-like
syntax. By the end of the year, version 6.1A updated the memory management to be compatible with code
produced by Visual C++. In 1993, full support for 32-bit applications and the Pentium instruction set had
been added, plus Phar Lap's DOS extender. By the end of 1997, MASM fully supported Windows 95, did
not require the DOS extender, and included some AMD-specific instructions. In 1999, Intel released
macros for SIMD and MMX instructions, which were shortly after supported natively by MASM. With
the 6.15 release in 2000, Microsoft discontinued support for MASM as a separate product, instead
subsuming it into the Visual Studio toolset, though it was still compatible with Windows 98, though
current versions of Visual Studio were not. Support for 64-bit processors was not added until the release
of Visual Studio 2005, with MASM given the version number 8.0.
Assembly language programming consists of following steps:
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 /TASM 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 from 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 pails 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/TASM assembler, MASM/TASM 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 reloadable because it can be put
anywhere in memory to be run. In MASM/TASM, LINK/TLIN7K 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 can
then examine register and memory contents to see whether the results are correct at that point. In MASM/TASM,
td filename is issued to debug the file.
DEBUGGER FUNCTIONS:
1. Debugger allows looking 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.
5. With the help of dump we can view register contents.
6. We can trace the program step by step with the help of F7.
7. We can execute the program completely at a time using F8.
THEORETICAL CALCULATIONS:
EXP. NO: 1 PERFORM SIMPLE ARITHMETIC OPERATIONS USING DIFFERENT ADDRESSING MODES
DATE: 1(a). Addition of two 16 bit numbers
AIM: To write an assembly language program for Addition of two 16-bit numbers.
PROGRAM:
CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
MOV AX,OP1
MOV BX,OP2
ADD AX,BX
MOV SUM,AX
INT 03H
CODE ENDS
END START
END
OUTPUT:
Address of an operand Example – 1 Example - 2
RESULT:
THEORETICAL CALCULATIONS:
AIM: To write an assembly language program for subtraction of two 16-bit numbers.
PROGRAM:
OUTPUT:
RESULT:
THEORETICAL CALCULATIONS:
PROGRAM:
OUTPUT:
Address of an operand Example – 1 Example - 2
RESULT:
THEORETICAL CALCULATIONS:
PROGRAM:
OUTPUT:
Address of an operand Example – 1 Example - 2
RESULT:
Viva questions:
Applications:
THEORETICAL CALCULATIONS:
AIM: To write an assembly language program for arranging a string in ascending order.
DATA SEGMENT
LIST DW 0101b, 0100b, 0011b,
0010b COUNT EQU 04H
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV DX, COUNT-
1 AGAIN0: MOV CX, DX
MOVSI, OFFSET
LIST AGAIN1: MOV AX, [SI]
CMP AX, [ SI+2]
JC PR1
XCHG [SI+2], AX
XCHG [SI], AX
PR1: ADD SI,02H
LOOP
AGAIN1 DEC
DX
JNZ AGAIN0
INT 03H
CODE ENDS
END START
OUTPUT:
INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
RESULT:
THEORETICAL CALCULATIONS:
AIM: To write an assembly language program for arranging a string in descending order.
PROGRAM:
ASSUME CS: CODE, DS:
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV DX, COUNT-
1 AGAIN0: MOV CX, DX
MOV SI, OFFSET
LIST AGAIN1: MOV AX, [SI]
CMP AX, [ SI+2]
JNC PR1
XCHG [SI+2], AX
XCHG [SI], AX
PR1: ADD SI,02H
LOOP
AGAIN1 DEC
DX
JNZ AGAIN0
INT 03
CODE ENDS
END START
OUTPUT:
INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
RESULT:
Viva questions:
1) What is the use of SI, DI, SP, and BP Registers?
2) What is the use of XCHG instruction?
3) What is the use of CX Register?
4) What is the use of JNZ instruction?
5) What are the functions of BIU?
6) What are the functions of EU?
7) What are the interrupts of 8086?
8) What is instruction cycle?
9) What is pipelining in 8086?
10) Draw the pin diagram of 8086?
Applications:
THEORETICAL CALCULATIONS:
AIM: - To write an assembly language program for converting packed BCD to unpacked BCD for 8086
processor.
PROGRAM:
DATA SEGMENT
PBCD DB ?
UPBCD DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
XOR AX,AX
MOV AL,
PBCD MOV
AH, AL MOV
CL, 4 SHR AH,
CL
AND AX, 0F0FH
MOV UPBCD,AX
INT 3H
CODE ENDS
END START
OUTPUT:
RESULT:
THEORETICAL CALCULATIONS:
AIM: - To write an assembly language program for converting packed BCD to ASCII for 8086 processor
PROGRAM:
DATA SEGMENT
PBCD DB ?
ASCI DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
XOR AX,AX
MOV AL,
PBCD MOV
AH, AL MOV
CL, 4 SHR AH,
CL
AND AX, 0F0FH
OR AX,3030H
MOV ASCI,AX
INT 3H
CODE ENDS
END START
OUTPUT:
Address of an operand Example – 1 Example - 2
RESULT:
THEORETICAL CALCULATIONS:
AIM: - To write an assembly language program for converting ASCII to packed BCD for 8086 processor
PROGRAM:
ASSUME CS:CODE
CODE SEGMENT
MOV Ax,3637h
MOV CL, 04
and Ax,0f0fh
rol ah,cl
add ah,al
INT 3H
CODE ENDS
END
OUTPUT:
RESULT:
Viva questions:
1) What is the meaning of packed and unpacked data?
2) What is ASCII and BCD code?
3) What is difference between ROR and RCR?
4) What are the hardware and software interrupts of 8086?
5) Explain how AAA, AAS, AAM and AAD instructions are performed by the 8086 processor?
6) Bring out the differences between 8086 and 8088?
7) What is instruction set of 8086 and give the classification?
8) What are the differences between maskable and non maskable interrupts?
9) What is maximum and minimum mode of 8086?
10) Mention the pins present in maximum and minimum mode of 8086
Applications:
THEORETICAL CALCULATIONS:
AIM: - To write an assembly language program for Addition of an array of BCD numbers stored in packed
form.
APPARATUS: MASM SOFTWARE, PC
OUTPUT:
RESULT:
Viva questions:
1) What is the use of DAA instruction?
2) Explain LOOP and LOOPE instructions?
3) What is stack pointer and program counter?
4) What are the functions of RD’, WR’, M/IO’, BHE’/S7 pins in 8086?
5) What are the advantages of memory segmentization?
6) What are macros and procedures?
7) What is the use of PUSH and POP instruction?
8) Differentiate RISC and CISC processors?
9) What is the need of interfacing I/O devices to microprocessor?
10) Differentiate between inter segment and intra segment jumps in 8086?
Applications:
THEORETICAL CALCULATIONS:
AIM: - To write an assembly language program for Multiplying two 3x3 matrices and print on DOS.
PROGRAM:
ASSUME CS:CODE , DS:DATA
DATA SEGMENT
ROCOL EQU 03H
MAT1 DB 01H,02H,03H,04H,05H,06H,07H,08H,09H
MAT2 DB 01H,02H,03H,01H,02H,03H,01H,02H,03H
PMAT3 DW 09H DUP(?)
DATA ENDS
CODE SEGMENT
START:MOV
AX,DATA MOV
DS,AX
MOV CH,ROCOL
MOV BX,OFFSET PMAT3
MOV SI,OFFSET MAT1
NEXTROW: MOV DI,OFFSET MAT2
MOV CL,ROCOL
NEXTCOL: MOV
DL,ROCOL MOV
BP,0000H
MOV AX,0000H
SAHF
NEXT_ELE:MOV AL,[SI]
MUL BYTE PTR[DI]
ADD BP,AX
INC SI
ADD DI,03
DEC DL
JNZ NEXT_ELE
SUB DI,08
SUB SI,03
MOV [BX],BP
ADD BX,02
DEC CL
JNZ NEXTCOL
ADD SI,03
DEC CH
INT 21H
CODE ENDS
END START
END
OUTPUT:
RESULT:
Viva questions:
1) State the significance of LOCK’ signal in 8086?
2) How does the microprocessor differentiate data and instruction?
3) Differentiate near jump and far jump?
4) What is DOS and BIOS function calls?
5) Compare serial and parallel communication?
6) List the various operating modes of 8253?
7) Write the format of ICW1 of 8259?
8) Name the six modes of operations of an 8253?
9) Give the memory classification?
10) What are the differences between SRAM and DRAM?
Applications:
EXP. NO: 6 IDENTIFICATION & DISPLAYING THE ACTIVATED KEY USING DOS AND BIOS FUNCTION
CALLS
DATE:
AIM: To write an assembly language program for Identification & Displaying the Activated Key
Using DOS and BIOS Function Calls
PROGRAM:
DISPLAY A CHARACTER
ASSUME CS:CODE
CODE SEGMENT
START:
MOV AH,08H
INT 21H
CODE ENDS
END START
END
ASSUME CS:CODE
CODE SEGMENT
START:
MOV AH,01H
INT 21H
CODE ENDS
END START
END
OUTPUT:
RESULT:
Viva questions:
1) What is DOS and BIOS function calls?
2) Write differences between macros & procedures?
3) Define immediate addressing mode of 8086 microprocessor with example.
4) Define direct addressing mode of 8086 microprocessor with example.
5) Define register addressing mode of 8086 microprocessor with example.
6) Define indexed addressing mode of 8086 microprocessor with example.
7) Define based, based indexed addressing modes of 8086 microprocessor with example.
8) What is assembler directive? List out all assembler directives of 8086?
9) List out the data transfer instructions of 8086?
10) List out the arithmetic and logical instructions of 8086?
11) List out the string manipulation instructions of 8086?
12) List out the data transfer instructions of 8086?
13) List out the branch instructions of 8086?
14) List out the processor control and flag manipulation instructions of 8086?
15) Compare CALL, PUSH and RET,POP instructions?
Applications:
CYCLE -II
INTEL 8051 ( 8-Bit Microcontroller)
EXP. NO: 1 DETECTION OF KEY CLOSURE BY POLLING TECHNIQUE
DATE:
AIM: To write an C language program for Detection of Key Closure by Polling Technique
PROGRAM:
#include<reg51.h>
sbit SW=P1^7;
void Msdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void main()
{
SW=1;
while(1)
{
if (SW==0)
{
P2=0X66;
Msdelay(10000);
P2=0Xcc;
Msdelay(10000);
P2=0X99;
Msdelay(10000);
P2=0X33;
Msdelay(10000);
}
else
{
P2=0X66;
Msdelay(10000);
P2=0X33;
Msdelay(10000);
OUTPUT:
RESULT:
Applications: