As mentioned in [bugs:#3978], it looks more like a problem of the loop optimization. If the loop optimization can't be fixed easily and you want to revert this change, then I guess this optimization could also be done in the mcs51 backend when expanding/emitting the multiplication operation? (by looking at the operands)
Please elaborate
Nice, thanks!
@spth I've looked at your change once more I looked into rules 112.c, 108.f and 108.g. While they were useful, I think I came up with a more general solution that requires fewer rules in [r15431]. Please have a look. Interestingly, it misses some cases like: my original patterns (do ljmp -> sjmp after conditional jumps) mov dptr,#(_g_state + 0x0001) movx a,@dptr anl a,#0x03 jz 00219$ ... ... 00219$: ret ----------------------------- your patterns (do ljmp -> sjmp first) mov dptr,#(_g_state + 0x0001)...
mcs51: add banked jump
What about using a label on the seljump which is after main? Please see the attached patch.
As it turns out, my idea to use something like #((___str_0 >> 16) + 0x80) for the high byte doesn't work. Although it compiles and assembles and links fine, it silently outputs #0x00 in the final code. This is should be probably also fixed in the assembler/linker. Funnily, turning around the expression seems to work fine #((___str_0 + 0x800000) >> 16) . So use that for now. Updated patch
What about using a label on the seljump which is after main? uCsim can get address of the label from the cdb (or map) file and automatically break at that address and pass out return value produced by sim_stop_result(). Yes, that sounds good!