MPMC Unit-1-Part-B PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

1.

Describe the Instruction Set of 8086 Microprocessor


The 8086 instructions are categorized into the following main types
(i) Data copy /transfer instructions: These type of instructions are used to transfer
data from source operand to destination operand. All the store, load, move, exchange
input and output instructions belong to this category.
(ii) Arithmetic and Logical instructions: All the instructions performing arithmetic,
logical, increment, decrement, compare and ASCII instructions belong to this
category.
(iii) Branch Instructions: These instructions transfer control of execution to the
specified address. All the call, jump, interrupt and return instruction belong to this
class.
(iv) Loop instructions: These instructions can be used to implement unconditional and
conditional loops. The LOOP, LOOPNZ , LOOPZ instructions belong to this category.
(v) Machine control instructions: These instructions control the machine status.
NOP, HLT, WAIT and LOCK instructions belong to this class.
(vi) Flag manipulation instructions: All the instructions which directly effect the flag
register come under this group of instructions. Instructions like CLD, STD, CLI, STI
etc.., belong to this category of instructions.
(vii) Shift and Rotate instructions: These instructions involve the bit wise shifting or
rotation in either direction with or without a count in CX.
(viii) String manipulation instructions: These instructions involve various string
manipulation operations like Load, move, scan, compare, store etc..,
2. Methods of Interfacing I/O Devices
Memory Mapping IO mapping
1. 20-bit addresses are provided for IO 1. 8-bit or 16-bit address are provided for
devices. IO devices
2. The IO ports or peripherals can be treated 2. Only IN and OUT instructions can be
like memory locations and so all used for data transfer between IO
instructions related to memory can be device and the processor.
used for data transfer.
3. In memory mapped ports, the data can be 3. In IO mapped ports, the data transfer
moved from any register to port and vice can take only between the
versa accumulator and the ports
4. When memory mapping is used for IO 4. When IO mapping is used for IO
devices, the full memory address space devices, then the full address space
cannot be used for addressing memory. can be used for addressing memory.
3.
Differences between Procedures and Macros
PROCEDURES MACROS
Accessed by CALL and RET mechanism Accessed by name given to macro when
during program execution defined during assembly
Machine code for instructions only put in Machine code generated for
memory once instructions each time called
Parameters are passed in registers, Parameters passed as part of statement
memory locations or stack which calls macro
Procedures uses stack Macro does not utilize stack
A procedure can be defined anywhere in A macro can be defined anywhere in
program using the directives PROC and program using the directives MACRO and
ENDP ENDM
Procedures takes huge memory for CALL Length of code is very huge if macro’s are
(3 bytes each time CALL is used) called for more number of times
instruction
4.
ASSEMBLER DIRECTIVES
 Assembler directives are the commands to the assembler that direct the assembly
process.
 They indicate how an operand is treated by the assembler and how assembler handles
the program.
 They also direct the assembler how program and data should arrange in the memory.
 ALP’s are composed of two type of statements.
(i) The instructions which are translated to machine codes by assembler.
(ii) The directives that direct the assembler during assembly process, for which no
machine code is generated.

1. ASSUME: Assume logical segment name.


The ASSUME directive is used to inform the assembler the names of the logical
segments to be assumed for different segments used in the program .In the ALP each
segment is given name.
Syntax:ASSUME
segreg:segname,…segreg:segname
Ex: ASSUME CS:CODE
ASSUME CS:CODE,DS:DATA,SS:STACK
2. DB: Define Byte
The DB directive is used to reserve byte or bytes of memory locations in the available
memory.

Syntax: Name of variable DB initialization


