SlideShare a Scribd company logo
The Problem
Using C programming language write a program that simulates the Tiny Machine Architecture.
Your code must implement the basic instruction set that the Tiny Machine Architecture adheres
to (LOAD[1], ADD[2], STORE[3], SUB[4], IN[5], OUT[6], END[7], JMP[8], SKIPZ[9]). Each
piece of the architecture must be accurately represented in your code (Instruction Register,
Program Counter, Memory Address Register, Data Memory, Memory Data Register, and
Accumulator). Data Memory will be represented by a 0-9 array. Your Program Counter will
begin at 10.
For the sake of simplicity Program Memory and Data Memory may be implemented as separate
arrays.
Hint: Implementing a struct for your Instructions and an array of these structs as your Program
Memory greatly simplifies this program.
Example:
typedef struct {
int opCode, deviceOrAddress;
} Instruction;
Instruction programMemory[MAXPROGRAMSIZE];
Input Specifications
Your simulator must run from the command line with a single input file as a parameter to main.
This file will contain a sequence of instructions for your simulator to assemble (store in
“program memory”) and then run via the fetch/execute cycle.
Example:
5 5 //IN 5
6 7 //OUT 7
3 0 //STORE 0
5 5 //IN 5
6 7 //OUT 7
3 1 //STORE 1
1 0 //LOAD 0
4 1 //SUB 1
3 0 //STORE 0
6 7 //OUT 7
1 1 //LOAD 1
6 7 //OUT 7
7 0 //END
Output Specifications
Your simulator should provide output according to the input file. Along with this output your
program should provide status messages identifying details on the workings of your simulator.
Output text does not have to reflect my example word-for-word, but please provide detail on the
program as it runs in a readable format that does not conflict with the actual output of your
simulator. After each instruction print the current state of the Program Counter, Accumulator,
and Data Memory. The INPUT instruction is the only one that should prompt an interaction from
the user.
Example:
Assembling Program…
Program Assembled.
Run.
PC = 10 | A = NULL | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/* input value */
X
PC = 11 | A = X | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/* outputting accumulator to screen */
X
PC = 12 | A = X | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/* storing accumulator to memory location 0 */
PC = 13 | A = X | MEM = [X, 0, 0, 0, 0, 0, 0, 0, 0, 0]
… etc
Program complete.
Grading
Your simulator will be graded on the above criteria. Your program should compile and run from
the command line with one input file parameter. Please note that your program will not just be
graded on whether or not it runs successfully; accurate simulation and a thorough demonstration
of your understanding on the workings of this architecture will constitute a large portion of this
grade. As that is the case it is in your best interest to comment your program in a concise and
readable way. However, if your program does not run or compile the maximum points possible
will be 50 (up to 25 may be recovered by debugging and demonstrating an understanding of your
errors during TA’s office hours).
For instance, to implement FETCH and instruction LOAD you must implement each step:
FETCH
MAR ß PC
PC ß PC + 1
MDR ß M [MAR]
IR ß MDR
LOAD (Execute cycle)
MAR ß IR.ADDR */
MDR ß MEM[MAR] */
A ß MDR */
Note: Lecture 1 describes the instruction set architecture of the Tiny Machine.
Submission
Your program must be submitted as a C file. For example: NameMyProgram.c
Please check and double check your submission.
Solution
#include
#include
#include
#include
//Function used to count the amount of lines in text file
int getProgramSize();
//Function used to parse instruction into machine code
void toMachine();
//Global variable used to store the aforementioned
int MAXPROGRAMSIZE;
//Tiny Machine variables
int programCounter = 10;
int instructionRegister = 0;
int memoryAddressRegister = 0;
int dataMemory[9];
int memoryDataRegister = 0;
int accumulator = 0;
//Creating struct
typedef struct
{
int opCode;
int deviceOrAddress;
}Instruction;
int main(int argc, char *argv[])
{
//This is where we get the size of the program and define it
MAXPROGRAMSIZE = getProgramSize(fopen(argv[argc-1], "r"));
//This creates our struct array based on the amount of instructions
Instruction programMemory[MAXPROGRAMSIZE];
//Reading a file line by line
FILE *file = fopen(argv[argc-1], "r");
char fileBuffer[MAXPROGRAMSIZE];
int i = 0;
if (file == NULL)
{
printf("Error opening file!");
exit(0);
}
//Had to do some manipulation and checks here to make sure I only store the 1st and 3rd char
of every line
while(fgets(fileBuffer, sizeof(MAXPROGRAMSIZE), file)!=NULL)
{
if ((*fileBuffer == ' ' || *fileBuffer != ' ') && isdigit(*fileBuffer) && (int)fileBuffer[2]
!= 0)
{
programMemory[i].opCode = atoi(&fileBuffer[0]);
programMemory[i].deviceOrAddress = atoi(&fileBuffer[2]);
i += 1;
}
}
//Need to close the file
fclose(file);
//Just some text output
printf("  Otis Diaz --- CGS3269 ============================== Tiny Machine
Simulator ==============================  ");
printf("Assembling program...  ");
printf("Program assembled  ");
//Get the instruction from our struct and figure out what they mean by passing it into our
parser function
for (i=(programCounter/10)-1; i> Loading from address [%d]... << ", b);
instructionRegister = b;
memoryAddressRegister = instructionRegister;
memoryDataRegister = dataMemory[memoryAddressRegister];
accumulator = memoryDataRegister;
printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator);
for (i=0; i<9; i+=1)
{ printf("%d,", dataMemory[i]); }
printf("] ");
programCounter += 1;
break;
case 2:
//ADD
printf(" >> Adding accumulator and value obtain from address [%d]... << ", b);
instructionRegister = b;
memoryAddressRegister = instructionRegister;
memoryDataRegister = dataMemory[memoryAddressRegister];
accumulator += memoryDataRegister;
printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator);
for (i=0; i<9; i+=1)
{ printf("%d,", dataMemory[i]); }
printf("] ");
programCounter += 1;
break;
case 3:
//STORE
printf(" >> Storing accumulator value into memory... << ");
memoryDataRegister = accumulator;
instructionRegister = b;
memoryAddressRegister = instructionRegister;
dataMemory[memoryAddressRegister] = memoryDataRegister;
printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator);
for (i=0; i<9; i+=1)
{ printf("%d,", dataMemory[i]); }
printf("] ");
programCounter += 1;
break;
case 4:
//SUB
printf(" >> Subtracting memory address value [%d] from accumulator... << ", b);
instructionRegister = b;
memoryAddressRegister = instructionRegister;
memoryDataRegister = dataMemory[memoryAddressRegister];
accumulator -= memoryDataRegister;
printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator);
for (i=0; i<9; i+=1)
{ printf("%d,", dataMemory[i]); }
printf("] ");
programCounter += 1;
break;
case 5:
//GET INPUT
printf(" Please input a number: ");
scanf("%d", &accumulator);
printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator);
for (i=0; i<9; i+=1)
{ printf("%d,", dataMemory[i]); }
printf("] ");
programCounter += 1;
break;
case 6:
//OUTPUT TO SCREEN
printf(" >> Accumulator current value = %d << ", accumulator);
printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator);
for (i=0; i<9; i+=1)
{ printf("%d,", dataMemory[i]); }
printf("] ");
programCounter += 1;
break;
case 7:
//END PROGRAM
printf(" Program concluded... ");
exit(1);
case 8:
//JMP
// *Jump to address
printf(" >> Setting program counter to %d... << ", b);
programCounter = b;
printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator);
for (i=0; i<9; i+=1)
{ printf("%d,", dataMemory[i]); }
printf("] ");
break;
case 9:
//SKIPZ
// *Check if acc is 0, if it is skip next instruction, else proceed as normal
printf(" >> Skipping the next instruction... << ");
if (accumulator == 0)
{ programCounter += 2; }
else
{ programCounter += 1; }
printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator);
for (i=0; i<9; i+=1)
{ printf("%d,", dataMemory[i]); }
printf("] ");
break;
default:
printf(" There was an error parsing that opcode! Exiting program ");
exit(0);
}
}
int getProgramSize(FILE *file)
{
char fileBuffer[100];
int length = 0;
if (file == NULL)
{
printf("Error opening file!");
exit(0);
}
//This is where I kinda have to buck down and choose an arbitrary number... 1000 might be
overkill but w/e
while(fgets(fileBuffer, 1000 ,file)!=NULL)
{ length += 1; }
fclose(file);
return length;
}

