An opcode is an instruction. An operand is information used by the opcode. Not all opcodes require operands.
Each mnemonic maps directly to a machine instruction code, known as an opcode. Some mnemonics map to more than one opcode, however the instruction's operand types will determine which specific opcode will be generated.
#include<stdio.h> #include<conio.h> #include<string.h> struct symbol { char sn[35]; int add; }s[35]; void main() { int symerr=0,oper=0,i=1,j=1,lc,k,sa,p1,f,op,l,q,d,x=1; char opcode[50],lb[25],operand[25]; char optab[10][10]={"LDA","LDB","STA","ADD","COMP","J","JEQ","SUB","STA"}; char value[10][10]={"00","b8","0c","18","28","3C","30","lc","14","78"}; FILE *fp1,*fp2; clrscr(); fp1=fopen("input1.txt","r"); fp2=fopen("inter.txt","w"); fscanf(fp1,"%s %s",&lb,&opcode); if(strcmp(opcode,"START")==0) { fscanf(fp1,"%d",&lc); sa=lc; fprintf(fp2,"%d\t %s\t %s\t %d\n",lc,lb,opcode,lc); fscanf(fp1,"%s %s",&lb,&opcode); } while(!feof(fp1)) { d=lc; if(strcmp(".",lb)!=0) { if(strcmp("-",lb)!=0) { for(i=1;i<=j;i++) { if(strcmp(s[i].sn,lb)==0) symerr=1; break; } if(symerr==0) { strcpy(s[j].sn,lb); s[j].add=lc; j++; } } for(k=0;k<10;k++) for(l=0;l<10;l++) if(optab[k][l]==opcode) { fscanf(fp1,"%s",&operand); lc=lc+3; x=0; } if(strcmp(opcode,"RESW")==0) { fscanf(fp1,"%s",&operand); op=atoi(operand); lc=lc+(op*3); } else if(strcmp(opcode,"RESB")==0) { fscanf(fp1,"%s",&operand); op=atoi(operand); lc=lc+op; } else if(strcmp(opcode,"BYTE")==0) { fscanf(fp1,"%s",&operand); f=strlen(operand); lc=lc+(f-3); } else if(strcmp(opcode,"WORD")==0) { fscanf(fp1,"%s",&operand); lc=lc+3; } else { if(x==1) { fscanf(fp1,"%s",operand); lc=lc+3; } } } fprintf(fp2,"\n%d\t%s\t%s\t%s\n",d,lb,opcode,operand); if(symerr==1) fprintf(fp2,"\n**DUPLICATE SYMBOL**\n"); if(oper==1) fprintf(fp2,"\n**INVALID OPERATION CODE**\n"); fscanf(fp1,"%s\t%s",&lb,&opcode); symerr=0; oper=0; } p1=lc-sa; fprintf(fp2,"\nThe program length is %d",p1); printf("\n symbol table\tlabeL address\n"); for(q=1;q<j;q++) printf("\n%s\t%d",s[q].sn,s[q].add); fcloseall(); getch(); }
#include<stdio.h> #include<string.h> #include<stdlib.h> void chk_label(); void chk_opcode(); void READ_LINE(); struct optab { char code[10],objcode[10]; }myoptab[3]={ {"LDA","00"}, {"JMP","01"}, {"STA","02"} }; struct symtab{ char symbol[10]; int addr; }mysymtab[10]; int startaddr,locctr,symcount=0,length; char line[20],label[8],opcode[8],operand[8],programname[10]; void PASS1() { FILE *input,*inter; input=fopen("input.txt","r"); inter=fopen("inter.txt","w"); printf("LOCATION LABEL\tOPERAND\tOPCODE\n"); printf("_____________________________________"); fgets(line,20,input); READ_LINE(); if(!strcmp(opcode,"START")) { startaddr=atoi(operand); locctr=startaddr; strcpy(programname,label); fprintf(inter,"%s",line); fgets(line,20,input); } else { programname[0]='\0'; startaddr=0; locctr=0; } printf("\n %d\t %s\t%s\t %s",locctr,label,opcode,operand); while(strcmp(line,"END")!=0) { READ_LINE(); printf("\n %d\t %s \t%s\t %s",locctr,label,opcode,operand); if(label[0]!='\0') chk_label(); chk_opcode(); fprintf(inter,"%s %s %s\n",label,opcode,operand); fgets(line,20,input); } printf("\n %d\t\t%s",locctr,line); fprintf(inter,"%s",line); fclose(inter); fclose(input); } void READ_LINE() { char buff[8],word1[8],word2[8],word3[8]; int i,j=0,count=0; label[0]=opcode[0]=operand[0]=word1[0]=word2[0]=word3[0]='\0'; for(i=0;line[i]!='\0';i++) { if(line[i]!=' ') buff[j++]=line[i]; else { buff[j]='\0'; strcpy(word3,word2); strcpy(word2,word1); strcpy(word1,buff); j=0; count++; } } buff[j-1]='\0'; strcpy(word3,word2); strcpy(word2,word1); strcpy(word1,buff); switch(count) { case 0:strcpy(opcode,word1); break; case 1:strcpy(opcode,word2); strcpy(operand,word1); break; case 2:strcpy(label,word3); strcpy(opcode,word2); strcpy(operand,word1); break; } } void chk_label() { int k,dupsym=0; for(k=0;k<symcount;k++) if(!strcmp(label,mysymtab[k].symbol)) { mysymtab[k].addr=-1; dupsym=1; break; } if(!dupsym) { strcpy(mysymtab[symcount].symbol,label); mysymtab[symcount++].addr=locctr; } } void chk_opcode() { int k=0,found=0; for(k=0;k<3;k++) if(!strcmp(opcode,myoptab[k].code)) { locctr+=3; found=1; break; } if(!found) { if(!strcmp( opcode,"WORD")) locctr+=3; else if (!strcmp(opcode,"RESW")) locctr+=(3*atoi(operand)); else if(!strcmp(opcode,"RESB")) locctr+=atoi(operand); } } int main() { PASS1(); length=locctr-startaddr; }
Both the prefix and the postfix increment operators increment the operand. The difference is what is the value of the expression during the evaluation of the expression. In the prefix form, the value is already incremented. In the postfix form, it is not. int a = 1; int b = ++a; // both a and b are now equal to 2 int a = 1; int b = a++; // a is equal to 2 and b is equal to 1
popfd
op code is used as the value of instruction . And operand is address location where the instruction can meet.
Simply defining, in an expression like A+B A is an Operand B is an Operand Plus is the Operator in between
mov H , L mov is opcode H L are operands
3 for opcode fetch, 1 for opcode decode, 3 for operand fetch, and 3 for opcode store, for a total of 10, not including wait states.
An opcode is a single instruction in assembly language. An operand is the data it does something with.For example, in "MOV r0, #0C", MOV is the opcode ("move this value into this register"), while r0 (register 0) and #0C (the number 12) are operands.
Each mnemonic maps directly to a machine instruction code, known as an opcode. Some mnemonics map to more than one opcode, however the instruction's operand types will determine which specific opcode will be generated.
Every instruction contains to parts: operation code[opcode],and operand. The first part of an instruction which specifies the task to be performed by the computer is called opcode. The second part of the instruction is the data to be operated on.,and it is called operand. The operand[or data]given in the instruction may be in various forms such as 8-bit or 16-bit data, 8-bit or 16-bit address, internal register or a register or memory location.
The hard way: Download the processor manuals and code the opcode and operands by hand The easy way: Use an assembler program. The instructions are slightly different for each program, so try reading the manuals.
Immediate addressing mode is when one of the operands is "immediately" located after the opcode. It is more correct to say that the operand is part of the instruction.
Immediate addressing mode is when one of the operands is "immediately" located after the opcode. It is more correct to say that the operand is part of the instruction.
#include#include#includevoid main(){char opcode[10],operand[10],label[10],code[10][10],ch;char mnemonic[10][10]={"START","LDA","STA","LDCH","STCH","END"};int locctr,start,len,i=0,j=0;FILE *fp1,*fp2,*fp3;clrscr();fp1=fopen("INPUT.DAT","r");fp2=fopen("SYMTAB.DAT","w");fp3=fopen("OUT.DAT","w");fscanf(fp1,"%s%s%s",label,opcode,operand);if(strcmp(opcode,"START")==0){start=atoi(operand);locctr=start;fprintf(fp3,"%s\t%s\t%s\n",label,opcode,operand);fscanf(fp1,"%s%s%s",label,opcode,operand);}elselocctr=0;while(strcmp(opcode,"END")!=0){fprintf(fp3,"%d",locctr);if(strcmp(label,"**")!=0)fprintf(fp2,"%s\t%d\n",label,locctr);strcpy(code[i],mnemonic[j]);while(strcmp(mnemonic[j],"END")!=0){if(strcmp(opcode,mnemonic[j])==0){locctr+=3;break;}strcpy(code[i],mnemonic[j]);j++;}if(strcmp(opcode,"WORD")==0)locctr+=3;else if(strcmp(opcode,"RESW")==0)locctr+=(3*(atoi(operand)));else if(strcmp(opcode,"RESB")==0)locctr+=(atoi(operand));else if(strcmp(opcode,"BYTE")==0)++locctr;fprintf(fp3,"\t%s\t%s\t%s\n",label,opcode,operand);fscanf(fp1,"%s%s%s",label,opcode,operand);}fprintf(fp3,"%d\t%s\t%s\t%s\n",locctr,label,opcode,operand);fcloseall();printf("\n\nThe contents of Input Table :\n\n");fp1=fopen("INPUT.DAT","r");ch=fgetc(fp1);while(ch!=EOF){printf("%c",ch);ch=fgetc(fp1);}printf("\n\nThe contents of Output Table :\n\n\t");fp3=fopen("OUT.DAT","r");ch=fgetc(fp3);while(ch!=EOF){printf("%c",ch);ch=fgetc(fp3);}len=locctr-start;printf("\nThe length of the program is %d.\n\n",len);printf("\n\nThe contents of Symbol Table :\n\n");fp2=fopen("SYMTAB.DAT","r");ch=fgetc(fp2);while(ch!=EOF){printf("%c",ch);ch=fgetc(fp2);}fcloseall();getch();}INPUT FILE:INPUT.DAT** START 2000** LDA FIVE** STA ALPHA** LDCH CHARZ** STCH C1ALPHA RESW 1FIVE WORD 5CHARZ BYTE C'Z'C1 RESB 1** END **-Fabianski Benjamin
The assembler's role is most important.it converts the high level language statements into machine level language statements with the help of some operand and opcode specifications.there is first mnemonic opcode specification.here instead of writing binary opcodes,mnemonic opcodes can be specified.advantage of using mnemonic opcodes are:program becomes readable.debugging becomes simple.so it is the responsibility of the assembler to replace each mnemonic opcode by its respective binary opcode.also there is symbolic operand specification.in that,instead of specifying the addresses of instructions and data,symbols can be used.advantage of using the symbolic operand is that the program can be modified with no overhead.it is the responsibility of assembler to replace each symbol by its address.