{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

assign4.c - *Name Arria P Owlia*EID apo223*Section...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 /****************************************************************************** *Name:Arria P. Owlia *EID:apo223 *Section #:15735 *Assignment#:4 *Purpose:To become familiar with IO streams and strings with the DecMack *******************************************************************************/ #include <stdio.h> #define EXIT_FAILURE 1 #define input_file "interpreter.txt" clearAll(int RAM[1000], int REG[10])/*Clears all values in RAM and Registers*/ { int Count = 0 for (Count = 0 REG[Count] = 0 for (Count = 0 RAM[Count] = 0 } int main(void) { int REG[10] = {0}, output[1000][11] = {0}, counter[1000][10] = {0}, RAM[1000]={0} int i = 0, n = 0, j = 0, k = 0, X = 1, PC = 0, Count = 0 int opcode = 0, destination = 0, source = 0, address = 0, halt = 0, number = 0, temp = 0, value = 0 char s[6] FILE *fp = fopen(input_file, "r") if (fp == NULL)/*If fp is NULL, exit with EXIT_FAILURE as the return value*/ { printf("unable to open %s\n", input_file) getchar() exit(EXIT_FAILURE) } fgets(s,5,fp) n = atoi(s) fgets(s,5,fp) printf("Input:\n%d\n\n", n) for (j=0 { i = 0 do { fgets(s,5,fp) printf("%s", s) p RAM[i] = atoi(s) i++
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Sheet1 Page 2 } while (s[0] != '\n' && !feof(fp)) } k = i k for (i = 0 { if (RAM[i] >= 100)/*Sets variables to correct values for each instruction read*/ { opcode = RAM[i]/100 destination = (RAM[i]%100)/10 number = RAM[i]%10 source = RAM[i]%10 address = RAM[i]%10 }
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}