2 qq 32123899 qq_32123899 于 2016.04.11 08:27 提问

求助大神c程序的verilog写法 5C

将下列c程序改为verilog程序
#include
#include

int f0(int, int, int);
int f1(int, int, int);
int f2(int, int, int);
int f3(int, int, int);

int main(int argc, char ** argv)
{
unsigned int s[5]={0X12345678,0X23456789,0X3456789A,0X456789AB,0X56789ABC};
unsigned int h[4]={0X11223344,0X22334455,0X33445566,0X44556677};
unsigned int M[48];
unsigned int z,i;
unsigned int a, b, c, d, e;
unsigned int U;
FILE *source, *result;

/* for(z=0;z<8;z++)
{
printf("%d\n", z);
scanf("%x",&M[z]);
}
*/
if(argc != 3){
printf("Usage: rng source_file result_file.\n");
return 1;
}

if((source = fopen(argv[1], "rb")) == NULL){
    printf("Error! Can't open %s for read. \n", argv[1]);
    return 1;
}

if((result = fopen(argv[2], "wb")) == NULL){
    printf("Error! Can't open %s for write. \n", argv[2]);
    return 1;
}   

while(!feof(source)){

    for(z=0;z<8;z++)
    {
        fscanf(source, "%x", &M[z]);
        printf("Data readed is %08X\n", M[z]);
        //fread(&M[z], sizeof(unsigned int), 1, source); 
    }

    for(z=8;z<48;z++)
    {
        M[z]=((M[z-1]^M[z-2]^M[z-5]^M[z-8])<<1)|((M[z-1]^M[z-2]^M[z-5]^M[z-8])>>31);
        printf("M[%d] is %08X \n", z, M[z]);
    }

    a = h[0];
    b = h[1];
    c = h[2];
    d = h[3];

    for(z=0;z<48;z++)
    {
        e = (c<<3)|(c>>29);

        switch(z%4){
            case 0:
                U = f0(a,b,e)+d+M[z]+s[z%5];
                break;     
            case 1:            
                U = f1(a,b,e)+d+M[z]+s[z%5];
                break;     
            case 2:            
                U = f2(a,b,e)+d+M[z]+s[z%5];
                break;     
            case 3:            
                U = f3(a,b,e)+d+M[z]+s[z%5];
                break;
            default:
                printf("Error!\n");
                return 1;
        }

        d = c;
        c = b;
        b = (a<<23)|(a>>9);
        a = U;

        //if(z == 46){
            printf("z=%d : ", z);
            printf("%08X", d);
            printf("%08X", c);
            printf("%08X", b);
            printf("%08X", a);
            printf("\n");
        //}

    }

    h[0] = h[0]+a; 
    h[1] = h[1]+b; 
    h[2] = h[2]+c; 
    h[3] = h[3]+d; 

    for(z=0;z<4;z++)
    {
        printf("%08X", h[z]);
    }
    printf("\n");

    printf("%08X", d);
    printf("%08X", c);
    printf("%08X", b);
    printf("%08X", a);
    printf("\n");

    for(z=0;z<4;z++)
    {
        fprintf(result, "%08X\n", h[z]);
    }
    printf("\n");

    //printf("s4 is %X\n", s[4]^s[0]);
    //printf("s4 is %X\n", ((s[4]<<1)|(s[4]>>31)));

}   //while

fclose(source);
fclose(result);

return 0;

}

int f0(int a , int b, int c)
{
return a^b^c;

}

int f1(int a , int b, int c)
{
return (a&b)|(~a&c);

}

int f2(int a , int b, int c)
{
return a^(b|~c);

}

int f3(int a , int b, int c)
{
return (a&b)|(b&c)|(c&a);

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!