value. Ex: MARKS DB 35H,30H,35H,40H
NAME DB “VARDHAMAN”
3. DW: Define Word
The DW directive serves the same puposes as the DB directive,but it now makes the
assembler reserve the number of memory words(16-bit) instead of bytes.
Syntax: variable name DW initialization values. Ex:
WORDS DW 1234H,4567H,2367H
WDATA DW 5 Dup(522h)
(or) Dup(?)
4. DD: Define Double:
The directive DD is used to define a double word (4bytes) variable.
Syntax: variablename DD 12345678H Ex:
Data1 DD 12345678H
5. DQ: Define Quad Word
This directive is used to direct the assembler to reserve 4 words (8 bytes) of memory
for the specified variable and may initialize it with the specified values.
Syntax: Name of variable DQ initialize values.
Ex: Data1 DQ 123456789ABCDEF2H
6. DT: Define Ten Bytes
The DT directive directs the assembler to define the specified variable requiring 10
bytes for its storage and initialize the 10-bytes with the specified values.
Syntax: Name of variable DT initialize values. Ex:
Data1 DT 123456789ABCDEF34567H
7. END: End of Program
The END directive marks the end of an ALP. The statement after the directive END will be
ignored by the assembler.
8. ENDP: End of Procedure
The ENDP directive is used to indicate the end of procedure. In the AL
programming the subroutines are called procedures.
Ex: Procedure Start
:
Start ENDP
9. ENDS: End of segment
The ENDS directive is used to indicate the end of
segment. Ex: DATA SEGMENT
:
DATA ENDS
10. EVEN: Align on Even memory address
The EVEN directives updates the location counter to the next
even address. Ex: EVEN
Procedure Start
:
Start ENDP
 The above structure shows a procedure START that is to be aligned at an even
address.
11. EQU: Equate
The directive EQU is used to assign a label with a value or
symbol. Ex: LABEL EQU 0500H
ADDITION EQU ADD

12. EXTRN: External and public

 The directive EXTRN informs the assembler that the names, procedures and labels
declared after this directive have been already defined in some other AL modules.

 While in other module, where names, procedures and labels actually appear, they
must be declared public using the PUBLIC directive.
Ex: MODULE1 SEGMENT PUBLIC
FACT FAR MODULE1 ENDS
MODULE2 SEGMENT EXTRN
FACT FAR MODULE2 END
13. GROUP: Group the related segments

This directive is used to form logical groups of segments with similar


purpose or type. Ex: PROGRAM GROUP CODE, DATA, STACK
*CODE, DATA and STACK segments lie within a 64KB memory segment that is named as
PROGRAM.
14. LABEL: label

The label is used to assign name to the current content of the location counter.
Ex: CONTINUE LABEL FAR
The label CONTINUE can be used for a FAR jump, if the program contains the above
statement.

15. LENGTH: Byte length of a label


This is used to refer to the length of a data array or a
string Ex : MOV CX, LENGTH ARRAY
16. LOCAL: The labels, variables, constant or procedures are declared LOCAL in a
module are to be used only by the particular module.
Ex : LOCAL a, b, Data1, Array, Routine

17. NAME: logical name of a module


The name directive is used to assign a name to an assembly language program module.
The module may now be refer to by its declared name.
Ex : Name “addition”

18. OFFSET: offset of a label


When the assembler comes across the OFFSET operator along with a label, it first
computing the 16-bit offset address of a particular label and replace the string
‘OFFSET LABEL’ by the computed offset address.
Ex : MOV SI, offset list

19. ORG: origin

The ORG directive directs the assembler to start the memory allotment for the
particular segment, block or code from the declared address in the ORG statement.

Ex: ORG 1000H

20. PROC: Procedure

The PROC directive marks the start of a named procedure in


the statement. Ex: RESULT PROC NEAR
ROUTINE PROC FAR
21. PTR: pointer
The PTR operator is used to declare the type of a label, variable or memory operator.
Ex : MOV AL, BYTE PTR [SI] MOV
BX, WORD PTR [2000H]
22. SEG: segment of a label
The SEG operator is used to decide the segment address of the label, variable or
procedure.
Ex : MOV AX, SEG ARRAY
MOV DS, AX
23. SEGMENT: logical segment
The segment directive marks the starting of a logical segment
Ex: CODE SEGMENT
: CODE ENDS
24. SHORT: The SHORT operator indicates to the assembler that only one byte is
required to code the displacement for jump.
Ex : JMP SHORT LABEL
25. TYPE: The TYPE operator directs the assembler to decide the data type of the
specified label and replaces the TYPE label by the decided data type.
For word variable, the data type is 2.
For double word variable, the data type is 4.
For byte variable, the data type is 1.
Ex : STRING DW 2345H, 4567H MOV
AX, TYPE STRING AX=0002H
26. GLOBAL: The labels, variables, constants or procedures declared GLOBAL
may be used by other modules of the program.
Ex : ROUTINE PROC GLOBAL.

27. FAR PTR: This directive indicates the assembler that the label following FAR
PTR is not available within the same segment and the address of the label is of 32-
bits i.e 2-bytes of offset followed by 2-bytes of segment address.
Ex : JMP FAR PTR LABEL

28. NEAR PTR: This directive indicates that the label following NEAR PTR is in the
same segment and needs only 16-bit
i.e 2-byte offset to address it Ex :
JMP NEAR PTR LABEL CALL NEAR
PTR ROUTINE
5. Summarize the Data Copy/ Transfer Instructions used in 8086

The following instructions come under data copy / transfer instructions:


MOV PUSH POP IN OUT PUSHF POPF LEA LDS/LES XLAT
XCHG LAHF SAHF

Data Copy/ Transfer Instructions:


MOV: MOVE: This data transfer instruction transfers data from one register / memory
location to another register / memory location. The source may be any one of the
segment register or other general purpose or special purpose registers or a memory
location and another register or memory location may act as destination.
Syntax: 1) MOV mem/reg1, mem/reg2
[mem/reg1] ← [mem/reg2]
Ex: MOV BX, 0210H MOV AL, BL
MOV [SI], [BX] → is not valid
Memory uses DS as segment register. No memory to memory operation is allowed. It
won’t affect flag bits in the flag register.
2) MOV mem, data [mem] ← data
Ex: MOV [BX], 02H MOV [DI], 1231H
3) MOV reg, data [reg] ← data
Ex: MOV AL, 11H MOV CX, 1210H
4) MOV A, mem
[A] ← [mem]
Ex: MOV AL, [SI] MOV AX, [DI]
5) MOV mem, A [mem] ← A A ← : AL/AX
Ex: MOV [SI], AL MOV [SI], AX
6) MOV segreg,mem/reg [segreg] ← [mem/reg]
Ex: MOV SS, [SI]
7) MOV mem/reg, segreg [mem/reg] ← [segreg]
Ex: MOV DX, SS
In the case of immediate addressing mode, a segment register cannot be destination
register. In other words, direct loading of the segment registers with immediate data is
not permitted. To load the segment registers with immediate data, one will have to load
any general-purpose register with the data and then it will have to be moved to that
particular segment register.
Ex: Load DS with 5000H
MOV DS, 5000H; Not permitted (invalid)
Thus to transfer an immediate data into the segment register, the convert procedure is
given below:
MOV AX, 5000H MOV DS, AX
Both the source and destination operands cannot be memory locations (Except for string
instructions) Other MOV instructions examples are given below with the corresponding
addressing modes.
MOV AX, 5000H----------------------------Immediate
MOV AX, BX--------------------------------Register
MOV AX, [SI]--------------------------------Indirect
MOV AX, [2000H]--------------------------Direct
MOV AX, 50H[BX]------------------------- Based relative, 50H displacement

PUSH: Push to Stack: This instruction pushes the contents of the specified
register/memory location on to the stack. The stack pointer is decremented by 2, after each
execution of the instruction. The actual current stack-top is always occupied by the
previously pushed data. Hence, the push operation decrements SP by two and this store
the two-byte contents of the operand onto the stack. The higher byte is pushed first and
then the lower byte. Thus out of the two decremental stack addresses the higher byte
occupies the higher address and the lower byte occupies the lower address.
Syntax: PUSH reg
[SP] ← [SP]-2
[[S]] ← [reg]
Ex:
1) PUSH AX
2) PUSH DS
3) PUSH [5000H]; content of location 5000H & 5001H in DS are pushed onto the stack.
POP: Pop from stack: This instruction when executed, loads the specified register / memory
location with the contents
of the memory location of which address is formed using the current stack segment and
stack pointer as usual. The
stack pointer is incremented by 2. The POP instruction serves exactly opposite to the PUSH
instruction.
Syntax:
i) POP mem
[SP] ← [SP] +2
[mem] ← [[SP]]
ii) POP reg
[SP] ← [SP] + 2
[reg] ← [[SP]]
Ex: 1. POP AX
2. POP DS
3. POP [5000H]
XCHG: Exchange: This instruction exchanges the contents of the specified source and
destination operands, which may
be registers or one of them may be a memory location. However, exchange of data contents
of two memory locations
is not permitted.
Syntax:
i) XCHG AX, reg 16
[AX] [reg 16]
Ex: XCHG AX, DX
ii) XCHG mem, reg
[mem] [reg]
Ex: XCHG [BX], DX
Register and memory can be both 8-bit and 16-bit and memory uses DS as segment
register.
iii) XCHG reg, reg
[reg] [ reg ]
Ex: XCHG AL, CL XCHG DX, BX
Other examples:
1. XCHG [5000H], AX; This instruction exchanges data between AX and a memory
location [5000H] in the data segment.
2. XCHG BX; This instruction exchanges data between AX and BX.
I/O Operations:
IN: Input the port: This instruction is used for reading an input port. The address of
the input port may be specified in the instruction directly or indirectly AL and AX are
the allowed destinations for 8 and 16-bit input operations. DX is the only register
(implicit), which is allowed to carry the port address.
Ex: 1. IN AL, DX
[AL] ← [PORT DX]
Input AL with the 8-bit contents of the port addressed by DX
2. IN AX, DX
[AX] ← [PORT DX]
3. IN AL, PORT [AL] ← [PORT]
4. IN AX, PORT [AX] ← [PORT]
5. IN AL, 0300H; This instruction reads data from an 8-bit
port whose address is 0300H and stores it in AL.
6. IN AX ; This instruction reads data from a 16-bit port whose
address is in DX (implicit) and stores it in AX.

