Author Archives: Gangadhar Kopella

Write a program in 8086 assembly Language (with proper comments) that passes a parameter containing a lower case alphabet to a near procedure named TOUPCASE, which converts the lowercase alphabet to upper case and returns it to the calling assembly program – IGNOU MCA Assignment 2016 – 17

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-012
Course Title : Computer Organisation and Assembly Language Programming
Assignment Number : MCA(1)/012/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

 

Write a program in 8086 assembly Language (with proper comments) that passes a parameter containing a lower case alphabet to a near procedure named TOUPCASE, which converts the lowercase alphabet to upper case and returns it to the calling assembly program – IGNOU MCA Assignment 2016 – 17

Code:- 

DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

MOV BX,61H

LEA DX,MSG1
MOV AH,9
INT 21H

LEA DL,BL
MOV AH,2
INT 21H

LEA DX,MSG2
MOV AH,9
INT 21H

PUSH BX

CALL TOUPCASE

POP DX

MOV AH,2
INT 21H

MOV AH,4CH
INT 21H
CODE ENDS

TOUPCASE PROC NEAR
POP AX
POP BX

SUB BL,20H

PUSH BX
PUSH AX
RET
TOUPCASE ENDP

END START

DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV BX,61H
LEA DX,MSG1
MOV AH,9
INT 21H
LEA DL,BL
MOV AH,2
INT 21H
LEA DX,MSG2
MOV AH,9
INT 21H
PUSH BX
CALL TOUPCASE
POP DX
MOV AH,2
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
TOUPCASE PROC NEAR
POP AX
POP BX
SUB BL,20H
PUSH BX
PUSH AX
RET
TOUPCASE ENDP
END START
†

 

Screen Shots :-

Asm_program_Proc_ToUpCase

Output After Execution :-

Asm_program_Proc_ToUpCase_Output

Write a program in 8086 assembly Language that accepts a string of four characters entered using the keyboard and checks if all the entered characters are decimal digits. In case all the characters are decimal digits then it converts the entered string into equivalent binary number. – IGNOU MCA Assignment 2016 – 17

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-012
Course Title : Computer Organisation and Assembly Language Programming
Assignment Number : MCA(1)/012/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

 

Write a program in 8086 assembly Language that accepts a string of four characters entered using the keyboard and checks if all the entered characters are decimal digits. In case all the characters are decimal digits then it converts the entered string into equivalent binary number. - IGNOU MCA Assignment 2016 Р17

Code:- 

DATA SEGMENT
MSG1 DB 10,13,’ENTER NUMBER HERE :- $’
MSG2 DB 10,13,’ENTERED VALUE IS : $’
MSG3 DB 10,13,’ENTERED VALUE IS NOT A NUMBER ! $’
MSG4 DB 10,13,’ENTERED VALUE NOT A 4 DIGIT VALUE ! $’
MSG5 DB 10,13,’ENTER NUMBER IN BINARY IS :- $’

FLAG DB 0H
NUM  DW ?
RES¬† DB 20 DUP (‘$’)

P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
P11 DB 0FFH DUP (‘$’)

DATA ENDS

DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

DISPLAY MSG1

LEA DX,P1
MOV AH,0AH
INT 21H

DISPLAY MSG2
DISPLAY P11

CHECK1: CMP L1,04H
JNE NOT4D

LEA SI,P11
MOV CH,0
MOV CL,L1
DEC CL

CHECK2:
CMP [SI],30H
JB INCFLAG
CMP [SI],3AH
JB NOINC
INCFLAG:
INC FLAG
NOINC:

INC SI
LOOP CHECK2

CHECK3: CMP FLAG,0H
JNE NOTNUM

CONV:
LEA SI,P11

MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DX,1000
MUL DX

MOV NUM,AX
INC SI

MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DL,100
MUL DL

ADD NUM,AX
INC SI

MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DL,10
MUL DL

ADD NUM,AX
INC SI

MOV AX,0H
MOV AL,[SI]
SUB AL,30H

ADD NUM,AX
INC SI

MOV AX,NUM

LEA SI,RES
CALL HEX2BIN

DISPLAY MSG5

LEA DX,RES
MOV AH,9
INT 21H

JMP DONE
NOTNUM:
DISPLAY MSG3
JMP DONE

NOT4D:
DISPLAY MSG4

DONE:

MOV AH,4CH
INT 21H
CODE ENDS

