Wednesday, September 17, 2008

MCA SOLVED ASSIGNMENT MCS 07 (PROJECT)

MCS 07 (PROJECT)


Q. 1. Write an interactive C language to manage the study centre with menu options like student’s details, semester enrolled for, assignments submitted and marks obtained, attendance for the practical courses etc. Using the file handling concepts. The application should he designed user-friendly.

Note: You must execute the program and submit the program logic, sample input and output along with the necessary documentation for this question. Assumptions can be made wherever necessary.

Ans. C Program:

/* Include files
********************************/
#include //-------Header file for printf, scanf
#include //-------Header file for getch(), clrscr()
#include //--------Header file exit function

/************************************************
17user defined structure
************************************************/
///-----------structure used to define date data type

Struct date
{
Int dd;
Int mm;
Int yy;
};

//--------- structure to store personal details
Struct personal
{
Char fname[20];
Char mname[20];
Char lname[20];
Char address [50];
};

//------- structure to store student’s enrollment.


//----------Assumption : One student can enroll at max. One program.

Struct enrollment
{
Char program [30]; //--------program like, B.Sc , B. Tech(IT),
B. Tech. (CE)
Etc……
Int sem; //-----semester
Struct date doe;

};

//-----structure to define subject detail like name of subject, assignment submitted or not, marks
// obtained
//-----Assumption-one . student can have at max 5 courses
struct subjects
{
Char sub_nm[30];
Char ass_flag //---assigment submitton flag, ‘y’ or ‘n’
Int marks;
};

//----- student structure
Struct student
{
Int rollno;
Struct personal pers_dtl;
Struct enrollment enr_dtl;
Int subj_cnt;
Struct subjects sub_dtls[5];
};
Typedef struct student student;

/****************************************************************
Function prototypes
****************************************************************/

Void printLine(int count, char ch);
Void printHeader ();
Char printMenu();
Void continue_prog();
Void add_student (FILE *fp);
Void view_student (FILE *fp, char choice);
Void update_student (FILE *fp, char choice);

/*************************Main Program********************************/
Void main ()
//---------declaration section
Char ch, filename[20];
FILE *fp;

//--------------------file open
Fp= fopen (“z:\’\ student. Dat “,”w+”);

While (1)
{
Ch= printMenu();
Switch (ch)
{
Case ‘1’ :
Add_student(fp);
Break;
Case ‘b’ :
View_student(fp,’b’);
Break;
Case ‘c’ :
View_student(fp,’c’);
Break;
Case ‘d’ :
View_student(fp,’c’);
Break;
Case ‘A’ :
Update_student(fp,’A’);
Break;
Case ‘B’ :
Update_student(fp,’B’);
Break;
Case ‘C’ :
Update_student(fp,’C’);
Break;
Case ‘D’ :
Update_student(fp,’D’);
Break;
Case ‘4’ :
Update_student(“\n THANK YOU ………..”);
Break;
Exit(0);
}
}//----enf of while
Fclose (fp)
//--- terminate program
Printf(“\n press any key to continue ……………………….”);
Getch();

/***************************************************************
18procedure : srch_std
19purpose : search student in a file
20input :
o 1. rollno: int
o 2. fp : FILE
*Output :
Offset, if record found
-1, if not found
****************************************************************/
Int srch_std(int rolledno, FILE *fp)
{
Int num;
//------declaration section
Int pos=-1;
Student s1;
//-- search record
Fseek(fp,0,0); //--set file pointer to begin of file
While (!feof(fp))
{
Num=fsacnf(fp, “%d”, &s1.rollno);
If(num==rollno)
Pos = ftell(fp)-sizeof(s1);
}
} //--- end of while
Return pos;
}