OUT: Output to the Port: This instruction is used for writing to an output port.The
address of the output port may be specified in the instruction directly or implicitly in
DX. Contents of AX or AL are transferred to a directly or indirectly addressed port after
execution of this instruction. The data to an odd addressed port is transferred on D 8 –
D15 while that to an even addressed port is transferred on D0-D7.The registers AL and
AX are the allowed source operands for 8- bit and 16-bit operations respectively.
Ex: 1. OUTDX,AL
[PORT DX] ← [AL]
2. OUT DX,AX
[PORT DX] ← [AX]
3. OUT PORT,AL
[PORT] ← [AL]
4. OUT PORT,AX
[PORT] ← [AX]
Output the 8-bit or 16-bit contents of AL or AX into an I/O port addressed by the
contents of DX or local port.
5. OUT 0300H,AL; This sends data available in AL to a port whose address is
0300H
6. OUT AX; This sends data available in AX to a port whose address is specified
implicitly in DX.

6.
Procedures and Macros:

 When we need to use a group of instructions several times throughout a program


there are two ways we can avoid having to write the group of instructions each time
we want to use them.
1. One way is to write the group of instructions as a separate procedure.
2. Another way we can use macros.
Procedures:
 The procedure is a group of instructions stored as a separate program in the
memory and it is called from the main program whenever required using CALL
instruction.
 For calling the procedure we have to store the return address (next instruction
address followed by CALL) onto the stack.
 At the end of the procedure RET instruction used to return the execution to the
next instruction in the main program by retrieving the address from the top of the
stack.
 Machine codes for the procedure instructions put only once in memory.
 The procedure can be defined anywhere in the program using assembly directives
PROC and ENDP.

 The four major ways of passing parameters to and from a procedure are:
1. In registers
2. In dedicated memory location accessed by name
3. With pointers passed in registers
4. With the stack
 The type of procedure depends on where the procedure is stored in the memory.
 If it is in the same code segment where the main program is stored the it is called
near procedure otherwise it is referred to as far procedure.
 For near procedure CALL instruction pushes only the IP register contents on the
stack, since CS register contents remains unchanged for main program.
 But for Far procedure CALL instruction pushes both IP and CS on the stack.
Syntax:
Procedure name PROC near
instruction 1
instruction 2 RET
Procedure name ENDP Example:
near procedure:
ADD2 PROC near
ADD AX,BX
RET
ADD2 ENDP
far procedure:
Procedures segment
Assume CS : Procedures
ADD2 PROC far
ADD AX,BX

RET ADD2 ENDP

Procedures ends

 Depending on the characteristics the procedures are two types


1. Re-entrant Procedures
2. Recursive Procedures
Reentrant Procedures
 The procedure which can be interrupted, used and “reentered” without losing or
writing over anything.

Recursive Procedure
 A recursive procedure is procedure which calls itself.
ALP for Finding Factorial of number using procedures
CODE SEGMENT
ASSUME CS:CODE
START: MOV AX,7
CALL FACT
MOV AH,4CH
INT 21H
FACT PROC NEAR
MOV BX,AX
DEC BX
BACK: MUL BX
DEC BX
JNZ BACK
RET
ENDP
CODE ENDS
END START

Macros:
 A macro is a group of repetitive instructions in a program which are codified only