HEX2BIN PROC NEAR
MOV CX,0
MOV BX,2

LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,1
JG LOOP1

ADD AL,30H
MOV [SI],AL

LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2BIN ENDP

END START

DATA SEGMENT
MSG1 DB 10,13,'ENTER NUMBER HERE :- $'
MSG2 DB 10,13,'ENTERED VALUE IS : $'
MSG3 DB 10,13,'ENTERED VALUE IS NOT A NUMBER ! $'
MSG4 DB 10,13,'ENTERED VALUE NOT A 4 DIGIT VALUE ! $'
MSG5 DB 10,13,'ENTER NUMBER IN BINARY IS :- $'
FLAG DB 0H
NUM  DW ?
RES  DB 20 DUP ('$')
P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
P11 DB 0FFH DUP ('$')
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
LEA DX,P1
MOV AH,0AH
INT 21H
DISPLAY MSG2
DISPLAY P11
CHECK1: CMP L1,04H
JNE NOT4D
LEA SI,P11
MOV CH,0
MOV CL,L1
DEC CL
CHECK2:
CMP [SI],30H
JB INCFLAG
CMP [SI],3AH
JB NOINC
INCFLAG:
INC FLAG
NOINC:
INC SI
LOOP CHECK2
CHECK3: CMP FLAG,0H
JNE NOTNUM
CONV:
LEA SI,P11
MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DX,1000
MUL DX
MOV NUM,AX
INC SI
MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DL,100
MUL DL
ADD NUM,AX
INC SI
MOV AX,0H
MOV AL,[SI]
SUB AL,30H
MOV DL,10
MUL DL
ADD NUM,AX
INC SI
MOV AX,0H
MOV AL,[SI]
SUB AL,30H
ADD NUM,AX
INC SI
MOV AX,NUM
LEA SI,RES
CALL HEX2BIN
DISPLAY MSG5
LEA DX,RES
MOV AH,9
INT 21H
JMP DONE
NOTNUM:
DISPLAY MSG3
JMP DONE
NOT4D:
DISPLAY MSG4
DONE:
MOV AH,4CH
INT 21H
CODE ENDS
HEX2BIN PROC NEAR
MOV CX,0
MOV BX,2
LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,1
JG LOOP1
ADD AL,30H
MOV [SI],AL
LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2BIN ENDP
END START

 

Screen Shots :-

Asm_program_Check_4digits_2_binary

Output After Execution :-

Asm_program_Check_4digits_2_binary_Out

Write and run an 8086 assembly language program displays a string stored in memory – IGNOU BCA Assignment 2016 – 17

BACHELOR OF COMPUTER APPLICATIONS

Course Code : BCSL-022
Course Title : Assembly Language Programming Lab
Assignment Number : BCA(2)/L-022/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

 

Write and run an 8086 assembly language program displays a string stored in memory. You must use appropriate interrupt for the same – IGNOU MCA Assignment 2016 – 17

Code:-

DATA SEGMENT
STR DB “GANGADHAR$”
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

LEA DX,STR
MOV AH,9
INT 21H

MOV AH,4CH
INT 21H
CODE ENDS

END START

DATA SEGMENT
STR DB "GANGADHAR$"
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA DX,STR
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START

 

Screen Shots :-

Asm_program_Display_String_Memory

Output After Execution :-

Asm_program_Display_String_Memory_Out

An assembly program that converts 2 ASCII digits stored in two registers (say BH and BL) into an equivalent binary number – IGNOU BCA Assignment 2016 – 17

BACHELOR OF COMPUTER APPLICATIONS

Course Code : BCSL-022
Course Title : Assembly Language Programming Lab
Assignment Number : BCA(2)/L-022/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

 

Write and run (using appropriate calling program) a near procedure in 8086 assembly language that converts 2 ASCII digits stored in two registers (say BH and BL) into an equivalent binary number. For example, if the BH and BL registers contain digits 4 and 5 respectively, then the binary number obtained will be 0010 1101 which is 45 in decimal. The parameters should be passed using registers and the result should be returned in AL register – IGNOU MCA Assignment 2016 – 17

Code:-

DATA SEGMENT
MSG1¬† DB 10,13,’VALUE IN (BH REG.) IS : $’
MSG2¬† DB 10,13,’VALUE IN (BL REG.) IS : $’
BIN  DB ?
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

MOV BH,4
MOV BL,5

LEA DX,MSG1
MOV AH,9H
INT 21H

