0% found this document useful (0 votes)
20 views17 pages

MPP Exp6 Final On 10-9-2013 Okk Draft

Uploaded by

Yashodeep Sant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views17 pages

MPP Exp6 Final On 10-9-2013 Okk Draft

Uploaded by

Yashodeep Sant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 17

Microprocessor and Programming (17431) Experiment No.

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

 Unpacked BCD numbers: A single digit in the lower (Rightmost)


Four bits (Nibble= 4 bit format to represent binary number) of each byte, with
zeros in the upper four bits.
 Packed BCD numbers:
This is number format.
It contains two Binary Coded Decimal digits, one in upper nibble (4 Bit) and
one in lower Nibble (4 Bit).
It used for arithmetic using the numeric coprocessor
Example: Representation of decimal number 1527 in following three
Formats.
Format Length Example (Contents)
ASCII Four Bytes 31 35 32 37
Unpacked BCD Four Bytes 01 05 02 07
Packed BCD Two Bytes 15 27

82
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6

Proposition 2: BCD Arithmetic


 It is arithmetic operation.
 Microprocessor performs arithmetic operations on binary, hexadecimal
numbers.
 Arithmetic operations cannot performed directly on BCD numbers in
Packed BCD format.
Proposition 3: Subroutines, Procedure, FAR, NEAR, CALL, RET
Arguments /, Parameters
Large programs are more error prone. It also becomes difficult to find error
from such programs hence repeated groups of instruction in a program can
be organized as sub program. This sub program is called as sub routine or
procedures. The procedure is defined using directives PROC and ENDP
PROC DIRECTIVE FORMAT:
Name Operation Operand Comment

Procedure_name PROC FAR ;Begin procedure


…..
….
Procedure_name ENDP ;End procedure
Procedure Example
BCD_ADD PROC
…… ; Procedure Definition
……
BCD_ADD ENDP

Benefits of organizing a program into procedures:


 Reduces amount of code because a common procedure can be called
from any number of places in the code segment.
 Encourages better program organization
 Easy to maintain program as procedures are easy to identify
CALL and RET operations:
Format:

83
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6

CALL procedure_name
……
……
…..

RET

 Purpose is to transfer the control to the “called procedure”


 RET instruction returns from the called procedure to the
main /original calling program. It is last instruction in the
“Called procedure”
Types of procedure:
NEAR CALL FAR CALL
1) A Near call is a call to a 1) A Far call is a call to a procedure
procedure which is in the same which is in each difference different
code segment. code segment.

2) In Near call the contents of SP is 2) In Far call the contents of SP is


decremented by ‘2’ and the decremented by ‘2’ and value of CS
content of offset address IP is is loaded .Then SP is again
stored decremented by 2 and IP is loaded.

3) The contents of CS is not stored 3) The contents of CS is also stored


along with offset

4) Example: - Call Delay 4) Example :- Call FAR PTR Delay

5) Operation performed : 5) Operation performed :


NEAR PROC FAR PROC
SP = SP – 2 SP = SP – 2
Save IP on stack Save CS on stack
IP = Address of procedure CS = new segment base address of
the called procedure
SP =SP-2
Save IP on the stack and
IP = New offset Address of the called
procedure

Procedure Example (FAR AND NEAR )


TEMP1 PROC FAR
CALL B10 ; CALL PROC
……

84
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6

MOV AX, 4C00H ; END PROCESSING


INT 21H
TEMP1 ENDP

B10 PROC NEAR


……}
……
RET
B10 ENDP

END

Parameters/Argument can be passed between procedures in any of


TWO ways:

 Call by value(the actual parameter)

Example: passing values in


registers

MOV AX,MULTIPLICAND
MOV BX,MULTIPLIER
CALL MULTI
…..
…..
END
MULTI PROC NEAR
MUL BX
RET
MULTI ENDP

 Call by reference (Address of the data)

Example: passing addresses in


the registers

LEA BX,MULTIPLICAND

LEA SI,MULTIPLIER

CALL MULTI_1

85
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6

…..

…..

…..

END

MULTI_1 PROC NEAR

MOV AX,[BX]

MUL WORD PTR [SI]

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.

 The choice of methods of passing parameters depends on circumstances


and conventions

i.e. pass by value – for small values

pass by reference – for large values (arrays) used in high level languages
Types of Procedures based on way of execution:
 Re-entrant Procedure:-

Consider the following example:

MAIN PROGRAM Interrupt Service Routine(ISR)

MOV BH,05H ….

MOV AL,02H ….

MUL BH ;AX = AL * BH CALL Subroutine of multiplication

IRET

Suppose 8086 was in middle of executing factorial procedure when interrupt


occurs. The 8086 stops executing factorial procedure and execution branches
to ISR.

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.

The IRET instruction at the end of ISR returns to execution of factorial


procedure. Hence factorial procedure must be written in such a way that when
it is interrupted, used and re-entered the data should not be lost such
procedure is called as re-entrant procedure.

 Recursive procedure:-

Recursive procedures are the procedures which call itself.

4.0 Learning Objectives:

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.

6.0 Diagram / Concept Structure

 Call by reference(Address of the data)

Through general purpose registers:

PROC-1
General purpose
MOV AX,100 Registers

CALL PROC-2 AX, BX,CX,DX,

SI,DI,SP,BP,

PROC-2 CS,ES,SS,DS

MOV AX,BX

ADD AX,NUM

A calling procedure can be able to pass up to six parameters to the called


procedure by copying the parameters into above mentioned registers
(except SP & BP) before call instruction is executed.

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

7.0 Stepwise Procedure

Program 1(a): Addition of 8 bit BCD numbers using procedure