More Related Content

PPTX
C Homework Help
PPT
EMBEDDED SYSTEMS 4&5
PPTX
C Exam Help
PPTX
Home works summary.pptx
PDF
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
PDF
Taller practico emu8086_galarraga
PPTX
UNIT 3 - General Purpose Processors
PDF
CS520 Computer Architecture Project 2 � Spring 2023 Due date 0326.pdf
C Homework Help
EMBEDDED SYSTEMS 4&5
C Exam Help
Home works summary.pptx
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
Taller practico emu8086_galarraga
UNIT 3 - General Purpose Processors
CS520 Computer Architecture Project 2 � Spring 2023 Due date 0326.pdf

Similar to The ProblemUsing C programming language write a program that simul.pdf (20)

PPTX
Computer arch
PDF
mca is a microcontroller and accmulator is a third year couse
PPT
8085_Microprocessor(simar).ppt
PPT
Register Transfer Language and Micro Operations
PDF
02 isa
PPT
Lect05 Prog Model
PPTX
Basic computer organization design
PPTX
1st unit - microcontroller architechture and pin diagram
PDF
Microprocessor 8086-lab-mannual
RTF
Microprocessor File
PPT
intro.ppt
PPT
Chapter Eight(3)
PPTX
CH-3 CO-all-about-operating-system(Update).pptx
PPT
C Language Unit-1
PPT
Unit1 jwfiles
PDF
Lenguaje ensamblador EMU8086
PPT
Microprocessor system - summarize
PPT
8051assembly language
PDF
8051 microcontroller
PPTX
Intro (lesson1)comp arch
Computer arch
mca is a microcontroller and accmulator is a third year couse
8085_Microprocessor(simar).ppt
Register Transfer Language and Micro Operations
02 isa
Lect05 Prog Model
Basic computer organization design
1st unit - microcontroller architechture and pin diagram
Microprocessor 8086-lab-mannual
Microprocessor File
intro.ppt
Chapter Eight(3)
CH-3 CO-all-about-operating-system(Update).pptx
C Language Unit-1
Unit1 jwfiles
Lenguaje ensamblador EMU8086
Microprocessor system - summarize
8051assembly language
8051 microcontroller
Intro (lesson1)comp arch
Ad

