IGNOU BCA Reader,
1. Find the averages of two values stored in memory location named FIRST and SECOND and put the result in the memory location AVGE.
2. Write a Program for interchanging the values of two Memory locations ( tow memory variable of same size: 8 bit program)
3. Write a program using 8086 assembly language that adds two single digit ASCII digits stored in two consecutive memory locations. The result must be moved to DL register.
DATA SEGMENT
NUM1 DB '2';
NUM2 DB '3';
DATA ENDS
CODE SEGMENT
START:
ASSUME CS:CODE, DS:DATA
MOV AX,DATA
MOV DS,AX
MOV AL, NUM1
ADD AL, NUM2
MOV DL AL
MOV AX, 4C00H
INT 21H
CODE ENDS
END START
Explanation :4. Matching two strings of same length stored in memory locations, if the 8086 string instruction would have used.
In this example these following registers has been used : CS, DS, ES, AX, DX, CX, SI, DI
DATA SEGMENT
PASSWORD DB 'FALSESAFE';
DESTSRT DB 'FEELSAFE' ;
MESSAGE DB 'string are equal $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, ES:DATA
MOV AX, DATA
MOV DS, AX
MOV ES, AX
LEA SI, PASSWORD
LEA DI, DESTSTR
MOV CX, 08
CLD
PEPE CMPSB
JNE NOTEQUAL
MOV AH, 09
MOV DX, OFFSET MESSAGE
INT 21h
NOTEQUAL : MOV AX, 4C00h
INT 21h
CODE ENDS
Explanation :
In data segment, we have defined PASSWORD as a source string and DESTSTR is a destination/target string by which we have to compare. MESSAGE string which will be output when both string are equal.
In code segment, All of first we have to initialize the other segment. Here we have initialize DATA SEGMENT register and EXTRA SEGMENT (ES) register. ( String is considered to be in extra segment)
LEA instruction is used to load source pointer both of String in respectively following SI(Source Index) to PASSWORD and DI (Destination Index) to DESTSTR.
MOV CX, 08 - Load the Counter Register with length of string.
CLD - Clear direction flag, so compare will be proceed in forward direction.
REPE CMPSB - This instruction tells CPU to compare the two strings byte by byte . REPE CMPSB - repeat till not equal.
( CMPSB - Compare String Byte )
JNE NOTEQUAL - If strings are not equal, then JNE instruction will be jump to given label (NOTEQUAL). JNE
MOV AH, 09 and MOV DX, OFFSET MESSAGE - display message
INT 21h - display message
NOTEQUAL Label
MOV AX, 4C00h - interrupt function to halt, return to DOS
INT 21h - Interrupt accordingly whatever in AX register have value.
5. Add two 8-bit number in the memory locations NUM1 and NUM2. the result is stored in the memory location RESULT. If there was a carry from addition it will be stored as 0000 0001 in the location CARRY. ( Used: CS, DX, AX )
DATA SEGMENT
NUM1 DB 15h
NUM2 DB 20h
RESULT DB ?
CARRY DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, NUM1
ADD AL, NUM2
MOV RESULT, AL
RCL AL, 01
AND AL, 00000001B
MOV CARRY, AL
MOV AX, 4C00h
INT 21h
CODE ENDS
END START
EXPAINATION
RCL (Rotate Carry Left) AL, 01 - Rotate carry into LSB.
AND AL, 00000001B - Mask out all except LSB
MOV AX, 4C00h with INT 21h - is used to terminate DOS.
✍️ Only article/post centric comments are allowed.
❌**No Spam**
❌**Advertisement**
❌**No abuse**
Rules strictly applied ✅