SMACO

Following is the SMACO Master C program and below it are the opcodes for different programs.....


==============================================

#include<stdio.h>
#include<stdlib.h>
main(int ac, char *av[])
{

    int operation,op1,op2,opcode,ccode[6]={0,0,0,0,0,1};
    int reg[4],mem[1000],pc=0;
    FILE *fp;
    if(ac!=2)
    {
        printf("Invalid Command line arguments");
        exit(0);
    }
    fp=fopen(av[1],"r");
    if(!fp)
    {
        printf("File not exist");
        exit(0);
    }
    while(fscanf(fp,"%d",&mem[pc++])!=EOF);

    fclose(fp);

    pc=0;
    while(1)
    {
        opcode=mem[pc];
        operation=opcode/10000;
        op1=opcode%10000/1000;
        op2=opcode%10000%1000;
        switch(operation)
        {
            case 0:return;
                   break;
            case 1:reg[op1-1]+=mem[op2];
                   pc++;
                   break;
            case 2:reg[op1-1]-=mem[op2];
                   pc++;break;
            case 3:reg[op1-1]*=mem[op2];
                   pc++;break;
            case 4:reg[op1-1]=mem[op2];
                   pc++;break;
            case 5:mem[op2]=reg[op1-1];
                   pc++;break;
            case 6:
                   if(reg[op1-1]<mem[op2])
                       ccode[0]=1;
                   else
                       ccode[0]=0;
                   if(reg[op1-1]<=mem[op2])
                       ccode[1]=1;
                   else
                       ccode[1]=0;
                   if(reg[op1-1]==mem[op2])
                       ccode[2]=1;
                   else
                       ccode[2]=0;
                   if(reg[op1-1]>mem[op2])
                       ccode[3]=1;
                   else
                       ccode[3]=0;
                   if(reg[op1-1]>=mem[op2])
                       ccode[4]=1;
                   else
                       ccode[4]=0;
                   pc++;
                   break;
            case 7:
                   if(ccode[op1-1]==1)
                       pc=op2;
                   else
                       pc++;
                   break;
            case 8:reg[op1-1]/=mem[op2];
                   pc++;break;
            case 9:printf("Enter Number ");
                   scanf("%d",&mem[op2]);
                   pc++;break;
            case 10:printf("Ans is %d",mem[op2]);
                pc++;break;
        }
    }
}
================================================

1) Opcode for addition of n numbers
================================================
090011
041013
042013
090012
011012
012014
062011
071003
051015
100015
000000
0
0
0
1
0

=================================================
2) opcode for addition of two numbers
=================================================

090007
090008
041007
011008
051007
100007
000000
0
0
=================================================
3)Opcode for maximum of two numbers
=================================================
090009
090010
041009
061010
071007
100009
076008
100010
000000
0
0
=================================================
4) Opcode for maximum of three numbers
=================================================
090017
090018
090019
041017
061018
074011
041018
061019
071013
100018
076016
061019
074015
100019
076016
100017
000000
0
0
0
=================================================
5) Opcode for Prime number
=================================================
090021
041021
081023
051024
041023
051022
041021
081022
031022
021021
061026
073019
041022
011025
051022
061024
073006
100025
076020
100026
000000
0
0
2
0
1
0
=================================================
 

6 comments:

  1. I NEED CODES OF THESE TWO PROGRAMS.

    1. Write a macro pre-processor program that will create and display the contents of
    MDT, MNT and PNTAB for the following macro definition: [35]
    MACRO
    CALC &A,&B,&REG,&OP
    MOVER &REG, &A
    &OP &REG, &B
    &MOVEM &REG, &A
    MEND
    2. Write a program to implement a toy shell (Command Interpreter). It has its own
    prompt say “MyShell $”. Any normal shell command is executed from this shell
    (MyShell$) by starting a child process to execute the system program corresponding
    to the command.
    It should additionally interpret the following commands:
    typeline +n filename :- To print first n lines in the file.
    typeline -n filename :- To print last n lines in the file.
    typeline a filename :- To print all lines in the file.

    ReplyDelete
  2. I RUN THE SMACO CODE ABOVE ITS OCCURRING ERROR AT LINE OF CASE 0: WHAT SHOULD BE DONE
    [Error] return-statement with no value, in function returning 'int' [-fpermissive]

    ReplyDelete
    Replies
    1. i Have build this master SMACO program for standard mnenonics.
      STOP 00
      ADD 01
      SUB 02
      MULT 03
      MOVER 04
      MOVEM 05
      COMP 06
      BC 07
      DIV 08
      READ 09
      PRINT 10

      use these opcodes and create your SMACO and submit that file to the above program

      Delete
  3. I want smaco programm for factorial number.

    ReplyDelete
  4. sir , i want smaco for minimum of two numbers

    ReplyDelete
  5. sir ,syspro and os slips answer sheet is available ?.....if available then send me

    ReplyDelete

Note: only a member of this blog may post a comment.