More from federaleyecare (20)

PDF
A ISCSI SAN consists of Select one or more A. HBA B. LUN C. Fibr.pdf
PDF
Which of the following statements about tRNA molecules is TRUEMul.pdf
PDF
Write a C program to simulate the description below using semaphores.pdf
PDF
When analyzing any particular primary source, historians must consid.pdf
PDF
What is Linux SecuritySolutionLinux Security is a module in.pdf
PDF
What is the runtime complexity of Adams famous string splitter cod.pdf
PDF
What does personalized learning mean to you What does personal.pdf
PDF
What do patients in healthcare expect from their insurance company.pdf
PDF
Use Table A to find the number z such that the proportion of observa.pdf
PDF
Two of the main political systems are democracy and totalitarianism..pdf
PDF
The procedure of transferring journal entries to the ledger accounts .pdf
PDF
5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf
PDF
QUESTION 7 When using the indirect method to prepare the statement of.pdf
PDF
Q.1. Define noncontrolling (minority) interest. List three methods th.pdf
PDF
Picking a fruit-flavored or primary colored bean. overlapping event .pdf
PDF
Part F - Viral Evolution and LysogenyOne hypothesis regarding the .pdf
PDF
Match the following Data vs Information Reliability as it adds value .pdf
PDF
Many organizations invest substantial resources in creating their ow.pdf
PDF
Lets compare and contrast the national cultures of Egypt and Brazi.pdf
PDF
Great alveolar (type II) cells of the alveoli secrete a _______ t.pdf
A ISCSI SAN consists of Select one or more A. HBA B. LUN C. Fibr.pdf
Which of the following statements about tRNA molecules is TRUEMul.pdf
Write a C program to simulate the description below using semaphores.pdf
When analyzing any particular primary source, historians must consid.pdf
What is Linux SecuritySolutionLinux Security is a module in.pdf
What is the runtime complexity of Adams famous string splitter cod.pdf
What does personalized learning mean to you What does personal.pdf
What do patients in healthcare expect from their insurance company.pdf
Use Table A to find the number z such that the proportion of observa.pdf
Two of the main political systems are democracy and totalitarianism..pdf
The procedure of transferring journal entries to the ledger accounts .pdf
5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf
QUESTION 7 When using the indirect method to prepare the statement of.pdf
Q.1. Define noncontrolling (minority) interest. List three methods th.pdf
Picking a fruit-flavored or primary colored bean. overlapping event .pdf
Part F - Viral Evolution and LysogenyOne hypothesis regarding the .pdf
Match the following Data vs Information Reliability as it adds value .pdf
Many organizations invest substantial resources in creating their ow.pdf
Lets compare and contrast the national cultures of Egypt and Brazi.pdf
Great alveolar (type II) cells of the alveoli secrete a _______ t.pdf
Ad

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Insiders guide to clinical Medicine.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
PDF
Computing-Curriculum for Schools in Ghana
PPTX
master seminar digital applications in india
PPTX
Cell Structure & Organelles in detailed.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Supply Chain Operations Speaking Notes -ICLT Program
Classroom Observation Tools for Teachers
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Anesthesia in Laparoscopic Surgery in India
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Renaissance Architecture: A Journey from Faith to Humanism
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Sports Quiz easy sports quiz sports quiz
Abdominal Access Techniques with Prof. Dr. R K Mishra
Insiders guide to clinical Medicine.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning
Computing-Curriculum for Schools in Ghana
master seminar digital applications in india
Cell Structure & Organelles in detailed.
Final Presentation General Medicine 03-08-2024.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
102 student loan defaulters named and shamed – Is someone you know on the list?
PPH.pptx obstetrics and gynecology in nursing
Supply Chain Operations Speaking Notes -ICLT Program

