SlideShare une entreprise Scribd logo
1  sur  6
Expno:………….
Date :….............

                       MACROPROCESSOR
AIM:




ALGORITHM:
Expno:………….
Date :….............


CODING:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void expandmacro();
char a,p1[10],p2[10],p3[10], p[10],para[10][10];
int n,i=0,j=1,y=0,x=0;
void main()
{
        FILE *fmac,*fnam,*fdef;
        char a,label[10],opcode[10],operand[50],p1[10],p2[10],p3[10], p[10],para[10][10];
        int n,i=0,j=1,y=0,x=0;
        fmac=fopen("macro.txt","r");
        fnam=fopen("namtab.txt","w");
        fdef=fopen("deftab.txt","w");
        do
        {
                fscanf(fmac,"%s%s%s",label,opcode,operand);
                if(strcmp(opcode,"MACRO")==0)
                {
                        fprintf(fnam,"%sn",label);
                        fprintf(fdef,"%st%sn",label,operand);
                        n=strlen(operand);

                       for(i=0;i<=n;i++)
                       {
                               a=operand[i];
                               if(a!=',')
                               {

                              para[j][y++]=a;

                              }
                              if(a==',')
                              {
                                      para[j][y]='0';
                                      y=0;
                                      j++;
                              }

                       }
                       do
                       {
                              fscanf(fmac,"%s%s%s",label,opcode,operand);
                              for(i=1;i<=j;i++)
                              {

                                      if(strcmp(para[i],operand)==0)
                                      {
Expno:………….
Date :….............

                                              fprintf(fdef,"%st?%dn",opcode,i);

                                      }
                              }

                              if(operand[0]!='&')
                              fprintf(fdef,"%st%sn",opcode,operand);
                       }while(strcmp(opcode,"MEND")!=0);
                }
        }
        while(!feof(fmac));
        fcloseall();
        expandmacro();
}
void expandmacro()
{
       FILE *finp,*fnam,*fdef,*farg;
       int flag=0;
       char mname[10],label[10],opcode[10],operand[50];
       finp=fopen("input.txt","r");
       fnam=fopen("namtab.txt","r");
       fdef=fopen("deftab.txt","r");
       farg=fopen("argtab.txt","w");
       fscanf(fnam,"%s",mname);
       do
       {
       fscanf(finp,"%s%s%s",label,opcode,operand);
       if(strcmp(mname,opcode)==0)
       {
               flag=1;
               if(flag==1)
               {
               printf("%st%st%sn",label,opcode,operand);
                       n=strlen(operand);
               for(i=0;i<=n;i++)
                       {
                              a=operand[i];
                                     if(a!=',')
                              {

                              para[j][y++]=a;

                              }
                              if(a==',')
                              {
                                      para[j][y]='0';

                                      y=0;
                                      j++;
Expno:………….
Date :….............

                              }

                        }
                for(i=1;i<=j;i++)
                fprintf(farg,"%sn",para[i]);
                fclose(farg);
                flag=0;
                }
                fscanf(fdef,"%s%s",opcode,operand);
                        farg=fopen("argtab.txt","r");
                if(strcmp(opcode,mname)==0)
                {
                        do
                        {
                        fscanf(fdef,"%s%s",opcode,operand);
                        if(strcmp(operand,"?1")==0)
                        {
                                fscanf(farg,"%s",p);
                                strcpy(operand,p);
                                rewind(farg);
                        }
                        if(strcmp(operand,"?2")==0)
                        {
                                fscanf(farg,"%s%s",p,p1);
                                strcpy(operand,p1);
                                rewind(farg);
                        }
                        if(strcmp(operand,"?3")==0)
                        {
                                fscanf(farg,"%s%s%s",p,p1,p2);
                                strcpy(operand,p2);
                                rewind(farg);
                        }
                        printf("_t%st%sn",opcode,operand);
                        } while(strcmp(opcode,"MEND")!=0);
                }
        }
        else
        printf("%st%st%sn",label,opcode,operand);
        }while(!feof(finp));
        fcloseall();
}
Expno:………….
Date :….............




INPUT FILES:

MACRO:

