コード例 #1
0
int startVM() {
    fillCode( "mcode.txt" );
    
    FILE* file = fopen("stacktrace.txt","w");
    
    if ( file == NULL) {
        printf("Could not open file\n");
        exit(1);
    }

    printCode( file );
    
    fprintf(file, "Line  OP  L  M  pc  bp  sp     stack    \n");
    fprintf(file, "----------------------------------------\n");
    fprintf(file, "Init Values:    0   1   0               \n");
    
    /*instruction cycle*/

    //while instruction is not halt
    while ( halt == 0) {
        fetch();
        execute();
        printInstructionTrace(file);
    }
    
    fclose( file );
    return 0;
}
コード例 #2
0
int main(int argc, const char * argv[]) {
    
    FILE *file = fopen("mcode.txt", "r" );
    
//   stack_str = malloc((MAX_STACK_HEIGHT + 100) * sizeof(char));
    
    /* fopen returns 0, the NULL pointer, on failure */
    if ( file == 0 )
    {
        printf( "Could not open file\n" );
        exit(1);
    }

    fillCode( file );
    fclose( file );
    
    file = fopen("stacktrace.txt","w");
    
    if ( file == NULL) {
        printf("Could not open file\n");
        exit(1);
    }
    
    printCode( file );
    
    fprintf(file, "Line  OP  L  M  pc  bp  sp     stack    \n");
    fprintf(file, "----------------------------------------\n");
    fprintf(file, "Init Values:    0   1   0               \n");
    
    /*instruction cycle*/
    
    //while instruction is not halt
    while ( halt == 0) {
        fetch();
        execute();
        printInstructionTrace(file);
    }
    
    fclose( file );
}