once and can be used as many times as necessary.
 A macro can be defined anywhere in program using the directives MACRO and ENDM
 Each time we call the macro in a program, the assembler will insert the defined group
of instructions in place of the call.
 The assembler generates machine codes for the group of instructions each time the
macro is called.
 Using a macro avoids the overhead time involved in calling and returning from a
procedure.

Syntax of macro:
macroname MACRO
instruction1 instruction2
.
. ENDM

ENDM
Example:

READ MACRO
MOV AH,01H
INT 21H
ENDM

DISPLAY MACRO
MOV DL,AL
MOV AH,02H
INT 21H
ENDM

ALP for Finding Factorial of number using procedures


CODE SEGMENT
ASSUME CS:CODE
FACT MACRO
MOV BX,AX
DEC BX
BACK: MUL BX
DEC BX
JNZ BACK
ENDM
START: MOV AX,7
FACT
MOV AH,4CH
INT 21H
CODE ENDS
END START
ALP for Finding Factorial of number using procedures
CODE SEGMENT ASSUME
CS:CODE START: MOV AX,7
CALL FACT
MOV AH,4CH INT 21H
FACT PROC NEAR MOV
BX,AX
DEC BX
BACK: MUL BX DEC BX
JNZ BACK RET ENDP
CODE ENDS END START
Advantage of Procedure and Macros:
Procedures:
Advantages
The machine codes for the group of instructions in the procedure only have to be put once.
Disadvantages
Need for stack
Overhead time required to call the procedure and return to the calling program.
Macros:
Advantages:
Macro avoids overhead time involving in calling and returning from a procedure.
Disadvantages::
Generating in line code each time a macro is called is that this will make the program take
up more memory than using a procedure.

7. Write an Assembler Language Program to add two numbers


DATA SEGMENT
OPR1 DW 1234H
OPR2 DW 4567H
RESULT DW 01 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
MOV BX, OPR2
CLC
ADD AX, BX
MOV DI, OFFSET RESULT
MOV [DI], AX
MOV AH, 4CH
INT 21H
CODE ENDS
END START
8. Write an ALP to find no of +ve & -ve numbers from a given series of signed numbers
Data Segment

List DW 1234, 4567, 8976, 1238, 8975,


Count EQU 05h
Data Ends

Code Segment
Assume CS:Code, DS: Data
Start: MOV AX,Data
MOV DS,AX
XOR BX,BX
XOR DX,DX
MOV CL,Count
MOV SI,OFFSET List
AGAIN: MOV AX,[SI]
SHL AX,01H
JC NEG
INC BX
JMP NEXT
NEG: INC DX
NEXT: ADD SI,02H
DEC CL
JNZ AGAIN
MOV AH,4CH
INT 21H
Code Ends
End Start
9. Write an ALP to find no of Even & Odd numbers from a given series of signed numbers

Data Segment

List DW 1234, 4567, 8976, 1238, 8975,


Count EQU 05h
Data Ends
Code Segment
Assume CS:Code, DS: Data
Start: MOV AX,Data
MOV DS,AX
XORBX,BX
XORDX,DX
MOV CL,Count
MOV SI,OFFSET List
AGAIN: MOV AX,[SI]
RORAX,01H
JC ODD
INC BX
JMP NEXT
ODD: INC DX
NEXT: ADD SI,02H
DEC CL
JNZ AGAIN
MOV AH,4CH
INT 21H
Code Ends
End Start
10. Write an ALP to find sum of series of numbers
Data Segment
Count Equ 05H
Num_List DB 01, 02, 03, 04, 05
Result DB (?)
Data Ends
Code Segment
Assume CS:Code, DS:Data
Start: MOV AX,Data
MOV DS,AX
MOV CL,Count
XORAX,AX
MOV SI.OFFSET NUM_LIST
GO: MOV BX,[SI]
ADD AX,BX
INC SI
DEC CL
JNZ GO
MOV DI,OFFSET RESULT
MOV [DI],AX
MOV AH,4CH
INT 21H
Code Ends
End Start

11. Write an ALP to convert given binary number in to gray code