The ProblemUsing C programming language write a program that simul.pdf

  • 1. The Problem Using C programming language write a program that simulates the Tiny Machine Architecture. Your code must implement the basic instruction set that the Tiny Machine Architecture adheres to (LOAD[1], ADD[2], STORE[3], SUB[4], IN[5], OUT[6], END[7], JMP[8], SKIPZ[9]). Each piece of the architecture must be accurately represented in your code (Instruction Register, Program Counter, Memory Address Register, Data Memory, Memory Data Register, and Accumulator). Data Memory will be represented by a 0-9 array. Your Program Counter will begin at 10. For the sake of simplicity Program Memory and Data Memory may be implemented as separate arrays. Hint: Implementing a struct for your Instructions and an array of these structs as your Program Memory greatly simplifies this program. Example: typedef struct { int opCode, deviceOrAddress; } Instruction; Instruction programMemory[MAXPROGRAMSIZE]; Input Specifications Your simulator must run from the command line with a single input file as a parameter to main. This file will contain a sequence of instructions for your simulator to assemble (store in “program memory”) and then run via the fetch/execute cycle. Example: 5 5 //IN 5 6 7 //OUT 7 3 0 //STORE 0 5 5 //IN 5 6 7 //OUT 7 3 1 //STORE 1 1 0 //LOAD 0 4 1 //SUB 1 3 0 //STORE 0 6 7 //OUT 7 1 1 //LOAD 1
  • 2. 6 7 //OUT 7 7 0 //END Output Specifications Your simulator should provide output according to the input file. Along with this output your program should provide status messages identifying details on the workings of your simulator. Output text does not have to reflect my example word-for-word, but please provide detail on the program as it runs in a readable format that does not conflict with the actual output of your simulator. After each instruction print the current state of the Program Counter, Accumulator, and Data Memory. The INPUT instruction is the only one that should prompt an interaction from the user. Example: Assembling Program… Program Assembled. Run. PC = 10 | A = NULL | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] /* input value */ X PC = 11 | A = X | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] /* outputting accumulator to screen */ X PC = 12 | A = X | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] /* storing accumulator to memory location 0 */ PC = 13 | A = X | MEM = [X, 0, 0, 0, 0, 0, 0, 0, 0, 0] … etc Program complete. Grading Your simulator will be graded on the above criteria. Your program should compile and run from the command line with one input file parameter. Please note that your program will not just be graded on whether or not it runs successfully; accurate simulation and a thorough demonstration of your understanding on the workings of this architecture will constitute a large portion of this grade. As that is the case it is in your best interest to comment your program in a concise and readable way. However, if your program does not run or compile the maximum points possible
  • 3. will be 50 (up to 25 may be recovered by debugging and demonstrating an understanding of your errors during TA’s office hours). For instance, to implement FETCH and instruction LOAD you must implement each step: FETCH MAR ß PC PC ß PC + 1 MDR ß M [MAR] IR ß MDR LOAD (Execute cycle) MAR ß IR.ADDR */ MDR ß MEM[MAR] */ A ß MDR */ Note: Lecture 1 describes the instruction set architecture of the Tiny Machine. Submission Your program must be submitted as a C file. For example: NameMyProgram.c Please check and double check your submission. Solution #include #include #include #include //Function used to count the amount of lines in text file int getProgramSize(); //Function used to parse instruction into machine code void toMachine(); //Global variable used to store the aforementioned int MAXPROGRAMSIZE; //Tiny Machine variables int programCounter = 10; int instructionRegister = 0; int memoryAddressRegister = 0; int dataMemory[9];
  • 4. int memoryDataRegister = 0; int accumulator = 0; //Creating struct typedef struct { int opCode; int deviceOrAddress; }Instruction; int main(int argc, char *argv[]) { //This is where we get the size of the program and define it MAXPROGRAMSIZE = getProgramSize(fopen(argv[argc-1], "r")); //This creates our struct array based on the amount of instructions Instruction programMemory[MAXPROGRAMSIZE]; //Reading a file line by line FILE *file = fopen(argv[argc-1], "r"); char fileBuffer[MAXPROGRAMSIZE]; int i = 0; if (file == NULL) { printf("Error opening file!"); exit(0); } //Had to do some manipulation and checks here to make sure I only store the 1st and 3rd char of every line while(fgets(fileBuffer, sizeof(MAXPROGRAMSIZE), file)!=NULL) { if ((*fileBuffer == ' ' || *fileBuffer != ' ') && isdigit(*fileBuffer) && (int)fileBuffer[2] != 0) { programMemory[i].opCode = atoi(&fileBuffer[0]); programMemory[i].deviceOrAddress = atoi(&fileBuffer[2]); i += 1; } } //Need to close the file
  • 5. fclose(file); //Just some text output printf(" Otis Diaz --- CGS3269 ============================== Tiny Machine Simulator ============================== "); printf("Assembling program... "); printf("Program assembled "); //Get the instruction from our struct and figure out what they mean by passing it into our parser function for (i=(programCounter/10)-1; i> Loading from address [%d]... << ", b); instructionRegister = b; memoryAddressRegister = instructionRegister; memoryDataRegister = dataMemory[memoryAddressRegister]; accumulator = memoryDataRegister; printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator); for (i=0; i<9; i+=1) { printf("%d,", dataMemory[i]); } printf("] "); programCounter += 1; break; case 2: //ADD printf(" >> Adding accumulator and value obtain from address [%d]... << ", b); instructionRegister = b; memoryAddressRegister = instructionRegister; memoryDataRegister = dataMemory[memoryAddressRegister]; accumulator += memoryDataRegister; printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator); for (i=0; i<9; i+=1) { printf("%d,", dataMemory[i]); } printf("] "); programCounter += 1; break; case 3: //STORE printf(" >> Storing accumulator value into memory... << "); memoryDataRegister = accumulator;
  • 6. instructionRegister = b; memoryAddressRegister = instructionRegister; dataMemory[memoryAddressRegister] = memoryDataRegister; printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator); for (i=0; i<9; i+=1) { printf("%d,", dataMemory[i]); } printf("] "); programCounter += 1; break; case 4: //SUB printf(" >> Subtracting memory address value [%d] from accumulator... << ", b); instructionRegister = b; memoryAddressRegister = instructionRegister; memoryDataRegister = dataMemory[memoryAddressRegister]; accumulator -= memoryDataRegister; printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator); for (i=0; i<9; i+=1) { printf("%d,", dataMemory[i]); } printf("] "); programCounter += 1; break; case 5: //GET INPUT printf(" Please input a number: "); scanf("%d", &accumulator); printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator); for (i=0; i<9; i+=1) { printf("%d,", dataMemory[i]); } printf("] "); programCounter += 1; break; case 6: //OUTPUT TO SCREEN printf(" >> Accumulator current value = %d << ", accumulator); printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator);
  • 7. for (i=0; i<9; i+=1) { printf("%d,", dataMemory[i]); } printf("] "); programCounter += 1; break; case 7: //END PROGRAM printf(" Program concluded... "); exit(1); case 8: //JMP // *Jump to address printf(" >> Setting program counter to %d... << ", b); programCounter = b; printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator); for (i=0; i<9; i+=1) { printf("%d,", dataMemory[i]); } printf("] "); break; case 9: //SKIPZ // *Check if acc is 0, if it is skip next instruction, else proceed as normal printf(" >> Skipping the next instruction... << "); if (accumulator == 0) { programCounter += 2; } else { programCounter += 1; } printf(" PC: %d | A: %d | MEM: [", programCounter, accumulator); for (i=0; i<9; i+=1) { printf("%d,", dataMemory[i]); } printf("] "); break; default: printf(" There was an error parsing that opcode! Exiting program "); exit(0); }
  • 8. } int getProgramSize(FILE *file) { char fileBuffer[100]; int length = 0; if (file == NULL) { printf("Error opening file!"); exit(0); } //This is where I kinda have to buck down and choose an arbitrary number... 1000 might be overkill but w/e while(fgets(fileBuffer, 1000 ,file)!=NULL) { length += 1; } fclose(file); return length; }