COPY START    0
RDBUFF   MACRO               &INDEV,&BUFADR,&RECLTH
-   CLEAR     X
-   CLEAR     A
-   CLEAR     S
-   LDT 4096
-   TD   &INDEV
-   JEQ *-3
-   RD   &INDEV
-   COMPR     A,S
-   JEQ *+11
-   STCH &BUFADR
-   TIXR T
-   JLT *-19
-   STX &RECLTH
-   MEND-



INPUT PROGRAM:

FIRST STL              RETADR
CLOOP RDBUFF            F1,BUFFER,LENGTH
-      LDA              LENGTH
-     COMP             #0
-      JEQ              ENDFIL
ENDFIL J               @RETADR
RETADR RESW             1
LENGTH RESW             1
BUFFER RESB            4096
   -     END           FIRST
Expno:………….
Date :….............

OUTPUT:
FIRST STL     RETADR
CLOOP RDBUFF F1,BUFFER,LENGTH
-    CLEAR        X
-    CLEAR        A
-    CLEAR        S
-     LDT        4096
-     TD       F1
-     JEQ      *-3
-     RD         F1
-    COMPR     A,S
-    JEQ      *+11
-    STCH     BUFFER
-    TIXR      T
-    JLT     *-19
-    STX      LENGTH
-    MEND      -
ENDFIL J     @RETADR
RETADR RESW 1
LENGTH RESW 1
BUFFER RESB   4096
   -     END FIRST




RESULT:

Contenu connexe

Tendances

CL metaprogramming
CL metaprogrammingCL metaprogramming
CL metaprogramming
dudarev
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
akaptur
 
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐานภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
Noppanon YourJust'one
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
akaptur
 

Tendances (20)

Exercice.docx
Exercice.docxExercice.docx
Exercice.docx
 
CL metaprogramming
CL metaprogrammingCL metaprogramming
CL metaprogramming
 
Javascript compilation execution
Javascript compilation executionJavascript compilation execution
Javascript compilation execution
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
 
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐานภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
 
Virtual machines - how they work
Virtual machines - how they workVirtual machines - how they work
Virtual machines - how they work
 
StewartPlatform_cpp
StewartPlatform_cppStewartPlatform_cpp
StewartPlatform_cpp
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
Exploiting vectorization with ISPC
Exploiting vectorization with ISPCExploiting vectorization with ISPC
Exploiting vectorization with ISPC
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 
Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings
 
6. binary tree
6. binary tree6. binary tree
6. binary tree
 
C programming slide c04
C programming slide c04C programming slide c04
C programming slide c04
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
C# looping basic
C# looping basicC# looping basic
C# looping basic
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
TMPA-2017: The Quest for Average Response Time
TMPA-2017: The Quest for Average Response TimeTMPA-2017: The Quest for Average Response Time
TMPA-2017: The Quest for Average Response Time
 
Faster Python, FOSDEM
Faster Python, FOSDEMFaster Python, FOSDEM
Faster Python, FOSDEM
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
 

En vedette (6)

Pass 1 flowchart
Pass 1 flowchartPass 1 flowchart
Pass 1 flowchart
 
Macro
MacroMacro
Macro
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Two pass Assembler
Two pass AssemblerTwo pass Assembler
Two pass Assembler
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-Presented
 

Similaire à Macroprocessor

Sorting programs
Sorting programsSorting programs
Sorting programs
Varun Garg
 
More on Lex
More on LexMore on Lex
More on Lex
Tech_MX
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
gordienaysmythe
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 

Similaire à Macroprocessor (20)

Os 2 cycle
Os 2 cycleOs 2 cycle
Os 2 cycle
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Numerical Methods in C
Numerical Methods in CNumerical Methods in C
Numerical Methods in C
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
More on Lex
More on LexMore on Lex
More on Lex
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Frsa
FrsaFrsa
Frsa
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
Vcs16
Vcs16Vcs16
Vcs16
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Dvst
DvstDvst
Dvst
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 

Dernier