/******************************************************************
* procedure : update_student
* purpose : Read a roll number, and display student’s details for given roll number
* Input
* 1. fp : FILE *//--pointer to a file which contain data
* 2. choice : char //--- choice for which detail is required to be viewed
*output : None
******************************************************************/
Void update_student(FILE *fp, char choice)
{
//---declaration section
Student s1;
Int rno;
Int cno;
Int pos,
Int I;
//--- Enter rollno to be viewed
Printf(“\n Enter Roll number to be viewed :”);
Scanf(“%d”, &rno);

//---- Search student record with entered rollno from a file
Pos =srch_std;
//---if record not found
If(pos== -1)
{
Printf(“\n No record found for %d rollno”, rno);
Return;
}
//---If record found
Ftell(fp);
printHeder();
fscanf(fp, “%d”, &s1. rollno);
printf (“\nStudent Rollno : %d”,s1:rollno);
switch(choice)
{
Case ‘A’ ://--- personal detil
Printf(“\n*******************personal details************);
Printf(“\nEnter firstname middlename LastName : “);
Scanf(“%s %s %s”, &s1.pers_dt1.fname, &s1.pers_dt1.mname,&s1.pers_dt1.lname);
Fprintf (“%s %s %s”, &s1.pers_dt1.fname, &s1.pers_dt1.mname,&s1.pers_dt1.lname);
Printf (“\n Enter Address : ”);

scanf("%s", &s1.pers_dt1.address);
fprintf(fp, "%s", &s1.pers_dt1.address);
printf("\nEnter Date of birth (dd-mm-yy) : ");
scanf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.dob.yy);
fprintf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.dob.yy);


