I want to write a program in which I can select a HEX file recorded on a SD card (via a LED screen, etc.) and run it, i.e. transfer control to it, like launching programs on a PC. Is this possible and if so, how? I only found ways to directly run a sketch from an SD card without that "program"
The HEX files on SD card would have to be linked for a specific address in flash. Normal program is linked for address zero on ATmega, but the bootloaders are an example on how to link for specific address in flash.
Then you could use the do_sdm() function provided by Optiboot 8 (see the example) to write the bytes from the HEX file to the right location in flash memory. Next step would be to call the start address as function same way as do_spm() is made accessible with optiboot.h in the example.
typedef void (*loaded_function_t)(); const loaded_function_t loaded_function = (loaded_function_t)(ADDRESS_OF_LOADED_FUNCTION);
then you can use
Serial.prinln("Execute the loaded code...); loaded_function(); Serial.prinln("Loaded code finished.");
Not with an Uno, no, it's not possible. Or it's very very hard and the results would be less than desirable. You need a proper MCU with lots of RAM and the ability to run code from it, which you can't with an Uno.
It would be less work to write your own scripting language to control things from a text file.