MOV DL,BH
ADD DL,30H
MOV AH,2
INT 21H

LEA DX,MSG2
MOV AH,9H
INT 21H

MOV DL,BL
ADD DL,30H
MOV AH,2
INT 21H

CALL ASC2BIN

MOV AH,4CH
INT 21H
CODE ENDS

ASC2BIN PROC NEAR

MOV AL,BH

MOV CL,10
MUL CL
ADD AL,BL

MOV BIN,AL
RET
ASC2BIN ENDP

END START

DATA SEGMENT
MSG1  DB 10,13,'VALUE IN (BH REG.) IS : $'
MSG2  DB 10,13,'VALUE IN (BL REG.) IS : $'
BIN  DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV BH,4
MOV BL,5
LEA DX,MSG1
MOV AH,9H
INT 21H
MOV DL,BH
ADD DL,30H
MOV AH,2
INT 21H
LEA DX,MSG2
MOV AH,9H
INT 21H
MOV DL,BL
ADD DL,30H
MOV AH,2
INT 21H
CALL ASC2BIN
MOV AH,4CH
INT 21H
CODE ENDS
ASC2BIN PROC NEAR
MOV AL,BH
MOV CL,10
MUL CL
ADD AL,BL
MOV BIN,AL
RET
ASC2BIN ENDP
END START

 

Screen Shots :-

Asm_program_Ascii _2digit_To_Binary_v3

Output Before Execution :-

Asm_program_Ascii _2digit_To_Binary_v4

Output After Execution :-

Asm_program_Ascii _2digit_To_Binary_v5.1

Asm_program_Ascii _2digit_To_Binary_v5

Note :- To see the variable and its value you have to click vars button in the emulator.

Write and run an Assembly language program that converts lowercase alphabets in a given input string to uppercase – IGNOU MCA Assignment 2016 – 17

BACHELOR OF COMPUTER APPLICATIONS

Course Code : BCSL-022
Course Title : Assembly Language Programming Lab
Assignment Number : BCA(2)/L-022/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

Write and run an Assembly language program that converts lowercase alphabets in a given input string to uppercase. The input may consist of uppercase alphabets, special characters and lowercase alphabets. For example, for the input string A@abAYaf, the output will be A@ABAYAF. You may assume that the string is available in the memory and output is stored in a memory array – IGNOU MCA Assignment 2016 – 17

Code:-

DATA SEGMENT
STR DB ‘A@abAYaf$’
MSG1 DB 10,13,’STRING IN MEMORY IS : $’
MSG2 DB 10,13,’CONVERTED STRING IS : $’
DATA ENDS

DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

DISPLAY MSG1

DISPLAY STR

DISPLAY MSG2

LEA SI,STR

MOV CL,8
MOV CH,0
CHECK:
CMP [SI],61H
JB DONE

CMP [SI],5BH

UPR:    SUB [SI],20H

DONE:   INC SI
LOOP CHECK

DISPLAY STR

MOV AH,4CH
INT 21H
CODE ENDS

END START

DATA SEGMENT
STR DB 'A@abAYaf$'
MSG1 DB 10,13,'STRING IN MEMORY IS : $'
MSG2 DB 10,13,'CONVERTED STRING IS : $'
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
DISPLAY STR
DISPLAY MSG2
LEA SI,STR
MOV CL,8
MOV CH,0
CHECK:
CMP [SI],61H
JB DONE
CMP [SI],5BH
UPR:    SUB [SI],20H
DONE:   INC SI
LOOP CHECK
DISPLAY STR
MOV AH,4CH
INT 21H
CODE ENDS
END START

 

Screen Shots :-

Asm_program_Lower_2_Upper_Memory

Output After Execution :-

Asm_program_Lower_2_Upper_Memory_Out

Note :- To see the variable and its value you have to click vars button in the emulator.

Write a program in assembly language for finding the largest number in an array of 10 elements – IGNOU MCA Assignment 2016 – 17

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

 

Write a program in assembly language for finding the largest number in an array of 10 elements - IGNOU MCA Assignment 2016 Р17

Code:-

DATA SEGMENT
ARR DB 1,4,2,3,9,8,6,7,5,10
LEN DW $-ARR
LARGE DB ?
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA SI,ARR

MOV AL,ARR[SI]
MOV LARGE,AL

MOV CX,LEN
REPEAT:
MOV AL,ARR[SI]
CMP LARGE,AL
JG NOCHANGE