printf("\n*********************************************);
break;

case 'B': //......enrollment detail
printf("\n\n***********Enrollment Detail*****************);
printf("\nEnter program Name :");
scanf("%s",&s1.enr1_dt1.program);
fprintf(fp, "%s",&s1.enr1_dt1.program);

printf("\nEnter semester :");
scanf("%s",&s1.enr1_dt1.sem);
fprintf(fp, "%s",&s1.enr1_dt1.sem);
printf("\nEnter Date of enrollment (dd-mm-yy) : ");
scanf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.dob.yy);
fprintf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.dob.yy);
printf("\n*********************************************);
break;

case 'C': //--- assignment details
printf(************Assignment Detiail******************);
for( i=0; i {
printf ("\nsubject %s :" ,s1.sub_dtls[i].sub_nm);
printf ("submitted ?(y/n) ;");
scanf("%c", &s1.sub_dtls[i].ass_flag);
fprintf(fp, "%c", &s1.sub_dtls[i].ass_flag);
scanf("%c ", &s1.sub_dtls[i].ass_flag[i].ass_flag);
fprintf(fp, "%c ", &s1.sub_dtls[i].ass_flag[i].ass_flag);
}
break;

case 'D': //--- marks details
printf(************Marks Detiail******************);
for( i=0; i {
printf ("\nEnter Mark For subject %s :" ,s1.sub_dtls[i].sub_nm);
scanf("%c", &s1.sub_dtls[i].marks);
fprintf(fp, "%c", &s1.sub_dtls[i].marks);
}
break;
}
//----update record in file
ftell (fp);
//fwrite (&s1, sizeof (s1),1,fp);

continue_prog();
/***************************************************
*procedure : view_student
*purpose Read a roll number, and dislay student's details for given roll number
* input
*1. fp : File * // ***** pointer to a file which contain data
* 2. choice : char. //---choice for which detail is requried to be viewed
* output : None
**************************************************/
void view_student(FILE * fb, char choice)
{
//----declaration section
student s1;
int rno;
int pos;
int i;
int count;
//--- Enter rollno to be viewed
printf("\nEnter Roll Number to be Viewed :");
scanf("%d", &rno);

//--- Search student record with entered rollno from a file pos=srch_std;

//--- if record not found
if(pos== -1)
{
printf("\n No record found for %d rollno", rno);
return;
}

//--- if record found
ftell (fp);
//fread(&s1,sizeof(s1),1,fp);
printHeader();
fseek(fp,oL,0);
fscanf(fp," %d", &s.rollno);
printf("\nRoll no %d :" , s1.rollno);
swithch(choice)
{
Case ‘A’ ://--- personal detail
Printf(“\n*******************personal details************);
Printf(“\nEnter Firstname Middlename LastName : “);
Scanf(“%s %s %s”, &s1.pers_dt1.fname, &s1.pers_dt1.mname,&s1.pers_dt1.lname);
Fprintf (“%s %s %s”, &s1.pers_dt1.fname, &s1.pers_dt1.mname,&s1.pers_dt1.lname);
Printf (“\n Enter Address : ”);
scanf("%s", &s1.pers_dt1.address);
fprintf(fp, "%s", &s1.pers_dt1.address);
printf("\nEnter Date of birth (dd-mm-yy) : ");
scanf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.dob.yy);
fprintf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.dob.yy);


printf("\n*********************************************);
break;

case 'B': //......enrollment detail
printf("\n\n***********Enrollment Detail*****************);
printf("\nEnter program Name :");
scanf("%s",&s1.enr1_dt1.program);
fprintf(fp, "%s",&s1.enr1_dt1.program);

printf("\nEnter semester :");
scanf("%s",&s1.enr1_dt1.sem);
fprintf(fp, "%s",&s1.enr1_dt1.sem);
printf("\nEnter Date of enrollment (dd-mm-yy) : ");
scanf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.doe.yy);
fprintf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.doe.yy);
printf("\n*********************************************);
break;

case 'C': //--- assignment details
printf(************Assignment Detiail******************);
for( i=0; i {
printf ("\nsubject %s :" ,s1.sub_dtls[i].sub_nm);
printf ("submitted ?(y/n) ;");
scanf("%c", &s1.sub_dtls[i].ass_flag);
fprintf(fp, "%c", &s1.sub_dtls[i].ass_flag);
scanf("%c ", &s1.sub_dtls[i].ass_flag[i].ass_flag);
fprintf(fp, "%c ", &s1.sub_dtls[i].ass_flag[i].ass_flag);

}
break;

case 'D': //--- marks details
printf(************Marks Detiail******************);
for( i=0; i {
printf ("\nEnter Mark For subject %s :" ,s1.sub_dtls[i].sub_nm);
scanf("%c", &s1.sub_dtls[i].marks);
fprintf(fp, "%c", &s1.sub_dtls[i].marks);
}
break;
}

continue_prog();

/***************************************************************
* procedure : continue_prog
*purpose : print a message. Halt for trigger and switch to menu.
*Input : None
* Output : None
***********************************************************/

void continue_prog()
{
printf("\n\t\tpress any key to continue........");
getch();
}

/*************************************************************
* percedure : add_student(fp)
* purpose : Add new student record in file
* Input : fp : FILE"
* Output : None
***********************************************************/

void add_student(FILE *fp)
{
//---- declaraton section
student s1;
int i;
//-- read of input data
ptintHeader();

printf("\nEnter Student Roll number :");
scanf("%d", &s1.rollno);
fprintf(fp," %d",s1.rollno);
//---- check , does this student exist
if(srch_std(s1.rollno, fp) != -1)
{
printf("\nSorry, this rollno already exist");
continue_prog();
}
//----Enter Personal Detail
Printf(“\n*******************personal details************);
Printf(“\nEnter Firstname Middlename LastName : “);
Scanf(“%s %s %s”, &s1.pers_dt1.fname, &s1.pers_dt1.mname,&s1.pers_dt1.lname);
Fprintf (“%s %s %s”, &s1.pers_dt1.fname, &s1.pers_dt1.mname,&s1.pers_dt1.lname);
Printf (“\n Enter Address : ”);
scanf("%s", &s1.pers_dt1.address);
fprintf(fp, "%s", &s1.pers_dt1.address);
printf("\nEnter Date of birth (dd-mm-yy) : ");
scanf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.dob.yy);
fprintf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.dob.yy);


printf("\n*********************************************);

//......enrollment detail
printf("\n\n***********Enrollment Detail*****************);
printf("\nEnter program Name :");
scanf("%s",&s1.enr1_dt1.program);
fprintf(fp, "%s",&s1.enr1_dt1.program);

printf("\nEnter semester :");
scanf("%s",&s1.enr1_dt1.sem);
fprintf(fp, "%s",&s1.enr1_dt1.sem);
printf("\nEnter Date of enrollment (dd-mm-yy) : ");
scanf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.doe.yy);
fprintf("%d, %d, %d ", &s1.pers_dt1.dob.dd, &s1.pers_dt1.dob.mm, &s1.pers_dt1.doe.yy);
printf("\n*********************************************);

printf("\n\n***********Subjecct details****************************);
printf("\n How many subject enrolled :");
scanf ("%d",&s1.subj_cnt);
fprintf(fp," %d",s1.subj_cnt);
for( i=0; i {
printf("\nSubject Name :");
scanf("%s",&s1.sub_dtls[i].sub_nm);
fprintf(fp," %s", s1.sub_dtls[i].sub_nm);
s1.sub_dtls[i].ass_flag='n';
s1.sub_dtls[i].marks=0;
}

//--- assignment details
printf(************Assignment Detiail******************);
for( i=0; i {
printf ("\nsubject %s :" ,s1.sub_dtls[i].sub_nm);
printf ("submitted ?(y/n) ;");
scanf("\n%c", &s1.sub_dtls[i].ass_flag);
fprintf(fp, "%c", &s1.sub_dtls[i].ass_flag);
scanf("%c ", &s1.sub_dtls[i].ass_flag[i].ass_flag);
fprintf(fp, "%c ", &s1.sub_dtls[i].ass_flag[i].ass_flag);

}
//--- marks details
printf(************Marks Detiail******************);
for( i=0; i {
printf ("\nEnter Mark For subject %s :" ,s1.sub_dtls[i].sub_nm);
scanf("%c", &s1.sub_dtls[i].marks);
fprintf(fp, "%c", &s1.sub_dtls[i].marks);
}

//----insert student's record in file
fseek (fp, -1, SEEK_END));
//fwrite (&s1, sizeof (s1),1,fp);

continue_prog();
}

/*******************************************************************************
* prpcedure : printLine
*purpose : print a line with repeatation of chararctaer symbol
*Input :
** 1.count: int => specifies number of times a character to be printed
* 2.ch :- char=>specifies symbol to be printed
* Output : None
********************************************************************/
void printLine(int count, char ch)
{
int i;
printf("\n");
for(i=0; i {
printf("%c",ch);
}
}
/**********************************************************
*procedure : printHeader
*purpose : print page header
* Input : None
*Output : None
***********************************************************/

void printHeader()
{
clrscr();
printLine (80,'*');
printLine (80,'*');
printLine (20,'*');
printLine("STUDENT MAANGEMENT SYSTEM");
printLine(80,'*');
printLine(80,'*');
}

/*****************************************************************
* Procedure : printMenu
* Purpose : print Header, and Menu. Read choice from user input
and
return
* Input : None
*output :
* 1. ch : char=> specifies choice ('1' or '2' or '3' )
****************************************************************/
char printMenu()
{
char ch; //******* ****************Main Menu*************************
main_menu;
while(ch<'1'|| ch>'4'
{
printHeader();
printf("\n1'. Add A Student Record : ");
printf("\n2'. Add A Student Record : ");
printf("\n3'. Add A Student Record : ");
printf("\n4'. Exit : ");
printLine(40, "-");
printf("\n Enter your choice : ");
flushall();
scanf("%c",&ch);

printLine(40, '-' );
if(ch< '1' || ch>'4')
{
printf("\n Enter Valid choice. Please try again. ")
printf("\n Press any key to continue");
getch();
}
printLine(80, '*');

if(ch=='1' || ch== '4') //---- if ch is '1', return for
add_student, process '4' for exit.

return ch;
else if (ch=='2') //------ display view menu.
{
while(ch<'a' || > 'e')
{
PrintHeader();
printf(" \na. view Personal Detail " );
printf(" \nb. view Emrollment Detail " );
printf(" \nc. view Assignment Detail " );
printf(" \nd. view Marks " );
printf(" \ne. Back previous menu ");
scanf("%c",&ch);

if(ch<'a' ||>'e')
{
printLine(40, '_');
printf(" \n Enter Valid Choice Please try again . " );
printf("\n Press any key to continue.. " );
printLine(80, '*');
}
}
if (ch= ='e')
goto main_menu;
else
return ch;
}
else if (ch==3) //----- display update menu
{
while(ch< 'A' || ch> 'E')
{
PrintHeader();
printf(" \nA. view Personal Detail " );
printf(" \nB. view Emrollment Detail " );
printf(" \nC. view Assignment Detail " );
printf(" \nD. view Marks " );
printf(" \nE. Back previous menu ");
scanf("%c",&ch);

if(ch<'a' ||>'E')
{
printLine(40, '_');
printf(" \n Enter Valid Choice Please try again . " );
printf("\n Press any key to continue.. " );
printLine(80, '*');
}
}
if (ch= ='E')
goto main_menu;
else
return ch;
} //----end of update menu
}
}



































Q2. Write an assembly language program to accept a decimal number and display its hexadecimal equivalent.
Ans:
; decibin - get decimal digits from keyboard
; and convert them to binary in BX regoster

. model tiny
.code
.startup
;-------------------------------

; main program loop

start :

call read_num
call print_crlf
call print_hex
call print_crlf
jmp start ; loop endlessly

; *****************************************************************
; print_crlf
; prints out a carriage return and linefeed
; *****************************************************************

print_crlf proc
mov ah, 2h ; print character function
mov dl, 0dh ; carriage return
int 2lh ; print it
mov dl, 0ah ; linefeed
int 21h ; print it

ret
print_crlf endp

; ***************************************************************************
; read_num
; reads a number from keyboard input
; and stores it in BX in binary
; ***************************************************************************

read_nem proc

mov bx, 0h ; clear bx for number
;
; get digit form keybard and
; conevrt it to binary
;
newchar :
mov ah 1h ; keyboard input function
int 21h ; execute ^ with dos
sub a1, 30h ; ascii to binary
j1 endinpt ; jump if < 0
cmp a1, 9d ; is it > 9d?
jg endinpt ; yes, not decimal digit
cbw ; byte in a1 to wrod in ax

; digit is new in AX
; multiply number in Bx 10d

xchg ax, bx ; trade digit and number
mov cx, 10d ; put 10d in CX
mul cx ; number times 10d
xchg ax, bx ; trade number and digit
;
; add digit in AX to number in BX
;
add bx, ax ; add digit to number
jmp newchar ; get next digit
;
; check to see wht they entered
; if nothing, exit
; otherwise, return from process
;
endinpt :
emp bx, 0h ; is it 0?
jne return ; nope, return from process
exit ; yup, exit program
return :

ret
read_num endp

; **************************************************************
; print_hex
; print in hex to the sereen the contents of
; BX
; *************************************************************
print_hex proc

mov ch, 4h ; number fo digits to print

; start with first digit in Bx
; register

rotate:
mov c1, 4h ; set count to 4 bits
rol bx, cl ; left digit to right

; convert to number
mov a1, b1 ; mov to AL
and a1, 0fh ; mask off digit
add a1, 30h ; convert hex to ascii
cmp a1, 3ah ; is it > 9?
jl printit ; jump if digit =0 to 9
add a1, 27h ; digit is A to F

; print the digit in
; the AL register

printit :
mov dl, al ; put ASCII char inDL
mov ah, 2h ; display output function
int 21h ; call DOS
dec ch ; done 4 digit =0 to 9
jnz rotate ; not yet

; fallthrough and return
ret
print_hex endp
end











Q.3 Write a program to evaluates 4*(4^2)+3x +7 if flag = = or evaluates 9x+3 if flag = = 0. Assume x is a 16-bit unsigned number.

Ans.
.model small
.data
prompt1 db = " enter the number for flag "
prompt2 db = " enter the number X "
prompt3 db = " the result is "
X db ?
num db ?

.code
disp prompt1
call read_num
print _crlf ; read the number for flag
mov ax,num
add ax, num
jnc f0
disp prompt2
set ; check if carry flag
call read_num
print_crlf

mov ax,x
f1:
mul ax
mul 4
mov dx, ax
mul 3
add ax,dx
add ax, 07
jmp exit
f0 : mul 09
add ax,03
jmp exit

disp prompt3

; *********************************************************************************
; print_crif
; print out a carriage return and linefeed
; ********************************************************************************

print_crlf proc
mov ah, 2h ; print character function
mov dl, 0dh ; carriage return
int 21h ; print it
dl, 0ah ; linefeed
int 21h ; print it
ret
print_crlf endp

; ********************************************************************************
; reads number from keyboard
; ********************************************************************************

read_num proc
mov bx, oh ; clear bx for number
int 21h ; execute ^ with dos
sub a1, 30h ; ascii to binary
j1 endinpt ; jump if < 0
cmp a1, 9d ; is it > 9d?
jg endinpt ; yes, not decimal digit
cbw ; byre in a1 to word in ax

; digit is now in AX
; multiply number in BX by 10d

xchg ax, bx ; trade digit and number
mov cx, 10d ' put 10d in CX
mul cx ; number times 10d
xchg ax, bx ; trade number and digit

;
; add digit in AX to number in BX
;

add bx, ax ; add digit to number
jup newchar ; get next digit

; check to see what they entered
; if nothing, exit
; otherwise, return form process

endinpt :
cmp bx, 0h ; is it 0?
jne return ; return from process
exit
return :
ret
read_num endp
disp macro msg
mov ah, 09h
lea dx, msg
int 21h
disp endm

Exit : mov ax, 4c00h
int 21h

; ***************************************************************************
; OUTPUT
; ***************************************************************************

enter the number for flag 5
enter the number X 2
the result is 21






















Q.4 Write a program, which reads two decimal numbers, multiply them and display the product in decimal.

Ans.
.model small
.Data
Prompt1 db “Enter first number”
Prompt2 db “Enter second number”
Prompt3 db “The result is ”
.code
Disp macro msg
Mov ah, 09h
Int 21h
: disp endm
Call read_num
Mov ax, x
Cmp flag, 00
Je f0
F1: mul ax
Mul 3
Add ax, dx
Add ax, 07
Jmp exit
F0 mul 09
Add ax, 03

Disp prompt1
Call read_num
Mov bx, ax
Print clf
Disp prompt2
Call read_num
Mul bx
Print clf
Disp prompt3
Call write_num

Exit: mov ax, 4c00h
Int 21h

;**************************************************************************************
Read the decimal number
;**************************************************************************************

Read_num proc
Mov bx, 0h ; clear bx for number
; get digit form keyboard and
Newchar:
Mov ah 1h ; keyboard input function
Int 21h ; execute ^ with dos
Sub a1, 30h ; ascii to binary
J1 endinpt ; jump if < 0
Cmp a1, 9d ; is it > 9d?
Jg endinpt ; yes, not decimal digit
Cbw ; byre in a1 to word in ax


; digit is now in AX
; multiply number in BX by 10d

Xchg ax, bx ; trade digit and number
Mov cx, 10d ; put 10d in CX
Mul cx ; number times 10d
Xchg ax, bx ; trade number and digit

; add digit in AX to number in BX

Add bx, ax ; add digit to number
Jmp newchar ; get next digit

; check to see what they entered
; if nothing, exit
; otherwise, return from process
Endinpt:
Cmp bx, 0h ; is it 0?
Jne return ; return from process
Exit ; exit program

Return: ret
Read_num. endp

;************************************************************************************
; display the decimal number
;************************************************************************************

Write_num proc
Push dx ; save the values of all
Registers
Push cx
Push bx
Push ax

Mov cx, 0
Lea di, buffer_B+6
Mov bx, 10
B2: mov dx, 0
Div bx
Or d1, 30h ; separate each digit
Dec di
Mov [di ], d1 ; form the array of digits
Inc cx
Or ax, ax
Jnz b2

B3: mov ah, 2 ; display each digit
Mov d1, [di]
Int 21h
Inc di
Loop b3 ; continue till all digits displayed

Pop dx
Pop cx
Pop bx
Pop ax

Return: ret
Write_num endp

;******************************************************************************************; print_crlf
; prints out a carriage return and linefeed
;******************************************************************************************

Print_crlf proc

Mov ah, 2h ; print character function
Mov d1, 0dh ; carriage return
Int 21h ; print it
Mov d1, 0ah ; linefeed
Int 21h ; print it

Ret
Print_crlf end
End

;******************************************************************************************
OUTPUT
;******************************************************************************************

Enter first number: 8
Enter second number: 6
The result is: 48








































Q.5 Write an assembly language program to implement a stack

Ans.
----------------------------------------------------------------------------------------------------------------
; use of stack to print reverse of string
----------------------------------------------------------------------------------------------------------------

.model tiny
.stack 100h
.code
Mov cx, 0
Read_char: mov ah, 1 ; read character typed by programmer
Int 21h
Cmp a1, 0dh ; if enter key pressed go to endof
Line
Je end_of_line

Push ax ; push character in stack
Inc cx ; increment count_of_char
Jmp read_char ; go to read_char

End_of_line : pop dx ; pop character form stack
Mov ah,2 ; display poped character
Int 21h
Loop end_of_line ; if count_of_char>0 goto
End_of_line
Int 20h

;------------------------------------------------------------------------------------------------------------------------------
; OUTPUT
;----------------------------------------------------------------------------------------------------------------------------
dbcd
dcba


Website counter