Data Segment
NUM Equ 34H
Result DB (?)
Data Ends
Code Segment
Assume CS:Code, DS:Data
Start: MOV AX,Data
MOV DS,AX
MOV AX,NUM
MOV BX,AX
RCR AX,01H
XORBX,AX
MOV Result,BX
MOV AH,4CH
INT 21H
Code Ends
End Start
12. Write an ALP to perform one byte BCD addition
Data Segment
Num-1 Equ 92H
Num-2 Equ 52H
RESULT DB 02 DUP(0)
Data Ends
Code Segment
Assume CS: Code, Ds:Data
Start: MOV AX,Data
MOV DS,AX
MOV BL,NuM-1
MOV AL,Num-2
ADD AL,BL
DAA
MOV RESULT,AL
JNC GO
INC [RESULT+1]
GO: MOV AH,4CH
INT 21H
Code Ends
End Start
13. Write an ALP to find largest number from the given list
Data Segment
LISTDB 52, 56, 89, 55, 23
Count DB 05H
Largest DB (?)
Data Ends
Code Segment
Assume CS: Code, DS: Data
Start: MOV AX,Data
MOV DS,AX
MOV CL,Count
MOV SI,OFFSET LIST
MOV AL,[SI]
AGAIN: CMP AL,[SI+1]
JNL NEXT
MOV AL,[SI+1]
NEXT: INC SI
DEC CL
JNZ AGAIN
MOV SI,OFFSET Largest
MOV [SI],AL
MOV AH,4CH
INT 21H
Code Ends
End Start
14. Write an ALP to find sqare root of given 8-bit number assuming the number is perfect
square
Data Segment
NUM Equ 36H
RESULT DB (?)
Assume CS: Code, Ds:Data
Start: MOV AX,Data
MOV DS,AX
MOV CL,NUM
MOV BL,01H
MOV AL,00H
UP: CMP CL,00
JZ GO
SUB CL,BL
INC AL
ADD BL.02H
JMP UP
GO: MOV RESULT,AL
MOV AH,4CH
INT 21H
Code Ends
End Start

15. Write an ALP to arrange the given list of numbers in ascending order using bubble
sorting
Data Segment
List DB 23, 45, 56, 89, 78
Count EQU 04H
Data Ends
Code Segment
Assume CS:Code, DS:Data
Start: MOV AX,Data
MOV DS,AX
MOV DL,Count-1
AGAIN: MOV CL,DL
MOV SI,OFFSET List
BACK: MOV AL,[SI]
CMP AL,[SI+1]
JL GO
XCHG [SI+1],AL
XCHG [SI],AL
GO: INC SI
LOOP BACK
DEC DL
JNZ AGAIN
MOV AH,4CH
INT 21H
Code Ends
End Start
16. Write an ALP to find weather the given data is even or odd parity, if even parity put
DL=00H, else put DL=01H, Assuming the given data is multi byte

Data Segment
NUM DD 33 44 88 66H
BYTE_COUNT EQU 04H
Data Ends
Code Segment
Assume CS:Code,DS:Data
Start: MOV AX,Data
MOV DS,AX
MOV DH,BYTE_COUNT
XORAL,AL
MOV CL,00H
MOV SI,OFFSET NUM
NXT-BYTE: MOV AL,[SI]
JP EVEN-PARITY
INC CL
EVEN-PARITY: INC SI
MOV AL,00H
DEC DH
JNZ NXT-BYTE
MOV DL,00H
RCR CL,01H
JNC CLEAR
INC DL
CLEAR: MOV AH,4CH
INT 21H
Code Ends
End Start
17. Write an ALP to read a character from key board and convert it in to upper case
before display it, the program must be needed to terminate by pressing CNTRL+C key

Data Segment
M-1 DB ‘Enter the key:$’
M-2 DB ‘the upper case letter is:$’
Data Ends
Code Segment
Assume CS:Code, DS: Data
Start: MOV AX,Data
MOV DS,AX
MOV AX,09H
MOV DX,OFFSET M-1
INT 21H
MOV AH,01H
INT 21H
CMP AL,61H
JB NO
CMP AL,7AH
JA NO
AND AL,5FH ;or AND AL,DFH
NO: MOV DL,AL
MOV AH,09H
MOV DX,OFFSET M-2
INT 21H
MOV AH,02H
INT 21H
JMP Start
Code Ends
End Start
18. Write an ALP to perform addition, Subtraction, multiplication, division on given
operands, perform BCD operation for addition & subtraction.

