Professional Documents
Culture Documents
1
Q1
Step 2: Assembler simply generate object code as it scans the source code.
Step 3: If the instruction operand is a symbol text, has not yet been defined, the operands address is
omitted.
Step 4: When nearly half the program translation is over, some of the forward reference problem are
existed.
Step 5: Combine the process to the end of the program to fill forward reference property.
Step 6: At the end of the program, the symbol table entries with 'x' are undefined.
Ans:
#include<stdlib.h> #include<iostream>
void clrscr() {
system("cls"); }
int main()
{FILE *f1,*f2;
char ch,str[30],str1[10],str2[30],cstr[15];
int i,j,num,q,r;
clrscr();
f1=fopen("asin","w");
while(1) { ch=getchar();
2
if(ch=='*')
break;
fputc(ch,f1);}
fclose(f1);
f1=fopen("asin","r");
f2=fopen("asout","w");
while(1){
fgets(str,25,f1);
strncpy(str1,str,3);
str1[3]='\0';
j=0;
for(i=3;i<strlen(str);i++)
{str2[j]=str[i];
j++; } str2[j]='\0';
if((strcmp(str1,"lda"))==0)
{fputs("3a \t",f2);
fputs(str2,f2);
} else if((strcmp(str1,"mov"))==0)
{fputs("47\n",f2);
} else if((strcmp(str1,"add"))==0)
{fputs("80\n",f2);
} else if((strcmp(str1,"sub"))==0)
{fputs("90\n",f2);
} else if((strcmp(str1,"hlt"))==0)
3
{f7puts("76\n",f2);
break;
} else if((strcmp(str1,"sta"))==0)
{fputs("32\t",f2);
num=atoi(str2);
q=num/100; r=num%100;
if(r==0)
fputs("00\t",f2);
else
fputs(itoa(r,cstr,10),f2);
fputs("\t",f2);
fputs(itoa(q,cstr,10),f2); fputs("\n",f2);
} else
{fputs("error\n",f2);}}
fclose(f1); fclose(f2);
f2=fopen("asout","r");
ch=fgetc(f2);
ch=fgetc(f2);}
fclose(f2);
getch();