Dernier (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

Macroprocessor

  • 1. Expno:…………. Date :…............. MACROPROCESSOR AIM: ALGORITHM:
  • 2. Expno:…………. Date :…............. CODING: #include<stdio.h> #include<conio.h> #include<string.h> void expandmacro(); char a,p1[10],p2[10],p3[10], p[10],para[10][10]; int n,i=0,j=1,y=0,x=0; void main() { FILE *fmac,*fnam,*fdef; char a,label[10],opcode[10],operand[50],p1[10],p2[10],p3[10], p[10],para[10][10]; int n,i=0,j=1,y=0,x=0; fmac=fopen("macro.txt","r"); fnam=fopen("namtab.txt","w"); fdef=fopen("deftab.txt","w"); do { fscanf(fmac,"%s%s%s",label,opcode,operand); if(strcmp(opcode,"MACRO")==0) { fprintf(fnam,"%sn",label); fprintf(fdef,"%st%sn",label,operand); n=strlen(operand); for(i=0;i<=n;i++) { a=operand[i]; if(a!=',') { para[j][y++]=a; } if(a==',') { para[j][y]='0'; y=0; j++; } } do { fscanf(fmac,"%s%s%s",label,opcode,operand); for(i=1;i<=j;i++) { if(strcmp(para[i],operand)==0) {
  • 3. Expno:…………. Date :…............. fprintf(fdef,"%st?%dn",opcode,i); } } if(operand[0]!='&') fprintf(fdef,"%st%sn",opcode,operand); }while(strcmp(opcode,"MEND")!=0); } } while(!feof(fmac)); fcloseall(); expandmacro(); } void expandmacro() { FILE *finp,*fnam,*fdef,*farg; int flag=0; char mname[10],label[10],opcode[10],operand[50]; finp=fopen("input.txt","r"); fnam=fopen("namtab.txt","r"); fdef=fopen("deftab.txt","r"); farg=fopen("argtab.txt","w"); fscanf(fnam,"%s",mname); do { fscanf(finp,"%s%s%s",label,opcode,operand); if(strcmp(mname,opcode)==0) { flag=1; if(flag==1) { printf("%st%st%sn",label,opcode,operand); n=strlen(operand); for(i=0;i<=n;i++) { a=operand[i]; if(a!=',') { para[j][y++]=a; } if(a==',') { para[j][y]='0'; y=0; j++;
  • 4. Expno:…………. Date :…............. } } for(i=1;i<=j;i++) fprintf(farg,"%sn",para[i]); fclose(farg); flag=0; } fscanf(fdef,"%s%s",opcode,operand); farg=fopen("argtab.txt","r"); if(strcmp(opcode,mname)==0) { do { fscanf(fdef,"%s%s",opcode,operand); if(strcmp(operand,"?1")==0) { fscanf(farg,"%s",p); strcpy(operand,p); rewind(farg); } if(strcmp(operand,"?2")==0) { fscanf(farg,"%s%s",p,p1); strcpy(operand,p1); rewind(farg); } if(strcmp(operand,"?3")==0) { fscanf(farg,"%s%s%s",p,p1,p2); strcpy(operand,p2); rewind(farg); } printf("_t%st%sn",opcode,operand); } while(strcmp(opcode,"MEND")!=0); } } else printf("%st%st%sn",label,opcode,operand); }while(!feof(finp)); fcloseall(); }
  • 5. Expno:…………. Date :…............. INPUT FILES: MACRO: COPY START 0 RDBUFF MACRO &INDEV,&BUFADR,&RECLTH - CLEAR X - CLEAR A - CLEAR S - LDT 4096 - TD &INDEV - JEQ *-3 - RD &INDEV - COMPR A,S - JEQ *+11 - STCH &BUFADR - TIXR T - JLT *-19 - STX &RECLTH - MEND- INPUT PROGRAM: FIRST STL RETADR CLOOP RDBUFF F1,BUFFER,LENGTH - LDA LENGTH - COMP #0 - JEQ ENDFIL ENDFIL J @RETADR RETADR RESW 1 LENGTH RESW 1 BUFFER RESB 4096 - END FIRST
  • 6. Expno:…………. Date :…............. OUTPUT: FIRST STL RETADR CLOOP RDBUFF F1,BUFFER,LENGTH - CLEAR X - CLEAR A - CLEAR S - LDT 4096 - TD F1 - JEQ *-3 - RD F1 - COMPR A,S - JEQ *+11 - STCH BUFFER - TIXR T - JLT *-19 - STX LENGTH - MEND - ENDFIL J @RETADR RETADR RESW 1 LENGTH RESW 1 BUFFER RESB 4096 - END FIRST RESULT: