Exp 8 SPCC
Exp 8 SPCC
08
Date:
Roll No:
● A macro can be called by writing the name of the macro in the mnemonic field of the
assembly language. The syntax of a typical macro call can be of the following form:
<name_of_macro> [<actual_parameter_spec> [,…]]
● Eg.
Macro Definition:
MACRO
INCR &MEM_VAL, &INC_VAL, ®
MOVER ® &MEM_VAL
ADD ® &INC_VAL
MOVEM ® &MEM_VAL
MEND
Macro Call:
INCR A, B
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int mnt_line_counter = 0;
int mdt_line_counter = 0;
int main() {
FILE *fl, *f2, *f3;
char mne[20], la[20];
fl = fopen("input.txt", "r");
f2 = fopen("MNT.txt", "w");
f3 = fopen("MDT.txt", "w");
printFile("input.txt", "INPUT PROGRAM");
while(fgets(mne, sizeof(mne), fl)) {
mne[strcspn(mne, "\n")] = 0;
if(strcmp(mne, "MACRO") == 0) {
fgets(la, sizeof(la), fl);
la[strcspn(la, "\n")] = 0;
char *token = strtok(la, " ");
fprintf(f2, "%d %s %d\n", mnt_line_counter, token, mdt_line_counter);
fprintf(f3, "%d %s\n", mdt_line_counter, token);
mnt_line_counter++;
mdt_line_counter++;
fgets(mne, sizeof(mne), fl);
mne[strcspn(mne, "\n")] = 0;
while(strcmp(mne, "MEND") != 0) {
fprintf(f3, "%d %s\n", mdt_line_counter, mne);
mdt_line_counter++;
fgets(mne, sizeof(mne), fl);
mne[strcspn(mne, "\n")] = 0;
}
fprintf(f3, "%d %s\n", mdt_line_counter, mne);
mdt_line_counter++;
}
}
fclose(fl);
fclose(f2);
fclose(f3);
printFile("MNT.txt", "Macro Name Table");
return 0;
}
Output:
Input.txt:
MDT.txt:
MNT.txt:
Conclusion: Here, we have understood the Macro name table of the Macro processor and
implemented it using c.