MPP Exp6 Final On 10-9-2013 Okk Draft
MPP Exp6 Final On 10-9-2013 Okk Draft
1001 0010
EXPERIMENT No. 6 1000
(To be performed by group of 1-2 students)
9 2 8
1.0 Title: Write an Assembly Language Programming to Add / Sub / Multiply
Two BCD numbers.
2.0 Prior Concepts: ADD, SUB, MUL instructions, Hexadecimal, BCD
Numbers, Packed, Unpacked BCD and Assembler Directives.
3.0 New Concepts:
Proposition 1: Binary Coded Decimal (BCD) numbers:
Allows some limited arithmetic operations.
Permits proper rounding of numbers with no loss of precision (It is useful
for handling Dollars, Cents
Applicable for performing arithmetic on small values.
Binary BCD Digit Binary BCD Digit
0000 0 0101 5
0001 1 0110 6
0010 2 0111 7
0011 3 1000 8
0100 4 1001 9
82
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
83
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
CALL procedure_name
……
……
…..
RET
84
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
END
MOV AX,MULTIPLICAND
MOV BX,MULTIPLIER
CALL MULTI
…..
…..
END
MULTI PROC NEAR
MUL BX
RET
MULTI ENDP
LEA BX,MULTIPLICAND
LEA SI,MULTIPLIER
CALL MULTI_1
85
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
…..
…..
…..
END
MOV AX,[BX]
RET
MULTI_1 ENDP
The large number of parameters can be placed in argument list in one of the
data segments. A pointer to the list can be then pass to a called procedure
through general purpose register or Stack.
pass by reference – for large values (arrays) used in high level languages
Types of Procedures based on way of execution:
Re-entrant Procedure:-
MOV BH,05H ….
MOV AL,02H ….
IRET
86
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
In ISR again it calls factorial procedure .The RET instruction at the end of
factorial procedure returns to ISR.
Recursive procedure:-
Intellectual skills:
Understand program development steps like: Problem definition,
Analysis, Design of Logic, Coding, Testing and Maintenance
(Modification, error Correction etc.)
Use of programming Language constructs in assembly language
program implementation.
To apply different logics/ approaches to solve the given problem.
Understand the tools available for assembly language programming of
8086 such as Editor (Edit), Assembler (TASM /MASM/ NASM, Linker
(TLINK /LINK /NLINK and Debugger (TD, Debug) and to identify/locate
different types of errors as syntactical semantics, fatal, linker and
logical.
To understand the execution of Assembly Language Program.
Motor skills:
Ability of proper handling of the computer system.
Ability to switch between and operate the different tools of assembling.
Ability to draw the flowchart.
Ability to check the status of flags and memory registers during
execution of the programs.
5.0 Equipment :
Hardware:
A Personal computer with Pentium onwards, with minimum 1GHZ
processor, 1GB RAM, 80GB HDD (minimum 1 per student or two)
Software:
Assemblers (MASM Macro Assembler from Microsoft Corp or TASM Turbo
Assembler from Borland Inc. or NASM),
Linker (TLINK, LINK or NLINK),
Debugger (TD, Debug) and any other
Editor like EDIT, Norton Editor, and Notepad etc.
87
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
Teachers shall make the students aware of the use of 8086 simulator
for writing and executing assembly language programs.
PROC-1
General purpose
MOV AX,100 Registers
SI,DI,SP,BP,
PROC-2 CS,ES,SS,DS
MOV AX,BX
ADD AX,NUM
Through i) Stack:
PROC-1
BP
...… SP
……
MOV AX,100
CALL BCD_ADD RETURN ADDRESS SP+2
RET NUM
NUM SP+4
BCD_ADD
PUSH BP
MOV BP,SP
MOV BX,BP+4
To pass large number of parameters. The parameters can be placed on the
Stack frame for the calling procedure. It is use full to use the Stack frame base
pointer (BP register) to make frame boundary for easy access of the parameters.
88
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
The Stack can also be used to pass parameters back from called procedure to
calling procedure.
Through ii) argument list:
PROC-1
DATA SEGMENT
MOV COUNT ,AX
DATA SEGMENT
CALL PROC-2
……….
……
NUM DB 10H
COUNT DW 500H
PROC-2 ….
….
MOV AX, COUNT
….
INC AX DATA ENDS
MOV COUNT, AX
BCD_ADD PROC
MOV AL, NUM1
MOV BL, NUM2
ADD AL,BL
DAA
MOV BCD_SUM, AX
RET
BCD_ADD ENDP
END
89
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
.DATA
NUM1 DB 12H
NUM2 DB 09H
BCD_DIFF DW ?
.CODE
MOV AX,@DATA
MOV DS, AX
CALL BCD_SUB
MOV AH,4CH
INT 21H
BCD_SUB PROC
MOV AL, NUM1
MOV AH,00H
MOV BL, NUM2
MOV BH,00H
SUB AL,BL
DAS
MOV BCD_DIFF, AX
RET
BCD_SUB ENDP
END
Program 1(C): Multiplication of 8 bit BCD numbers using procedure
.MODEL SMALL
.DATA
NUM1 DB 08H
NUM2 DB 03H
MULTI DW ?
.CODE
MOV AX,@DATA
MOV DS, AX
CALL BCD_MUL
MOV AH,4CH
INT 21H
BCD_MUL PROC
MOV AL, NUM1
MOV AH,00H
MOV BL, NUM2
MOV BH,00H
MUL BL
AAM
MOV MULTI, AX
RET
BCD_MUL ENDP
END
90
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
START
STOP
91
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
DAA
Complete the table using given program
MOV BCD_SUM,AX
segment
3344 5366
be performed.
6. Stop
8.0 Observations:
92
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
Test the execution of procedure using above program for following data.
3010 1259
Instructio
Write its operation
n
93
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
DAA
DAS
AAM
CBW
CWD
2. Write the program segment for using procedure to solve given expression:
94
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
Student’s Activity 1:
Write ALP to perform BCD addition without using procedure:
Student’s Activity 2:
Write ALP to perform BCD multiplication without using procedure:
95
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
Student Activity 3:
1. Check contents of code segment and write contents of address from
cs:0000H to cs:0020H(Refer PROGRAM.LST file to complete this
table)
Content Content
Address Address Address Contents Address Contents
s s
CS:0000 CS:0009 CS:0011 CS:001A
CS:0001 CS:000A CS:0012 CS:001B
CS:0002 CS:000B CS:0013 CS:001C
CS:0003 CS:000C CS:0014 CS:001D
CS:0004 CS:000D CS:0015 CS:001E
CS:0005 CS:000E CS:0016 CS:001F
CS:0006 CS:000F CS:0017 CS:0020
CS:0007 CS:000G CS:0018
CS:0008 CS:0010 CS:0019
Student Activity 4:
2. Write the following table contents after executing the program given
above:
13.0 Questions:
96
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
97
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6
Total Signature of
C(4) P(4) A(2)
(10) Subject Teacher
98
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION