How can I find the equation from this truth-table using k-map or QM method?

194 Views Asked by At

How can I find the equation from this truth table using k-map or QM method?

1

1

There are 1 best solutions below

0
On

The answer is that the question is flawed. The code below finds these flaws/"CONFLICTS":

Mac_3.2.57$cat kmap_so_60848669--how-can-i-find-the-equation-from-this-truth-table-using-k-map-or-qm-method.c
#include <stdio.h>

#define F0 0
#define F1 1
#define F2 2
#define F3 3
#define ALUOp0 4
#define ALUOp1 5
#define Operation2 6
#define Operation1 7
#define Operation0 8

#define dontKnow 2
#define dontCare 3

int main(void){
    int op[64][9];

    /* populate inputs */
    for(int i=0; i<64; i++){
        if(i % 2 == 1){
            op[i][0] = 1;
        }else{
            op[i][0] = 0;
        }
        if(i/2 % 2 == 1){
            op[i][1] = 1;
        }else{
            op[i][1] = 0;
        }
        if(i/4 % 2 == 1){
            op[i][2] = 1;
        }else{
            op[i][2] = 0;
        }
        if(i/8 % 2 == 1){
            op[i][3] = 1;
        }else{
            op[i][3] = 0;
        }
        if(i/16 % 2 == 1){
            op[i][4] = 1;
        }else{
            op[i][4] = 0;
        }
        if(i/32 % 2 == 1){
            op[i][5] = 1;
        }else{
            op[i][5] = 0;
        }
        op[i][Operation2] = 3;
        op[i][Operation1] = 3;
        op[i][Operation0] = 3;
    }

    /* populate outputs based on CKT */
    for(int i=0; i<64; i++){
        /* from given ckt */
        op[i][Operation2] = op[i][ALUOp0] || (op[i][ALUOp1] && op[i][F1]);
        op[i][Operation1] = !op[i][ALUOp1] || !op[i][F2];
        op[i][Operation0] = op[i][ALUOp1] && (op[i][F3] || op[i][F0]);
    }

    /* print truth table */
    printf(    "ALUOp1  ALUOp0  F3  F2  F1  F0  Operation210  Notes\n");
    for(int i=0; i<64; i++){
        printf("%d       %d       %d   %d   %d   %d   %d%d%d  ", op[i][ALUOp1], op[i][ALUOp0], op[i][F3], op[i][F2], op[i][F1], op[i][F0], op[i][Operation2], op[i][Operation1], op[i][Operation0]);
        if(op[i][ALUOp1] == 0 && op[i][ALUOp0] == 0){
            printf("row1     ");
            if(op[i][Operation2] != 0 || op[i][Operation1] != 1 || op[i][Operation0] != 0){
                printf("CONFLICTS WITH TABLE! ");
            }
        }
        if(op[i][ALUOp1] == 0 && op[i][ALUOp0] == 1){
            printf("row2     ");
            if(op[i][Operation2] != 1 || op[i][Operation1] != 1 || op[i][Operation0] != 0){
                printf("CONFLICTS WITH TABLE! ");
            }
        }
        if(op[i][ALUOp1] == 1 && op[i][F3] == 0 && op[i][F2] == 0 && op[i][F1] == 0 && op[i][F0] == 0){
            printf("row3     ");
            if(op[i][Operation2] != 0 || op[i][Operation1] != 1 || op[i][Operation0] != 0){
                printf("CONFLICTS WITH TABLE! ");
            }
        }
        if(op[i][ALUOp1] == 1 && op[i][F3] == 0 && op[i][F2] == 0 && op[i][F1] == 1 && op[i][F0] == 0){
            printf("row4     ");
            if(op[i][Operation2] != 1 || op[i][Operation1] != 1 || op[i][Operation0] != 0){
                printf("CONFLICTS WITH TABLE! ");
            }
        }
        if(op[i][ALUOp1] == 1 && op[i][F3] == 0 && op[i][F2] == 1 && op[i][F1] == 0 && op[i][F0] == 0){
            printf("row5     ");
            if(op[i][Operation2] != 0 || op[i][Operation1] != 0 || op[i][Operation0] != 0){
                printf("CONFLICTS WITH TABLE! ");
            }
        }
        if(op[i][ALUOp1] == 1 && op[i][F3] == 0 && op[i][F2] == 1 && op[i][F1] == 0 && op[i][F0] == 1){
            printf("row6     ");
            if(op[i][Operation2] != 0 || op[i][Operation1] != 0 || op[i][Operation0] != 1){
                printf("CONFLICTS WITH TABLE! ");
            }
        }
        if(op[i][ALUOp1] == 1 && op[i][F3] == 1 && op[i][F2] == 0 && op[i][F1] == 1 && op[i][F0] == 0){
            printf("row7     ");
            if(op[i][Operation2] != 1 || op[i][Operation1] != 1 || op[i][Operation0] != 1){
                printf("CONFLICTS WITH TABLE! ");
            }
        }
        printf("\n");
    }

    return(0);
}
Mac_3.2.57$cc kmap_so_60848669--how-can-i-find-the-equation-from-this-truth-table-using-k-map-or-qm-method.c
Mac_3.2.57$./a.out 
ALUOp1  ALUOp0  F3  F2  F1  F0  Operation210  Notes
0       0       0   0   0   0   010  row1     
0       0       0   0   0   1   010  row1     
0       0       0   0   1   0   010  row1     
0       0       0   0   1   1   010  row1     
0       0       0   1   0   0   010  row1     
0       0       0   1   0   1   010  row1     
0       0       0   1   1   0   010  row1     
0       0       0   1   1   1   010  row1     
0       0       1   0   0   0   010  row1     
0       0       1   0   0   1   010  row1     
0       0       1   0   1   0   010  row1     
0       0       1   0   1   1   010  row1     
0       0       1   1   0   0   010  row1     
0       0       1   1   0   1   010  row1     
0       0       1   1   1   0   010  row1     
0       0       1   1   1   1   010  row1     
0       1       0   0   0   0   110  row2     
0       1       0   0   0   1   110  row2     
0       1       0   0   1   0   110  row2     
0       1       0   0   1   1   110  row2     
0       1       0   1   0   0   110  row2     
0       1       0   1   0   1   110  row2     
0       1       0   1   1   0   110  row2     
0       1       0   1   1   1   110  row2     
0       1       1   0   0   0   110  row2     
0       1       1   0   0   1   110  row2     
0       1       1   0   1   0   110  row2     
0       1       1   0   1   1   110  row2     
0       1       1   1   0   0   110  row2     
0       1       1   1   0   1   110  row2     
0       1       1   1   1   0   110  row2     
0       1       1   1   1   1   110  row2     
1       0       0   0   0   0   010  row3     
1       0       0   0   0   1   011  
1       0       0   0   1   0   110  row4     
1       0       0   0   1   1   111  
1       0       0   1   0   0   000  row5     
1       0       0   1   0   1   001  row6     
1       0       0   1   1   0   100  
1       0       0   1   1   1   101  
1       0       1   0   0   0   011  
1       0       1   0   0   1   011  
1       0       1   0   1   0   111  row7     
1       0       1   0   1   1   111  
1       0       1   1   0   0   001  
1       0       1   1   0   1   001  
1       0       1   1   1   0   101  
1       0       1   1   1   1   101  
1       1       0   0   0   0   110  row3     CONFLICTS WITH TABLE! 
1       1       0   0   0   1   111  
1       1       0   0   1   0   110  row4     
1       1       0   0   1   1   111  
1       1       0   1   0   0   100  row5     CONFLICTS WITH TABLE! 
1       1       0   1   0   1   101  row6     CONFLICTS WITH TABLE! 
1       1       0   1   1   0   100  
1       1       0   1   1   1   101  
1       1       1   0   0   0   111  
1       1       1   0   0   1   111  
1       1       1   0   1   0   111  row7     
1       1       1   0   1   1   111  
1       1       1   1   0   0   101  
1       1       1   1   0   1   101  
1       1       1   1   1   0   101  
1       1       1   1   1   1   101  
Mac_3.2.57$

