MPMC Lab Manual 2019-20 PDF
MPMC Lab Manual 2019-20 PDF
LIST OF EXPERIMENTS
1. INTRODUCTION TO MASM/TASM.
3. ADDITION OF N NUMBERS.
4. AVERAGE OF N NUMBERS.
2.7-SEGMENT DISPLAY
3. STEPPERMOTOR INTERFACE.
Page 2
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
Page 3
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
1. INTRODUCTION TO MASM/TASM
1. Machine language
2. Assembly language
Machine language programs are programs that the computer can understand and execute
directly. Assembly language programs/instructions match machine language
programs/instructions, but are written using characters or 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 from 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.
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.
Page 4
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
COMMANDS:
F:
CD 8086 TOOLS
MASM FILENAME.ASM
LINK FILENAME.OBJ
DEBUG FILENAME.EXE
EXIT
Page 5
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
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.
Assembler directives help the assembler to correctly understand assembly language Programs to
prepare the codes. Commonly used assembler directives are DB, DD, DW, DUP, ASSUME,
BYTE, SEGMENT, MACRO, PROC, OFFSET, NEAR, FAR, EQU, STRUC, PTR, END,
ENDM, ENDP etc. Some directives generate and store information in the memory, while others
do not.
Page 6
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
BYTE PTR: - This directive indicates the size of data referenced by pointer.
DUP (Duplicate) :- The DUP directive reserves memory locations given by the Number
preceding it, but stores no specific values in any of these locations.
ASSUME: - The ASSUME statement is only used with full segment definitions. This statement
tells the assembler what names have been chosen for the code, data, and extra and stack
segments.
EQU: - The equate directive equates a numeric ASCII or label to another label.
ORG: - The ORG (origin) statement changes the starting offset address in a segment.
PROC and ENDP: - The PROC and ENDP directives indicate start and end of a procedure (Sub
routine). Both the PROC and ENDP directives require a label to indicate the name of the
procedure. The PROC directive must also be followed with the NEAR or FAR. A NEAR
procedure is one that resides in the same code segment as the program. A FAR procedure may
reside at any location in the memory system.
MACRO:-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.
ENDM: - The last statement of a macro is the ENDM instruction. Never place a label in front of
the ENDM statement.
PUBLIC &EXTRN: - The public and extern directives are very important to modular
programming. We use PUBLIC to declare that labels of code, data or entire segments are
available to other program modules. We use EXTRN to declare that labels are external to a
module. Without this statement, we could not link modules together to create a program using
modular programming techniques.
OFFSET: - Offset of a label. When the assembler comes across the OFFSET operator along
with a label, it first computes the 16 – bit displacement of the particular label, and replaces the
string ‘OFFSET LABEL’ by the computed displacement.
LENGTH: - Byte length of the label. This directive is used to refer to the length of data array or
a string.
Result: Hence introduction of Microsoft macro assembler/Borland turbo assembler and their
TOOLS are studied.
Page 7
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
2. ARITHMETIC OPERATIONS.
CODE SEGMENT
START: MOV AX, DATA
MOV DS,AX
MOV AX,OPR1
ADD AX,OPR2
MOV RES, AX
HLT
CODE ENDS
END START
Page 8
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
MUL OPR2
MOV RES1, AX
MOV RES2, DX
HLT
CODE ENDS
END START
Page 9
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
ADD AX, OPR2
MOV RES, AX
HLT
CODE ENDS
END START
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
SUB AX, OPR2
MOV RES, AX
HLT
CODE ENDS
END START
Page 10
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
IMUL OPR2
MOV RES1, AX
MOV RES2, DX
HLT
CODE ENDS
END START
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
IDIV OPR2
MOV RESQ, AX
MOV RESR, DX
HLT
CODE ENDS
END START
Page 11
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
2. I) 32-BIT Addition
ALP:
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
LEA SI, OPR1
LEA BX, OPR2
LEA DI, RES
MOV CX, 0004H
LOOP: MOV AL, [SI]
ADC AL, [BX]
MOV [DI], AL
INC SI
INC BX
INC DI
DEC CX
JNZ LOOP
HLT
CODE ENDS
END START
RESULT:
INPUT: OPR1= 12345678H
OPR2= 12345678H
OUTPUT: RES= 6B A5 88 57 H
Page 12
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
2. J) 32-BIT Subtraction
AIM: write an ALP for 32-bit subtraction & verify the result
ALP:
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
LEA SI, OPR1
LEA BX, OPR2
LEA DI, RES
MOV CX, 0004H
LOOP: MOV AL, [SI]
SBB AL, [BX]
MOV [DI], AL
INC SI
INC BX
INC DI
DEC CX
JNZ LOOP
HLT
CODE ENDS
END START
RESULT:
INPUT: OPR1= 12345678H
OPR2= 02345678H
OUTPUT: RES=10 00 00 00 H
Page 13
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
2. K) 32-BIT Multiplication
AIM: write an ALP for 32-bit Multiplication & verify the result
ALP:
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
LEA SI, OPR1
LEA DI, RES
MOV CX, 0004H
MOV DX, 0000H
LOOP: MOV AL, [SI]
MOV AH,00H
MUL OPR2
ADD AX, DX
MOV DL, AH
MOV [DI], AL
INC SI
INC DI
DEC CX
JNZ LOOP
MOV [DI], AH
HLT
CODE ENDS
END START
RESULT:
INPUT: OPR1= 12345678H
OPR2= 36H
OUTPUT: RES=03 D7 0A 3D 50H
Page 14
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
2. L) 32-BIT Division
AIM: write an ALP for 32-bit Division & verify the result
ALP:
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
LEA SI, OPR1
LEA DI, RES
MOV CX, 0004H
ADD SI, 03H
MOV BP, SI
MOV AX, 0000H
BACK: MOV AL, [BP]
DIV OPR2
MOV [DI], AL
DEC BP
INC DI
DEC CX
JNZ BACK
INC DI
MOV [DI],AH
HLT
CODE ENDS
END START
RESULT:
INPUT: OPR1= 12345678H
OPR2= 36H
OUTPUT: RES=00 56 4D 74H
Page 15
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
ASCII OPERATIONS
2. M) ASCII addition
AIM: write an ALP for ASCII addition & verify the result
ALP:
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AH, 00H
MOV AL, OPR1
ADD AL, OPR2
AAA
MOV RES, AX
HLT
CODE ENDS
END START
RESULT:
INPUT: OPR1= 09H
OPR2= 05H
OUTPUT: RES= 01 04H
Page 16
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
2. N) ASCII SUBTRACTION
ALP:
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AH, 00H
MOV AL, OPR1
SUB AL, OPR2
AAS
MOV RES, AL
HLT
CODE ENDS
END START
RESULT:
INPUT: OPR1= 06H
OPR2= 02H
OUTPUT: RES= 04H
Page 17
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
2. O) ASCII MULTIPLICATION
AIM: write an ALP for ASCII multiplication & verify the result
ALP:
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AH, 00H
MOV AL, OPR1
MUL OPR2
AAM
MOV RES, AX
HLT
CODE ENDS
END START
RESULT:
INPUT: OPR1= 09 H
OPR2= 05H
OUTPUT: RES= 04 05H
Page 18
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
2. P) ASCII DIVISION
ALP:
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AH, 00H
MOV AX, OPR1
AAD
DIV OPR2
MOV RESQ, AL
MOV RESR, AH
HLT
CODE ENDS
END START
RESULT:
INPUT: OPR1= 0607H
OPR2= 09H
OUTPUT: RESQ =07H
RESR=04H
Page 19
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
3. LOGICAL OPERATIONS
AIM: write an ALP to perform BCD to ASCII conversion& verify the result
ALP:
RESULT:
INPUT:
BCD: 49H
OUTPUT:
ASCII1: 34H
ASCII 2:39H
Page 20
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
AIM: write an ALP to perform PACKED BCD to UNPACKED BCD conversion& verify the result
ALP:
RESULT:
INPUT:
BCD: 49H
OUTPUT:
UNPCK1: 04H
UNPCK2: 09H
Page 21
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
AIM: write an ALP to perform UNPACKED BCD to PACKED BCD conversion& verify the result
ALP:
RESULT:
INPUT:
OPR1:04H
OPR2:09H
OUTPUT:
RES: 49H
Page 22
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
4. STRING OPERATIONS
4. A) MOVE A BLOCK
AIM: write an ALP to move a string from one location to another location without using string instructions
ALP:
RESULT:
INPUT: JNTUK
D DS: 0010
OUTPUT: JNTUK
Page 23
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
4. B) MOVE A BLOCK
AIM: write an ALP to move a string from one location to another location using string instructions
ALP:
RESULT:
INPUT: JNTUK
D DS: 0010
OUTPUT: JNTUK
Page 24
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
4. C) REVERSING A STRING
AIM: write an ALP for REVERSING A STRING & verify the result
ALP:
RESULT:
INPUT:JNTUK
OUTPUT:KUTNJ
Page 25
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
ALP:
RESULT:
INPUT:
STR1:JNTUK
OUTPUT:
0B80:0000 4A 4E 54 55 4B 05
Page 26
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
4. E) STRING COMPARISION
AIM: write an ALP for STRING COMPARISION & verify the result
Page 27
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
4. F) ASCENDING ORDER .
ALP:
CODE SEGMENT
START:MOV AX,DATA
MOV DS, AX
MOV DX,COUNT
BACK: MOV CX,DX
MOV SI, OFFSET LIST
AGAIN: MOV AX, [SI]
CMP AX, [SI+2]
JC GO
XCHG AX, [SI+2]
XCHG AX,[SI]
GO: INC SI
INC SI
LOOP AGAIN
DEC DX
JNZ BACK
HLT
CODE ENDS
END START
RESULT:
INPUT: 05H, 04H, 01H, 03H, 02H
Page 28
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
4. G) DECENDING ORDER.
AIM: write an ALP for DECENDING ORDER TOOLS: MASM Software, PC.
ALP:
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV DX, COUNT
BACK: MOV CX, DX
MOV SI, OFFSET LIST
AGAIN: MOV AX, [SI]
CMP AX, [SI+2]
JNC GO
XCHG AX, [SI+2]
XCHG AX,[SI]
GO: INC SI
INC SI
LOOP AGAIN
DEC DX
JNZ BACK
HLT
CODE ENDS
END START
RESULT:
INPUT: 05H, 04H, 01H, 03H, 02H
Page 29
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
ALP
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
NUM DB 36
RESULT DB ?
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV CL,NUM
MOV BL,1
MOV AL,0
UP:CMP CL,0
JZ ZRESULT
SUB CL,BL
INC AL
ADD BL,02H
JMP UP
ZRESULT:MOV RESULT,AL
HLT
CODE ENDS
END START
Page 30
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
6. ADDITION OF N NUMBER.
Page 31
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
7. SUM OF SQUARES/CUBES.
ALP:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
NUM DB 12H,13H,15H
SUM DW ?
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
LEA SI,NUM
MOV CL,03H
MOV AX,0000H
MOV SUM,00H
BACK:MOV AL,[SI]
MUL AL
ADD AX,SUM
MOV SUM,AX
INC SI
DEC CL
JNZ BACK
HLT
CODE ENDS
END START
Page 32
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
ALP:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
LIST DW 2357H,0A579H,0C322H,0C91EH,0957H
COUNT EQU 006H
DATA ENDS
CODE SEGMENT
START:XOR BX,BX
XOR DX,DX
MOV AX,DATA
MOV DS,AX
MOV CL,COUNT
MOV SI,OFFSET LIST
AGAIN:MOV AX,[SI]
ROR AX,01
JC ODD
INC BX
JMP NEXT
ODD:INC DX
NEXT:ADD SI,02
DEC CL
JNZ AGAIN
MOV AH,4CH
INT 21H
CODE ENDS
END START
Page 33
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
DATA SEGMENT
LIST DW 2579H,0A500H,0C009H,0159H,0B900H
COUNT EQU 05H
DATA ENDS
CODE SEGMENT
START:XOR BX,BX
XOR DX,DX
MOV AX,DATA
MOV DS,AX
MOV CL,COUNT
MOV SI,OFFSET LIST
AGAIN:MOV AX,[SI]
SHL AX,01
JC NEG
INC BX
JMP NEXT
NEG:INC DX
NEXT:ADD SI,02
DEC CL
JNZ AGAIN
MOV AH,4CH
INT 21H
CODE ENDS
END START
Page 34
KKR & KSR INSTITUTE OF TECHNOLOGY & SCIENCES, GUNTUR
DATA SEGMENT
NUM DW 04H
RES DW ?
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
MOV AX,NUM
MOV BX,AX
BACK:DEC BX
MUL BX
CMP BX,0001H
JE NEXT
JNZ BACK
NEXT:MOV RES,AX
HLT
CODE ENDS
END START
Page 35