I'm wanting to read hex numbers from a text file into an unsigned integer so that I can execute Machine instructions. It's just a simulation type thing that looks inside the text file and according to the values and its corresponding instruction outputs the new values in the registers.
For example, the instructions would be:
- 1RXY -> Save register R with value in memory address XY
- 2RXY -> Save register R with value XY
- BRXY -> Jump to register R if xy is this and that etc..
- ARXY -> AND register R with value at memory address XY
The text file contains something like this each in a new line. (in hexidecimal)
- 120F
- B007
- 290B
My problem is copying each individual instruction into an unsigned integer...how do I do this?
#include <stdio.h>
int main(){
FILE *f;
unsigned int num[80];
f=fopen("values.txt","r");
if (f==NULL){
printf("file doesnt exist?!");
}
int i=0;
while (fscanf(f,"%x",num[i]) != EOF){
fscanf(f,"%x",num[i]);
i++;
}
fclose(f);
printf("%x",num[0]);
}