SlideShare uma empresa Scribd logo
1 de 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:

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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.
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

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: