Simpletron help!

This is a discussion on Simpletron help! within the C Programming forums, part of the General Programming Boards category; i wrote this simpletron code: Code: #include<stdio.h> /**/ #define SIZE 100 #define READ 10 #define WRITE 11 #define LOAD 20 ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    27

    Simpletron help!

    i wrote this simpletron code:

    Code:
    #include<stdio.h>
    
    
    /**/
    #define SIZE 100
    #define READ 10
    #define WRITE 11
    #define LOAD 20 
    #define STORE 21
    #define ADD 30
    #define HALT 43
    /*****************/
    
    
    void inputArry( int * );
    void operate( int *, int *, int *, 
                 int *, int *, int * );
    void printArray( int *, int, int, int, int, int );
    
    
    /* START "main" */
    int main()
    {
        int memory[ SIZE ] = { 0 };
        int opC = 0, oper = 0;
        int acc = 0, instReg = 0;
        int instC = 0;
    
    
        printf( "\t--SIMPLETRON SIMULATION--\n\n\n" );
    
    
        printf( "*******************************************\n" );
        printf( "**      Welcome To SIMPLETRON!           **\n" );
        printf( "** Simulator will type memory location   **\n" );
        printf( "** along with \"?\", you then type         **\n" );
        printf( "** instruction. Enter -99999 to stop     **\n" );
        printf( "** entering instructions. Enter your     **\n" );
        printf( "** instructions between -99999 and 99999.**\n" );
        printf( "*******************************************\n\n\n" );
    
    
        inputArry( memory );
        operate( memory, &instReg, &opC, &oper, &acc, &instC );
    
    
        printf( "\n\n" );
    
    
        printArray( memory, acc, instC, instReg, opC, oper );
    
    
        printf( "\n\n" );
    
    
        return 0;
    }   
    /* END    "main" */
    
    
    /* START "inputArray" */
    void inputArry( int *memoryPtr )
    {
        long int inst;
        int i = 0;
    
    
        printf( "00 ? " );
        scanf( "%ld", &inst );
    
    
        while( inst != -99999 )
        {
            if( !(inst >= -99999 && inst <= 99999) )
            {
                printf( "Invalid number!!\nEnter Again!\n\n" );
            }
            else
            {
                memoryPtr[ i ] = inst;
    
    
                i++;
            }
    
    
            printf( "%02d ? ", i );
            scanf( "%ld", &inst );
        }
    }
    /* END "inputArray" */
    
    
    /* START "operate" */
    void operate( int *memoryPtr, int *instRegPtr, int *opCPtr, int *operPtr, int *accPtr, int *instCPtr )
    {
        int a;
    
    
        printf( "\t--START SIMPLETRON SIMULATION--\n\n\n" );
    
    
        *instRegPtr = memoryPtr[ *instCPtr ];
    
    
        *opCPtr = *instRegPtr / 100;
        *operPtr = *instRegPtr % 100;
    
    
        while( *opCPtr != HALT )
        {
            if( !(*instRegPtr == -99999) )
            {
                break;
            }
    
    
            switch( *opCPtr )
            {
    
    
            case READ:
                {
                    printf( "Enter Integer: " );
                    scanf( "%d", &a );
    
    
                    memoryPtr[ *operPtr ] = a;
    
    
                    ( *instCPtr )++;
    
    
                    break;
                }
    
    
            case WRITE:
                {
                    printf( "Index number %d has = %d\n\n", *operPtr, memoryPtr[ *operPtr ] );
    
    
                    ( *instCPtr )++;
    
    
                    break;
                }
    
    
            case LOAD:
                {
                    *accPtr = memoryPtr[ *operPtr ];
    
    
                    ( *instCPtr )++;
    
    
                    break;
                }
    
    
            case STORE:
                {
                    memoryPtr[ *operPtr ] = *accPtr;
    
    
                    ( *instCPtr )++;
    
    
                    break;
                }
    
    
            case ADD:
                {
                    *accPtr = a + memoryPtr[ *operPtr ];
    
    
                    ( *instCPtr )++;
    
    
                    break;
                }
            } 
            /* End Switch */
    
    
            *instRegPtr = memoryPtr[ *instCPtr ];
    
    
            *opCPtr = *instRegPtr / 100;
            *operPtr = *instRegPtr % 100;
    
    
        }
        /* End While */
    
    
        printf( "\t--END SIMPLETRON SIMULATION  --\n\n\n" );
    } 
    /* END "operate" */
    
    
    /* START "printArray" */
    void printArray( int *memoryPtr, int accumulator,
                    int instCounter, int instRegister,
                    int operationCode, int operand )
    {
        int i;
    
    
        printf( "accumulator         \t %+05d\n", accumulator );
        printf( "instructionCounter  \t %5d\n", instCounter );
        printf( "instructionRegister \t %+05d\n", instRegister );
        printf( "operationCode       \t %5d\n", operationCode );
        printf( "operand             \t %5d\n\n\n\n", operand );
    
    
        for( i = 0; i <= 9 ; i++ )
        {
            printf( " %5d ", i );
        }
    
    
        for( i = 0; i < SIZE; i++ )
        {
    
    
            if( i % 10 == 0 )
            {
                printf( "\n\n%2d", i );
            }
    
    
            printf( " %+05d ", memoryPtr[ i ] );
        }
    }
    /* END "printArray" */
    the problem is that it doesnt print the READ case, there are also some more problems, i suggest please compile
    please HELP me, i really need help on this
    please
    i will be very thankful!

    i am very sorry for long code

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    9
    Code:
    define READ 10
    change to 10 to 0


    EDIT dont't do this actually!!
    Last edited by tetartos; 11-27-2011 at 07:17 AM.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    27

    Talking

    Quote Originally Posted by tetartos View Post
    Code:
    define READ 10
    change to 10 to 0


    EDIT dont't do this actually!!

    come on man its a matter of life and death for me

    anyway i solved it

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,300
    Quote Originally Posted by ahmedbatty View Post
    the problem is that it doesnt print the READ case, there are also some more problems, i suggest please compile
    No! I will not be compiling any code people post here. It's your job to post the error messages that you are getting. I can then spot your bug just by looking at the code.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simpletron problem!
    By ahmedbatty in forum C Programming
    Replies: 1
    Last Post: 11-27-2011, 03:37 AM
  2. Simpletron! Simulator
    By cyberCLoWn in forum Tech Board
    Replies: 0
    Last Post: 02-29-2004, 01:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21