Data Segment
OPR-1 Equ 98H
OPR-2 Equ 49H
SUM DW 01 DUP (00)
DIFF DW 01 DUP (00)
PROD DW 01 DUP (00)
DIV DW 01 DUP (00)
Data Ends
Code Segment
Assume CS: Code, DS: Data
Start: MOV AX,Data
MOV DS,AX
MOV BL,OPR-2
XORAL,AL
MOV AL,OPR-1
ADD AL,BL
DAA
MOV BYTE_PTR SUM,AL
JNC GO-1
INC [SUM+1]
GO-1: XORAL,AL
MOV AL,OPR-1
SUB AL,BL
DAS
MOV BYTE_PTR DIFF,AL
JNB GO-2
INC [DIFF+1]
GO-2: XORAL,AL
MOV AL,OPR-1
MUL BL
MOV WORD_PTR PROD,AX
XORAX,AX
MOV AL,OPR-1
DIV BL
MOV WORD_PTR DIV,AX
MOV AH,4CH
INT 21H
Code Segment
End Start
19. Write an ALP to compare the first 10 bytes beginning at STRG-1 with the first 10
bytes beginning at STRG-2 and branches to MATCH if they are equal, otherwise
continue in sequence.

Data Segment
MSG-1 DB 10,13 ‘Enter String-1:$’
MSG-2 DB 10,13 ‘Enter String-2:$’
MSG-3 DB 10,13 ‘STRG-1 and STRG-2 are not matching $’
MSG-4 DB 10,13 ‘STRG-1 and STRG-2 are matching $’
STRG-1 DB ‘PSCMR’
STRG-2 DB ‘PSRCMR’
Data Ends
Code Segment
Assume CS:Code, DS:Data
Start: MOV AX,Data
MOV DS,AX
MOV AH,09H
MOV DX,OFFSET MSG-1
INT 21H
MOV SI,OFFSET STRG-1
INT 21H
MOV BX,OFFSET MSG-2
INT 21H
MOV DI,OFFSET STRG-2
INT 21H
MOV CL.0AH
REP: CMP SB
JCXZ MATCH
MOV BX,00H
MOV BX,OFFSET MSG-3
MATCH: MOV BX,00H
MOV BX,OFFSET MSG-4
INT 21H
CODE ENDS
END START
20. Write an ALP to add two multi byte numbers and store the result in third number.
The stored number in the form of byte list stored with the lowest byte first.
Data Segment
Num-1 DB 05H,12H, 45H, 56H, 49H, 78H, 42H, 79H, 41H, 71H
Num-2 DB 45H, 12H, 49H, 56H, 78H, 42H, 79H, 71H, 41H, 05H
Num-3 DB 0AH DUP (00)
BYTES EQU 0AH
Data Ends
Code Segment
Assume CS: Code, DS:Data
Start: MOV AX,Data
MOV DS,AX
MOV CL,BYTES
MOV SI,OFFSET Num-1
MOV DI,OFFSET Num-2
MOV BX,OFFSET Num-3
XOR AX,AX
NXT BYTE: MOV AX,[SI]
ADC AX,[DI]
MOV BYTE_PTR [BX],AX
INC SI
INC DI
DEC CX
JNZ NXT BYTE
JNC NO CARRY
MOV BYTE_PTR [BX],01
NO CARRY: MOV AH,4CH
INT 21H
Code Ends
End Start
21. It is necessary to define a block of data in 8086 assembly language program. The
length of the block is 90,000 bytes. Give the initialization of data segment for the
above block of data. It is necessary to add second element and 68,000th element of
the above data. Give the sequence of instructions to perform the above operation.

Sol: In 8086 the length of each segment is limited to 64KB (65536 bytes). Hence we
cannot load define a continous block of 90,000 bytes. For this purpose we need to
define two segments. One segment holding the first 62536 bytes of data while the other
holding remaining 24464 bytes of data.

Data Segment
Block-1 DB FFFFH DUP (0)
Data Ends
Extra Segment
Block-2 DB 24464H DUP (0)
Extra Ends
Code Segment
Assume CS:Code, DS:Data
Start: MOV AX,Data
MOV DS,AX
MOV AX,Extra
MOV ES,AX
LEA SI,Block-1
LEA DI,Block-2
MOV CX,FFFFH
INITI-1: MOV [SI],CX
INC SI
LOOP INITI-1
MOV CX,5F90H
INITI-2: MOV [DI],CX
INC DI
LOOP INITI-2
LEA SI,Block-1
LEA DI,Block-2
MOV AL,[SI+1]
ADD AL,[DI+2464]
Code Ends
End Start

You might also like