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