0

FWIW, here is the start of the kmaps (not accurate due to conflicts between table and CKT): Op = o2o1o0

   o2:

          f1\f0                    0                                  1            
     
               p1p0\f3f2   00   01   11   10      p1p2\f3f2   00   01   11   10
                                                                                
               00          0    0    0    0        00         0    0    0    0                  
                                                                                  
               01          x    x    x    x        01         x    x    x    x      
          0                                                                         
               11          0    0    x    x        11         x    0    x    x       
                                                                                  
               10          0    0    x    x        10         x    0    x    x       

     
               p1p0\f3f2   00   01   11   10      p1p2\f3f2   00   01   11   10
                                                                                
               00          0    0    0    0        00         0    0    0    0                  
                                                                                  
               01          x    x    x    x        01         x    x    x    x      
          1                                                                         
               11          1    x    x    1        11         x    x    x    x                
                                                                                   
               10          1    x    x    1        10         x    x    x    x             

   o1:

          f1\f0                    0                                  1            
     
               p1p0\f3f2   00   01   11   10      p1p2\f3f2   00   01   11   10
                                                                                
               00          1    1    1    1        00         1    1    1    1                  
                                                                                  
               01          x    x    x    x        01         x    x    x    x      
          0                                                                         
               11          1    0    x    x        11         x    0    x    x   
                                                                                 
               10          1    0    x    x        10         x    0    x    x   

     
               p1p0\f3f2   00   01   11   10      p1p2\f3f2   00   01   11   10
                                                                                
               00          1    1    1    1        00         1    1    1    1                  
                                                                                  
               01          x    x    x    x        01         x    x    x    x      
          1                                                                         
               11          1    x    x    1        11         x    x    x    x   
                                                                                  
               10          1    x    x    1        10         x    x    x    x   

   o0:

          f1\f0                    0                                  1            
     
               p1p0\f3f2   00   01   11   10      p1p2\f3f2   00   01   11   10
                                                                                
               00          0    0    0    0        00         0    0    0    0                  
                                                                                  
               01          x    x    x    x        01         x    x    x    x      
          0                                                                         
               11          1    0    x    x        11         x    1    x    x  
                                                                                  
               10          1    0    x    x        10         x    1    x    x    

     
               p1p0\f3f2   00   01   11   10      p1p2\f3f2   00   01   11   10
                                                                                
               00          0    0    0    0        00         0    0    0    0                  
                                                                                  
               01          x    x    x    x        01         x    x    x    x      
          1                                                                         
               11          0    x    x    1        11         x    x    x    x   
                                                                                 
               10          0    x    x    1        10         x    x    x    x