At the moment the only program the simulator can execute is statically defined as Program array during compilation. It would be great to be able to load external programs from files. That would add a lot of flexibility to the simulator.
Steps required:
Add a new option to argc, argv parsing for optional file name, like ./switched 1000 file.raw
If the option is present, the file contents is loaded to the program memory as-is starting from address 0x0
If no option is present, the default program is used
Proper error checking should be implemented:
If the file cannot be read (missing/no permissions), an error is reported
If the file is shorter than memory length, the rest of it should be padded with zeroes
If file is too big (contains more words than program memory should hold), an error or at least a warning should be produced. At no circumstances buffer overflow may happen.
(optional) If file contains instructions that are not valid for the processor, a warning (not error) should be produced
A test should be prepared that showcases the new functionality with at least one external file with some sort of a valid program.
The file loading functionality is generic, i.e., it does not depend on used interpreter mode, so it can/should be done for all variants of the interpreter/translator
At the moment the only program the simulator can execute is statically defined as
Program
array during compilation. It would be great to be able to load external programs from files. That would add a lot of flexibility to the simulator.Steps required:
argc, argv
parsing for optional file name, like./switched 1000 file.raw
The file loading functionality is generic, i.e., it does not depend on used interpreter mode, so it can/should be done for all variants of the interpreter/translator