Advertisement
Guest User

opc

a guest
Dec 12th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 20.21 KB | None | 0 0
  1. #include "Vars.h"
  2. #include "Opcodes.h"
  3. extern int Max_Line ;
  4.  
  5. int i, j ;
  6. int currentIC ;
  7.  
  8. int ExecuteProc(struct PCB *Current)
  9.     {int Done = 0 ;
  10.      currentIC = Current->IC;
  11.      while (!Done)
  12.      /* This is implementing the Instruction Cycle */
  13.      /*First, fetch instruction */
  14.       {
  15.         currentIC--;
  16.         if (currentIC == 0)
  17.         {  
  18.             printf("PID %d completed time slice. Placing at the tail of the Ready Queue\n", Current->PID);
  19.             break;
  20.         }
  21.         for (i = 0; i < 6 ; i++)
  22.             IR[i] = memory[PC][i] ; //instruction fetch
  23.  
  24.         /*Second, Decode instruction*/
  25.  
  26.         opcode = ((int) (IR[0]) - 48) * 10 ;
  27.         opcode += ((int) (IR[1]) - 48) ;
  28.  
  29.         /* Provide user information about Program Execution */
  30.         printf("*********************************************************") ;
  31.             printf("\nIn Program Execution Loop: New PC is %d OPCODE IS %d\n\n", PC, opcode) ;
  32.         /*Now execute instruction and increment PC (unless Branch) */
  33.             switch(opcode)
  34.          {case 0:    OP0(IR, Current) ; PC++; break ;
  35.           case 1:    OP1(IR, Current) ; PC++; break ;
  36.           case 2:    OP2(IR, Current) ; PC++ ; break ;
  37.           case 3:    OP3(IR, Current) ; PC++ ; break ;
  38.           case 4:    OP4(IR, Current) ; PC++ ; break ;
  39.           case 5:    OP5(IR, Current) ; PC++ ; break ;
  40.           case 6:    OP6(IR, Current) ; PC++ ; break ;
  41.           case 7:    OP7(IR, Current) ; PC++ ; break ;
  42.           case 8:    OP8(IR, Current) ; PC++ ; break ;
  43.           case 9:    OP9(IR, Current) ; PC++ ; break ;
  44.           case 10:   OP10(IR, Current) ; PC++ ; break ;
  45.           case 11:   OP11(IR, Current) ; PC++ ; break ;
  46.           case 12:   OP12(IR, Current) ; PC++ ; break ;
  47.           case 13:   OP13(IR, Current) ; PC++ ; break ;
  48.           case 14:   OP14(IR, Current) ; PC++ ; break ;
  49.           case 15:   OP15(IR, Current) ; PC++ ; break ;
  50.           case 16:   OP16(IR, Current) ; PC++ ; break ;
  51.           case 17:   OP17(IR, Current) ; PC++ ; break ;
  52.           case 18:   OP18(IR, Current) ; PC++ ; break ;
  53.           case 19:   OP19(IR, Current) ; PC++ ; break ;
  54.           case 20:   OP20(IR, Current) ; PC++ ; break ;
  55.           case 21:   OP21(IR, Current) ; PC++ ; break ;
  56.           case 22:   OP22(IR, Current) ; PC++ ; break ;
  57.           case 23:   OP23(IR, Current) ; PC++ ; break ;
  58.           case 24:   OP24(IR, Current) ; PC++ ; break ;
  59.           case 25:   OP25(IR, Current) ; PC++ ; break ;
  60.           case 26:   OP26(IR, Current) ; PC++ ; break ;
  61.           case 27:   OP27(IR, Current) ; PC++ ; break ;
  62.           case 28:   OP28(IR, Current) ; PC++ ; break ;
  63.           case 29:   OP29(IR, Current) ; PC++ ; break ;
  64.           case 30:   OP30(IR, Current) ; PC++ ; break ;
  65.           case 31:   OP31(IR, Current) ; PC++ ; break ;
  66.           case 32:   OP32(IR, Current) ; PC++ ; break ;
  67.           case 33:   OP33(IR,&PC) ; break ;
  68.           case 34:   OP34(IR,&PC) ; break ;
  69.           case 35:   OP35(IR, &PC) ; break ;
  70.           case 99: printf("ALL DONE\n") ; Done = 1 ; printMEM(100); break;
  71.           default: printf("Instruction %d not found!~\n", opcode) ;
  72.           exit(0) ;
  73.          }
  74.        }
  75.        //system("clear");
  76.      return Done ;
  77.      }
  78.  
  79.     /*These are some helper functions that do most of the
  80.       in terms of parsing to obtain operands and to perform
  81.       memory access operations.
  82.     */
  83.  
  84.     //This function returns the integer value of operand 1
  85.     //when this operand is an immediate two-byte integer.
  86.  
  87.     int ParseOp1 (char *IR)
  88.     {int VAL = (int) (IR[2] - 48) * 10 + (int) (IR[3] - 48) ;
  89.      return (VAL) ;  
  90.     }
  91.          
  92.     // returns the integer value of operand 2 when this operand is a two-byte integer.
  93.  
  94.     int ParseOp2 (char *IR)
  95.     {int VAL = (int) (IR[4] - 48) * 10 + (int) (IR[5] - 48) ;
  96.          return (VAL) ;
  97.     }
  98.  
  99.     //returns the integer value of operands 1 and 2 combined to form a 4-byte integer.
  100.     int ParseOP1andOP2Imm(char *IR)
  101.     {
  102.      int VAL = (int) (IR[2] - 48) * 1000 + (int) (IR[3] - 48) * 100
  103.          + (int) (IR[4] - 48) * 10 + (int) (IR[5] - 48) ;
  104.      return(VAL) ;
  105.     }
  106.  
  107.  
  108.     // returns the register number of the register used as operand  1 of an instruction.
  109.     // Can be either Pointer or General-Purpose register.
  110.     int ParseOp1Reg (char *IR)  
  111.         {
  112.          int VAL ;
  113.      VAL = (int) (IR[3] - 48) ;
  114.      return(VAL) ;
  115.         }
  116.  
  117.  
  118.     // returns the register number of a register used as operand  2 of an instruction.
  119.     // Can be either a Pointer or General-Purpose register.
  120.     int ParseOp2Reg (char *IR)  
  121.     {int VAL ;
  122.      VAL = (int) (IR[5] - 48) ;
  123.          return(VAL) ;
  124.     }
  125.  
  126.     // returns the data stored at memory location Memory_Location
  127.     int FetchData(int Memory_Location)  
  128.     {int VAL ;
  129.      VAL =  (int) (memory[Memory_Location][2] - 48) * 1000 ;
  130.      VAL += (int) (memory[Memory_Location][3] - 48) * 100 ;
  131.      VAL += (int) (memory[Memory_Location][4] - 48) * 10 ;
  132.      VAL += (int) (memory[Memory_Location][5] - 48) ;
  133.      return(VAL) ;
  134.      }
  135.  
  136.     //Prints out the contents of the IR on the same line.
  137.  
  138.     void PrintIR(char *IR)
  139.     { printf("IR: %s\n", IR) ; }
  140.  
  141.     void PrintLocation(int Address)
  142.     { int i ;
  143.       printf("Memory Location[%d]: ", Address) ;
  144.       for (i = 0; i < 6 ; i++)
  145.         printf(" %c ", memory[Address][i]) ;
  146.       printf("\n") ;
  147.     }
  148.     /*Converts Value from an int to a character string and stores
  149.     it in memory[Memory_Location]
  150.     */
  151.  
  152.     void StoreData(int Memory_Location, int Value)
  153.     {
  154.      if (Memory_Location > Max_Line)
  155.        Max_Line = Memory_Location ;
  156.          int start = 2;
  157.          char temp[6];
  158.          temp[0] = 'Z'; temp[1] = 'Z';
  159.          if(Value < 1000)
  160.             {start++;
  161.              temp[2] = '0';
  162.             }
  163.      if(Value < 100)
  164.             { start++;
  165.               temp[3] = '0';
  166.             }
  167.        
  168.      if(Value< 10)
  169.             {
  170.              start++;
  171.              temp[4] = '0';
  172.             }
  173.    
  174.          sprintf(&temp[start], "%d", Value);
  175.    
  176.          for(int i = 0; i < 6; i++)
  177.           memory[Memory_Location][i] = temp[i];
  178.     }
  179.  
  180.     /*Prints out all memory locations used in program*/
  181.  
  182.     /*Prints out the value of the Program Reisters*/
  183.     void PrintRegs(struct PCB *Current)
  184.     {int i, j ;
  185.      printf("\n") ;
  186.      printf("PID is %d\n", Current->PID);
  187.      printf("IC is %d\n", currentIC);
  188.      printf("ACC %d P0 %d P1 %d P2 %d P3 %d\n",ACC,PRegs[0],PRegs[1], PRegs[2], PRegs[3]) ;
  189.          printf("R0 %d R1 %d R2 %d R3 %d\n", RRegs[0], RRegs[1], RRegs[2], RRegs[3]) ;
  190.      printf("PC is %d\n", PC) ;
  191.     }
  192.  
  193.     void printMEM(int upto)
  194.         {int i;
  195.          for (i = 0; i < upto ; i++)
  196.            {printf("Memory[%d]: ", i) ;
  197.                 for(j = 0; j < 6 ; j++)
  198.                   printf("%c ", memory[i][j]) ;
  199.             printf("\n") ;
  200.            }
  201.         }
  202.  
  203.  
  204.     /*Simulate Execution of Opcodes*/
  205.  
  206.     void OP0(char *IR, struct PCB *Current)
  207.     {int PREG, VAL ;
  208.      printf("Opcode = 0. Load Pointer Immediate\n") ;
  209.      PrintIR(IR) ;
  210.      PREG = ParseOp1Reg(IR) ;
  211.      VAL =  ParseOp2 (IR) ;
  212.      PRegs[PREG] = VAL ;
  213.      PrintRegs(Current) ;
  214.      printf("*************************************************\n\n") ;
  215.     }
  216.  
  217.     void OP1(char *IR, struct PCB *Current)
  218.     {int PREG, VAL ;
  219.          printf("Opcode = 1. ADD Pointer Immediate\n");
  220.          PrintIR(IR) ;
  221.          PREG = ParseOp1Reg(IR) ;
  222.          VAL =  ParseOp2 (IR) ;
  223.      PRegs[PREG] += VAL ;
  224.      PrintRegs(Current) ;
  225.      printf("************************************************\n\n") ;
  226.  
  227.     }
  228.  
  229.     void OP2(char *IR, struct PCB *Current)
  230.         {int PREG, VAL ;
  231.          printf("Opcode = 2. Subtract Pointer Immediate\n") ;
  232.          PrintIR(IR) ;
  233.          PREG = ParseOp1Reg(IR) ;
  234.          VAL =  ParseOp2 (IR) ;
  235.      PRegs[PREG] -= VAL ;
  236.      PrintRegs(Current) ;
  237.      printf("***********************************************\n\n") ;
  238.  
  239.     }
  240.  
  241.     void OP3(char *IR, struct PCB *Current)
  242.         {int PREG, VAL ;
  243.          printf("Opcode = 3. Load Accumulator Immediate\n");
  244.          PrintIR(IR) ;
  245.          VAL = ParseOP1andOP2Imm(IR) ;
  246.      ACC = VAL ;
  247.      PrintRegs(Current) ;
  248.      printf("************************************************\n\n") ;
  249.     }
  250.        
  251.     void OP4(char *IR, struct PCB *Current)
  252.     {int PREG, Value, Address ;
  253.      printf("Opcode 4: Load ACC Register Addressing\n") ;
  254.      PrintIR(IR) ;
  255.      PREG = ParseOp1Reg(IR) ;
  256.      Address = PRegs[PREG];
  257.      Value = FetchData(Address) ;
  258.      ACC = Value ;
  259.      PrintRegs(Current) ;
  260.      printf("************************************************\n\n") ;
  261.     }
  262.  
  263.     void OP5(char *IR, struct PCB *Current)
  264.         {int PREG, Value, Address ;
  265.          printf("Opcode 5: Load ACC Direct Addressing\n") ;
  266.      PrintIR(IR) ;
  267.      PREG = ParseOp1(IR) ;
  268.      Address = PRegs[PREG] ;
  269.          Value = FetchData(Address) ;
  270.          ACC = Value ;
  271.      PrintRegs(Current) ;
  272.      printf("**********************************************\n\n") ;
  273.         }
  274.  
  275.     void OP6(char *IR, struct PCB *Current)
  276.         {int PREG, Value, Address ;
  277.          printf("Opcode 6: Store ACC Register Addressing\n") ;
  278.      PrintIR(IR) ;
  279.      PREG = ParseOp1Reg(IR) ;
  280.          Address = PRegs[PREG] ;
  281.      StoreData(Address, ACC) ;
  282.      PrintRegs(Current) ;
  283.      PrintLocation(Address) ;
  284.      printf("********************************************\n\n") ;
  285.         }
  286.  
  287.  
  288.     void OP7(char *IR, struct PCB *Current)
  289.     {int PREG, Value, Address ;
  290.          printf("Opcode 7: Store ACC Direct Addressing\n") ;
  291.      PrintIR(IR) ;
  292.          Address = ParseOP1andOP2Imm(IR) ;
  293.          StoreData(Address, ACC) ;
  294.      PrintLocation(Address) ;
  295.      printf("*********************************************\n\n") ;
  296.         }
  297.  
  298.     void OP8(char *IR, struct PCB *Current)
  299.         {int PREG, RREG, Value, Address ;
  300.          printf("Opcode 8: Store Register to Memory:  Register Addressing\n") ;
  301.      PrintIR(IR) ;
  302.          RREG = ParseOp1Reg(IR) ;
  303.          PREG = ParseOp2Reg(IR) ;
  304.          Address = PRegs[PREG] ;
  305.      Value = RRegs[RREG] ;
  306.          StoreData(Address, Value) ;
  307.      PrintLocation(Address) ;
  308.      printf("***********************************************\n\n") ;
  309.         }
  310.  
  311.     void OP9(char *IR, struct PCB *Current)
  312.         {int RREG, Value, Address ;
  313.          printf("Opcode 9: Store Register to Memory: Direct Addressing\n") ;
  314.      PrintIR(IR) ;
  315.          RREG = ParseOp1Reg(IR) ;
  316.          Address = ParseOp2(IR) ;
  317.          printf("Storing Reg %d Value %d to Memory Address %d\n",RREG,RRegs[RREG],Address) ;
  318.          StoreData(Address, RRegs[RREG]) ;
  319.      PrintLocation(Address) ;
  320.      printf("**********************************************\n\n") ;
  321.         }
  322.  
  323.     void OP10(char *IR, struct PCB *Current)
  324.     {int RREG, PREG, Value, Address ;
  325.          printf("Opcode 10: Load Register From Memory: Register Addressing\n") ;
  326.      PrintIR(IR) ;
  327.          RREG = ParseOp1Reg(IR) ;
  328.          PREG = ParseOp2Reg(IR) ;
  329.      Address = PRegs[PREG] ;
  330.          Value = FetchData(Address) ;
  331.      RRegs[RREG] = Value ;
  332.      PrintRegs(Current) ;
  333.      printf("************************************************\n\n") ;
  334.         }
  335.  
  336.     void OP11(char *IR, struct PCB *Current)
  337.         {int RREG, PREG, Value, Address ;
  338.          printf("Opcode 11: Load Register From Memory: Direct Addressing\n") ;
  339.      PrintIR(IR) ;
  340.          RREG = ParseOp1Reg(IR) ;
  341.          Address = ParseOp2(IR) ;
  342.          Value = FetchData(Address) ;
  343.          RRegs[RREG] = Value ;
  344.      PrintRegs(Current) ;
  345.      printf("*****************************************************\n\n") ;
  346.         }
  347.    
  348.     void OP12(char *IR, struct PCB *Current)
  349.         {int RREG, VAL ;
  350.          printf("Opcode = 12. Load Register R0 Immediate\n");
  351.      PrintIR(IR) ;
  352.          PrintIR(IR) ;
  353.  
  354.          VAL = ParseOP1andOP2Imm(IR) ;
  355.      printf("P1&2Imm returned %d\n", VAL) ;
  356.      RRegs[0]  = VAL ;
  357.      PrintRegs(Current) ;
  358.      printf("******************************************************\n\n") ;
  359.         }
  360.  
  361.     void OP13(char *IR, struct PCB *Current)
  362.         {int RREG, PREG, Value, Address ;
  363.          printf("Opcode 13: Register to Register Transfer\n") ;
  364.      PrintIR(IR) ;
  365.          RREG = ParseOp1Reg(IR) ;
  366.          PREG = ParseOp2Reg(IR) ;
  367.          RRegs[RREG] = RRegs[PREG] ;
  368.      PrintRegs(Current) ;
  369.      printf("******************************************************\n\n") ;
  370.         }
  371.  
  372.     void OP14(char *IR, struct PCB *Current)      
  373.         {int RREG, PREG, Value, Address ;
  374.          printf("Opcode 14: Load Accumulator From Register\n") ;
  375.      PrintIR(IR) ;
  376.          RREG = ParseOp1Reg(IR) ;
  377.      ACC = RRegs[RREG] ;
  378.      PrintRegs(Current) ;
  379.      printf("***************************************************\n\n") ;
  380.         }
  381.  
  382.     void OP15(char *IR, struct PCB *Current)
  383.         {int RREG, PREG, Value, Address ;
  384.          printf("Opcode 15: Load Register From Accumulator \n") ;
  385.      PrintIR(IR) ;
  386.          RREG = ParseOp1Reg(IR) ;
  387.          RRegs[RREG] = ACC ;
  388.      PrintRegs(Current) ;
  389.      printf("*************************************************\n\n") ;
  390.         }
  391.  
  392.    
  393.     void OP16(char *IR, struct PCB *Current)
  394.         {int PREG, VAL ;
  395.          printf("Opcode = 16. Add Accumulator Immediate\n");
  396.          PrintIR(IR) ;
  397.          VAL = ParseOP1andOP2Imm(IR) ;
  398.          ACC += VAL ;
  399.          printf("ADDED %d to ACC.\n", VAL) ;
  400.          PrintRegs(Current) ;
  401.      printf("**************************************************\n\n") ;
  402.         }
  403.  
  404.     void OP17(char *IR, struct PCB *Current)
  405.         {int PREG, VAL ;
  406.          printf("Opcode = 17. Substract Accumulator Immediate\n");
  407.          PrintIR(IR) ;
  408.          VAL = ParseOP1andOP2Imm(IR) ;
  409.          ACC -= VAL ;
  410.          PrintRegs(Current) ;
  411.      printf("**************************************************\n\n") ;
  412.         }
  413.  
  414.     void OP18(char *IR, struct PCB *Current)
  415.         {int RREG, VAL ;
  416.          printf("Opcode = 18. Add contents of Register to  Accumulator \n");
  417.          PrintIR(IR) ;
  418.      RREG = ParseOp1Reg(IR) ;
  419.          ACC  += RRegs[RREG] ;
  420.          PrintRegs(Current) ;
  421.      printf("****************************************************\n\n") ;
  422.         }
  423.  
  424.     void OP19(char *IR, struct PCB *Current)
  425.         {int RREG, VAL ;
  426.          printf("Opcode = 19. Subtract contents of Register From  Accumulator \n");
  427.          PrintIR(IR) ;
  428.          RREG = ParseOp1Reg(IR) ;
  429.          ACC  -= RRegs[RREG] ;
  430.          PrintRegs(Current) ;
  431.      printf("*****************************************************\n\n") ;
  432.         }
  433.  
  434.     void OP20(char *IR, struct PCB *Current)
  435.         {int PREG, VAL ;
  436.          printf("Opcode = 20. Add to Accumulator Register Addressing\n")  ;
  437.          PrintIR(IR) ;
  438.          PREG = ParseOp1Reg(IR) ;
  439.      VAL  = FetchData(PRegs[PREG]) ;
  440.          ACC  += VAL ;
  441.          PrintRegs(Current) ;
  442.      printf("**********************************************************\n\n") ;
  443.         }
  444.  
  445.     void OP21(char *IR, struct PCB *Current)
  446.         {int Address, PREG, VAL ;
  447.          printf("Opcode = 21. Add to Accumulator Direct Addressing\n")  ;
  448.          PrintIR(IR) ;
  449.          Address = ParseOp1(IR) ;
  450.          VAL  = FetchData(Address) ;
  451.          ACC  += VAL ;
  452.          PrintRegs(Current) ;
  453.      printf("*******************************************************\n\n") ;
  454.     }
  455.  
  456.     void OP22(char *IR, struct PCB *Current)
  457.         {int PREG, VAL ;
  458.          printf("Opcode = 22. Subtract From Accumulator Register Addressing\n")  ;
  459.          PrintIR(IR) ;
  460.          PREG = ParseOp1Reg(IR) ;
  461.          VAL  = FetchData(PRegs[PREG]) ;
  462.          ACC  -= VAL ;
  463.          PrintRegs(Current) ;
  464.      printf("********************************************************\n\n") ;
  465.         }
  466.  
  467.  
  468.     void OP23(char *IR, struct PCB *Current)
  469.         {int Address, PREG, VAL ;
  470.          printf("Opcode = 23. Subtract From Accumulator Direct Addressing\n")  ;
  471.          PrintIR(IR) ;
  472.          Address = ParseOp1(IR) ;
  473.          VAL  = FetchData(Address) ;
  474.          ACC  -= VAL ;
  475.          PrintRegs(Current) ;
  476.      printf("*******************************************************\n\n") ;
  477.         }
  478.  
  479.     void OP24(char *IR, struct PCB *Current)
  480.         {int PREG, VAL ;
  481.          printf("Opcode = 24. Compare Equal Register Addressing\n") ;
  482.          PrintIR(IR) ;
  483.          PREG = ParseOp1Reg(IR) ;
  484.          VAL  = FetchData(PRegs[PREG]) ;
  485.      if (ACC == VAL)
  486.        PSW[0] = 'T' ;
  487.      else
  488.        PSW[0] = 'F' ;
  489.      printf("PSW[0] = %c\n", PSW[0]) ;
  490.      printf("*********************************************************\n\n") ;
  491.     }
  492.  
  493.     void OP25(char *IR, struct PCB *Current)
  494.         {int PREG, VAL ;
  495.          printf("Opcode = 25. Compare Less Register Addressing\n") ;
  496.          PrintIR(IR) ;
  497.          PREG = ParseOp1Reg(IR) ;
  498.          VAL  = FetchData(PRegs[PREG]) ;
  499.          if (ACC < VAL)
  500.            PSW[0] = 'T' ;
  501.          else
  502.            PSW[0] = 'F' ;
  503.          printf("PSW[0] = %c\n", PSW[0]) ;
  504.      printf("********************************************************\n\n") ;
  505.         }
  506.  
  507.     void OP26(char *IR, struct PCB *Current)
  508.         {int PREG, VAL ;
  509.          printf("Opcode = 26. Compare Greater Register Addressing\n") ;
  510.          PrintIR(IR) ;
  511.          PREG = ParseOp1Reg(IR) ;
  512.          VAL  = FetchData(PRegs[PREG]) ;
  513.      printf("Pointer Register = P%d. Memory at Location %d is: \n", PREG, PRegs[PREG]);
  514.      PrintLocation(PRegs[PREG]) ;
  515.      printf("Comparing ACC = %d > %d\n", ACC, VAL) ;
  516.          if (ACC > VAL)
  517.            PSW[0] = 'T' ;
  518.           else
  519.            PSW[0] = 'F' ;
  520.          printf("PSW[0] set to %c\n", PSW[0]) ;
  521.      printf("***********************************************************\n\n") ;
  522.         }
  523.  
  524.     void OP27(char *IR, struct PCB *Current)
  525.         {int PREG, VAL ;
  526.          printf("Opcode = 27. Compare Greater Immediate\n") ;
  527.          PrintIR(IR) ;
  528.          VAL  = ParseOP1andOP2Imm(IR) ;
  529.          if (ACC > VAL)
  530.                 PSW[0] = 'T' ;
  531.           else
  532.                 PSW[0] = 'F' ;
  533.           printf("PSW[0] set to %c\n", PSW[0]) ;
  534.      printf("************************************************\n\n") ;
  535.         }
  536.  
  537.     void OP28(char *IR, struct PCB *Current)
  538.         {
  539.           int PREG, VAL ;
  540.           printf("Opcode = 28. Compare Equal Immediate\n") ;
  541.           PrintIR(IR) ;
  542.  
  543.           VAL  = ParseOP1andOP2Imm(IR) ;
  544.           if (ACC == VAL)
  545.                 PSW[0] = 'T' ;
  546.           else
  547.                 PSW[0] = 'F' ;
  548.           printf("PSW[0] set to %c\n", PSW[0]) ;
  549.      printf("**********************************************\n\n") ;
  550.         }
  551.  
  552.      void OP29(char *IR, struct PCB *Current)
  553.         {
  554.           int PREG, VAL ;
  555.           printf("Opcode = 29. Compare Less Immediate\n") ;
  556.           PrintIR(IR) ;
  557.  
  558.           VAL  = ParseOP1andOP2Imm(IR) ;
  559.           if (ACC < VAL)
  560.                 PSW[0] = 'T' ;
  561.           else
  562.                 PSW[0] = 'F' ;
  563.           printf("PSW[0] set to %c\n", PSW[0]) ;
  564.      printf("***********************************************\n\n") ;
  565.         }
  566.  
  567.     void OP30(char *IR, struct PCB *Current)
  568.         {
  569.           int RREG, VAL ;
  570.           printf("Opcode = 30. Compare Register Equal\n") ;
  571.           PrintIR(IR) ;
  572.       RREG = ParseOp1Reg(IR) ;
  573.  
  574.      
  575.           if (ACC == RRegs[RREG])
  576.                 PSW[0] = 'T' ;
  577.           else
  578.                 PSW[0] = 'F' ;
  579.           printf("PSW[0] set to %c\n", PSW[0]) ;
  580.      printf("***********************************************\n\n") ;
  581.         }
  582.  
  583.     void OP31(char *IR, struct PCB *Current)
  584.         {
  585.           int RREG, VAL ;
  586.           printf("Opcode = 31. Compare Register Less\n") ;
  587.           PrintIR(IR) ;
  588.           RREG = ParseOp1Reg(IR) ;
  589.  
  590.          
  591.           if (ACC < RRegs[RREG])
  592.                 PSW[0] = 'T' ;
  593.           else
  594.                 PSW[0] = 'F' ;
  595.           printf("PSW[0] set to %c\n", PSW[0]) ;
  596.      printf("*********************************************\n\n") ;
  597.         }
  598.  
  599.     void OP32(char *IR, struct PCB *Current)
  600.         {
  601.           int RREG, VAL ;
  602.           printf("Opcode = 32. Compare Register Greater\n") ;
  603.           PrintIR(IR) ;
  604.           RREG = ParseOp1Reg(IR) ;
  605.  
  606.  
  607.           if (ACC > RRegs[RREG])
  608.                 PSW[0] = 'T' ;
  609.           else
  610.                 PSW[0] = 'F' ;
  611.           printf("PSW[0] set to %c\n", PSW[0]) ;
  612.      printf("*********************************************\n\n") ;
  613.         }
  614.  
  615.     void OP33(char *IR, short int *PC)
  616.     {printf("Branch Conditional True\n") ;
  617.      if (PSW[0] == 'T')
  618.         *PC = ParseOp1(IR) ;
  619.      else
  620.         *PC = ++(*PC) ;
  621.     printf("New PC is %d\n", *PC) ;
  622.      printf("********************************************\n\n") ;
  623.     }
  624.      
  625.     void OP34(char *IR, short int *PC)
  626.         {printf("Branch Conditional False\n") ;
  627.          if (PSW[0] == 'F')
  628.                 *PC = ParseOp1(IR) ;
  629.         else
  630.                 *PC = ++(*PC) ;
  631.     printf("New PC is %d\n", (*PC)) ;
  632.      printf("******************************************\n\n") ;
  633.         }
  634.  
  635.     void OP35(char *IR, short int *PC)
  636.         {printf("Branch Unconditional \n") ;
  637.         *PC = ParseOp1(IR) ;
  638.         printf("New PC is %d\n", *PC) ;
  639.      printf("*****************************************\n\n") ;
  640.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement