sverx / devkitSMS

development kit and libraries for SEGA Master System / SEGA Game Gear / SEGA SG-1000 / SEGA SC-3000 homebrew programming using C language (and the SDCC compiler)
224 stars 34 forks source link

Use the A register explicitely with OR instruction #39

Closed raphnet closed 2 years ago

raphnet commented 2 years ago

"OR L" and "OR A, L" are equivalent, but when compiling with --peep-asm, the optimiser does not seem to know that OR L touches A, so it deems the "LD A,H" instruction preceding it useless and drops it.

i.e. with sdcc 4.2.8 #13663, the following:

ld hl,(_SMS_theFrameInterruptHandler) ld a,h or l

Becomes:

ld hl,(_SMS_theFrameInterruptHandler) or l

As the A register is often non-zero, the frame interrupt handler function ends up being called, even when _SMS_theFrameInterruptHandler is NULL.

sverx commented 2 years ago

Honestly I would avoid using --peep-asm completely - handwritten code can rarely be improved by it but more often it gets broken :disappointed: (for instance the optimizer doesn't know about time sensitive parts so it might end up making the code write to VRAM too fast for instance...)

raphnet commented 2 years ago

Ok, so should I also update the Makefile and the how to build this.txt file to remove the --peep-asm then?

sverx commented 2 years ago

yeah, it's probably the safest option. Thanks!

raphnet commented 2 years ago

Ok, the last commit also removes the --peep-asm option from the makefile and how to compile.txt file.