.MODEL SMALL
.DATA
NUM1 DB 04H
NUM2 DB 06H
BCD_SUM DW ?
.CODE
MOV AX,@DATA
MOV DS, AX
CALL BCD_ADD
MOV AH,4CH
INT 21H

BCD_ADD PROC
MOV AL, NUM1
MOV BL, NUM2
ADD AL,BL
DAA
MOV BCD_SUM, AX
RET
BCD_ADD ENDP
END

Program 1(b): Subtraction of 8 bit BCD numbers using procedure


.MODEL SMALL

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

FLOWCHART FOR ADDITION OF TWO BCD NUMBERS

START

INITIALISE ADDRESS OF ‘DS’

INITIALISE FIRST NUMBER IN ‘AX’

INITIALISE SECOND NUMBER IN ‘BX’

ADD NUMBER IN ‘AX’ WITH ‘BX’

AJUST IT VALID BCD NUMBER

STORE ANSWER OF ‘AX’ AS ‘RESULT’

STOP

Algorithm for program to add / Sub / multiply /Divide, Two BCD


numbers.

91
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6

1. Initialize the data segment with numbers on which BCD operations to

Complete the table using given program


Label Mnemonics 1.
segment

BCD_ADD PROC AX NUM1 NUM2 BCD_SUM

MOV AX, NUM1 1000 2000 3000

ADD AX, NUM2

DAA
Complete the table using given program
MOV BCD_SUM,AX
segment

RET AX NUM1 NUM2 BCD_SUM

BCD_ADD ENDP 2345 1233

3344 5366

be performed.

2. Initialize necessary supporting variable to store results generated


during above different operations.

3. Decide which part of program can be written as procedure. According


to that give name to procedures.

4. Call respective procedure to perform concerned BCD operation

5. Store result(s) during every procedure execution in respective


variables

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.

9.0 Questions for confirmation of learning:


 The student shall attempt these questions independently in the
laboratory only.
 The teacher shall supervise these activities and provide guidance if
necessary.
Complete the table using given program
Label Mnemonics 1.
segment
BCD_SUB PROC AX NUM1 NUM2 BCD-DIFF
MOV AX, NUM1 4443 2121 2322
SUB AX, NUM2
DAS
MOV BCD_DIFF, AX Complete the table using given program
2.
segment
RET AX NUM1 NUM2 BCD-DIFF
BCD_SUB ENDP
8500 3240

3010 1259

1. Explain following instructions used in the program?

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:

3. (NUM1+NUM2) - (NUM3 –NUM4) in (SPACE FOR ANSWER)

4. NEAR is ……………………Procedure. (Inter segment/Intra segment) And


FAR is ……………….. (Inter segment/Intra segment) procedure.

10.0 Sample Calculations:

Decimal Adjust Instructions DAA and DAS


Example
Instructi
Description Store
on BCD HEX BINARY
d BCD
DAA ;Decimal Adjust After Addition
 If value of lower nibble in
Accumulator is greater than 9 or set
AF flag then DAA Adds 06H to lower
nibble of accumulator 0011 0110
i.e. Lower Nibble of AL>9 or AF 36 36
+27 0010 0111
=1 then AL =AL +06. +27
5D 0101 1101
 If value of Higher nibble in 63
0000 0110
Accumulator is greater than 9 or set 0110 0011 63
AF flag then DAA Adds 06H to
Upper nibble of accumulator
Higher nibble of AL >9 or CF =1
then
AL =AL +60.
DAS ;Decimal Adjust After Subtraction 35 35 0011 0101
 If value of lower nibble in -18 -1B 0001 1011
Accumulator is greater than 9 or set 53 1A 0010 0010
AF flag then DAA subtracts 06H 0000 0110
from lower nibble of accumulator AL ---------------
i.e. Lower Nibble of AL>9 or AF 53
=1 then AL =AL - 06.

94
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6

 If value of Higher nibble in


Accumulator is greater than 9 or set
CF flag then DAA subtracts 06H
from Upper nibble of accumulator
AL
Higher nibble of AL >9 or CF =1
then AL =AL - 60.
11.0 Result:

12.0 Student’s Activity:


 Teacher shall form a group of 4 to 6 students.
 Each group shall perform only one allotted activity.
 Teacher shall supervise activity and provide guidance if necessary.

 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:

Types Register FLAG Register


AX Carry C
General
BX Zero Z
purpose
CX Sign S
registers
DX Overflow O
SI Parity P
Index Registers
DI Auxiliary A
Base Pointer BP Interrupt I
Stack Pointer SP Direction D
DS
Segment ES
Registers SS
CS
Instruction
IP
Register

13.0 Questions:

Write answers to Q..... Q.....Q......Q...... (Teacher shall allot the questions).


1. What is procedure?

96
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6

2. Differentiate NEAR and FAR procedure (Any Three points).


3. How re-entrant procedure is different from recursive procedure?
4. What are advantages of procedure over the traditional program
segment?
5. Discriminate Modular programming? How it is useful in high level
programming? Justify?
6. Write operations performed during execution of NEAR procedure in
terms of contents of CS, SP and IP.
7. Write operations performed during execution of FAR procedure in
terms of contents of CS, SP and IP.
8. List type of parameter passing in procedure. Explain any one?
9. State importance of RET instruction in Procedure?
10. What is calling procedure and called procedure? Explain with small
example?

14.0 Industrial Applications:


 Helpful in modularizing the larger programs into small modules
 It also help to increase reusability concept in software development as
programmer / developer can us already coded procedures in different
new programs or softwares.

(Space for Answers)

97
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Microprocessor and Programming (17431) Experiment No. 6

(Space for Answers)

Total Signature of
C(4) P(4) A(2)
(10) Subject Teacher

98
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy