Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
struct VarData{
unsigned long var;
};
int main()
{
FILE * mFile;
struct VarData data;
mFile = fopen ("b3-long-sample.bin" , "rb");
if (mFile == NULL) { /* If there was a problem, show the error */
perror ("Error opening file");
}
else {
while( !feof( mFile ) ) {
fread( &data, sizeof( struct VarData ), 1, mFile);
printf("The address: %08lx\n", &data);
printf("The word: %08lx\n", data.var);
}
}
return 0;
}
this is the attempt i made so far.
im wondering if this is right.
supposedly i have to read a .bin file.
i have to make sure tt the length is in a multiple of 4 bytes. and store each four byte into a unsigned long variable and print the variable in hexa.
i would use the fopen to read the file in binary .
however im having problems trying to read the file in four 'bytes'...
how am i suppose to break the file into bytes?
also the address is the same for each word ...
but i have to print the address before each instruction is loaded into.
ive noted tt the MIPS text segment begins at 0x00400000.
but i have can't seems to acheive that.
can some1 tell me what the problem is ?
thanks