MOV LARGE,AL
NOCHANGE:
INC SI
LOOP REPEAT

MOV AH,4CH
INT 21H
CODE ENDS
END START

DATA SEGMENT
ARR DB 1,4,2,3,9,8,6,7,5,10
LEN DW $-ARR
LARGE DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARR
MOV AL,ARR[SI]
MOV LARGE,AL
MOV CX,LEN
REPEAT:
MOV AL,ARR[SI]
CMP LARGE,AL
JG NOCHANGE
MOV LARGE,AL
NOCHANGE:
INC SI
LOOP REPEAT
MOV AH,4CH
INT 21H
CODE ENDS
END START

 

Screen Shots :-

Asm_program_Largest_in_Array

Output Before Execution :-

Asm_program_Largest_in_Array_Output1

Output After Execution :-

Asm_program_Largest_in_Array_Output2

Note :- To see the variable and its value you have to click vars button in the emulator.

Write a program in assembly language for reversing a four byte string – IGNOU MCA Assignment 2016 – 17

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

 

Write a program in assembly language for reversing a four byte string - IGNOU MCA Assignment 2016 Р17

Code:- 

DATA SEGMENT
STR1 DB “RITU$”
STR2 DB 7 DUP (‘$’)
MSG1 DB 10,13,’STORED STRING IN MEMORY IS : $’
MSG2 DB 10,13,’REVERSE STRING IS : $’
DATA ENDS

DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

DISPLAY MSG1

DISPLAY STR1

LEA SI,STR2
LEA DI,STR1
ADD DI,3

MOV CX,4
REVERSE:
MOV AL,[DI]
MOV [SI],AL
INC SI
DEC DI
LOOP REVERSE

DISPLAY MSG2

DISPLAY STR2

MOV AH,4CH
INT 21H
CODE ENDS

DATA SEGMENT
STR1 DB "RITU$"
STR2 DB 7 DUP ('$')
MSG1 DB 10,13,'STORED STRING IN MEMORY IS : $'
MSG2 DB 10,13,'REVERSE STRING IS : $'
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
DISPLAY STR1
LEA SI,STR2
LEA DI,STR1
ADD DI,3
MOV CX,4
REVERSE:
MOV AL,[DI]
MOV [SI],AL
INC SI
DEC DI
LOOP REVERSE
DISPLAY MSG2
DISPLAY STR2
MOV AH,4CH
INT 21H
CODE ENDS

 

Screen Shots :-

Asm_program_Rev_Str_4_Memory

Output After Execution :-

Asm_program_Rev_Str_4_Memory_Output

 

Write a program in assembly language to find the factorial of any number (assume number is smaller than 10) – IGNOU MCA Assignment 2016 – 17

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

 

Write a program in assembly language to find the factorial of any number (assume number is smaller than 10) - IGNOU MCA Assignment 2016 Р17

Code:- 

DATA SEGMENT
NUM DB ?
FACT DB 1H
RES DB 10 DUP (‘$’)
MSG1 DB “ENTER NUMBER : $”
MSG2 DB 10,13,”RESULT : $”
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA DX,MSG1
MOV AH,9
INT 21H

MOV AH,1
INT 21H
SUB AL,30H
MOV NUM,AL

MOV AH,0
MOV AL,FACT
MOV CH,0
MOV CL,NUM

LABEL1: MUL CL
LOOP LABEL1

LEA SI,RES
CALL HEX2DEC

LEA DX,MSG2
MOV AH,9
INT 21H

LEA DX,RES
MOV AH,9
INT 21H

MOV AH,4CH
INT 21H
CODE ENDS

HEX2DEC PROC NEAR
MOV CX,0
MOV BX,10

LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1

ADD AL,30H
MOV [SI],AL

LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP

END START

 

 

 

DATA SEGMENT
NUM DB ?
FACT DB 1H
RES DB 10 DUP ('$')
MSG1 DB "ENTER NUMBER : $"
MSG2 DB 10,13,"RESULT : $"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV NUM,AL
MOV AH,0
MOV AL,FACT
MOV CH,0
MOV CL,NUM
LABEL1: MUL CL
LOOP LABEL1
LEA SI,RES
CALL HEX2DEC
LEA DX,MSG2
MOV AH,9
INT 21H
LEA DX,RES
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
HEX2DEC PROC NEAR
MOV CX,0
MOV BX,10
LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1
ADD AL,30H
MOV [SI],AL
LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP
END START

 

Screen Shots :-

Asm_program_Factorical

Output After Execution :-

Asm_program_Factorical_Output

 

Write a program in assembly language to find if two given strings are of equal length – IGNOU MCA Assignment 2016 – 17

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/16-17
Maximum Marks : 50
Weightage : 25%

 

Write a program in assembly language to find if two given strings are of equal length - IGNOU MCA Assignment 2016 Р17

 

Code:-

DATA SEGMENT
STR1 DB ‘GANGADHAR$’
STR2 DB ‘KOPELLA$’
MSG1 DB 10,13,’LENGTH OF THE STRING 1 IS :- $’
MSG2 DB 10,13,’LENGTH OF THE STRING 2 IS :- $’
MSG3 DB 10,13,’STRING ARE OF EQUAL LENGTH$’
MSG4 DB 10,13,’STRING ARE OF NOT EQUAL LENGTH$’
LEN1 DB 0H
LEN2 DB 0H
DATA ENDS

DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

LEA SI,STR1
NEXT1:
CMP [SI],’$’
JE DONE1
INC LEN1
INC SI
JMP NEXT1
DONE1:
DISPLAY MSG1

MOV AL,LEN1
ADD AL,30H

MOV DL,AL
MOV AH,2
INT 21H

LEA DI,STR2
NEXT2:
CMP [DI],’$’
JE DONE2
INC LEN2
INC DI
JMP NEXT2
DONE2:
DISPLAY MSG2

MOV AL,LEN2
ADD AL,30H

MOV DL,AL
MOV AH,2
INT 21H

MOV AL,LEN1
CMP AL,LEN2
JE EQUAL

DISPLAY MSG4
JMP EXIT
EQUAL:
DISPLAY MSG3

EXIT:
MOV AH,4CH
INT 21H
CODE ENDS

END START

 

DATA SEGMENT
STR1 DB 'GANGADHAR$'
STR2 DB 'KOPELLA$'
MSG1 DB 10,13,'LENGTH OF THE STRING 1 IS :- $'
MSG2 DB 10,13,'LENGTH OF THE STRING 2 IS :- $'
MSG3 DB 10,13,'STRING ARE OF EQUAL LENGTH$'
MSG4 DB 10,13,'STRING ARE OF NOT EQUAL LENGTH$' 
LEN1 DB 0H
LEN2 DB 0H 
DATA ENDS
 
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
 
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX 
 
LEA SI,STR1
NEXT1: 
CMP [SI],'$'
JE DONE1
INC LEN1
INC SI
JMP NEXT1 
DONE1: 
DISPLAY MSG1
 
MOV AL,LEN1
ADD AL,30H
 
MOV DL,AL
MOV AH,2
INT 21H
 
LEA DI,STR2
NEXT2: 
CMP [DI],'$'
JE DONE2
INC LEN2
INC DI
JMP NEXT2 
DONE2: 
DISPLAY MSG2
 
MOV AL,LEN2
ADD AL,30H
 
MOV DL,AL
MOV AH,2
INT 21H
 
MOV AL,LEN1
CMP AL,LEN2
JE EQUAL
 
DISPLAY MSG4
JMP EXIT
EQUAL: 
DISPLAY MSG3 
 
EXIT:
MOV AH,4CH
INT 21H
CODE ENDS
 
END START

 

Screen Shots :-

Asm_program_String_Equal_Length

 

Output After Execution :-

 

Asm_program_String_Equal_Length_Output

Write a macro to demonstrate #define, #if, #else preprocessor commands. 6m Jun 2010

Write a macro to demonstrate #define, #if, #else preprocessor commands. 6

 

 Code:

#include <stdio.h>
#define CHOICE 100
int my_int = 0;
#if (CHOICE == 100)
void set_my_int()
{ my_int = 35; }
#else
void set_my_int()
{
my_int = 27;
}
#endif
main ()
{
set_my_int();
clrscr();
printf(“%d\n”, my_int);
getch();
}

#include <stdio.h>
#define CHOICE 100
int my_int = 0;
#if (CHOICE == 100)
void set_my_int()
{ my_int = 35; }
#else
void set_my_int()
{
my_int = 27;
}
#endif
main ()
{
set_my_int();
clrscr();
printf("%d\n", my_int);
getch();
}

Screen Shots:

C_program_Preprocessor

C_program_Preprocessor_Out