mikeakohn / naken_asm

Assembler for MSP430, dsPIC, ARM, MIPS, 65xx, 68000, 8051/8052, Atmel AVR8, and others.
http://www.mikekohn.net/micro/naken_asm.php
GNU General Public License v3.0
290 stars 49 forks source link

8051 improve/optimize to try acall/ajmp before direct assembly to lcall/ljmp #93

Open wenij opened 3 years ago

wenij commented 3 years ago

some assembler (AS31) will try using acall/ajmp (even coding it as lcall/ljmp), because it can save 1 bytes. Can naken_asm(8051) have possible to optimize it like this way?

mikeakohn commented 3 years ago

Sorry for a slow reply. This could be done, but this requires a possibly ugly change to the code since branching forward to a label that hasn't been defined yet would force it to fall back on the bigger instruction.

pulkomandy commented 2 years ago

Hello, I have a similar problem on unsp. The conditional jump instructions have only a 6-bit range, which is often not enough. The solution is to combine them with a goto instruction, so that:

JE label

Becomes:

JNE $+2
GOTO label

It's a bit annoying to decide when this long form must be used (especially because I'm porting a C compiler and the compiler doesn't currently know about instruction sizes to make the decision)

Could this be handled by the optimizer?

mikeakohn commented 2 years ago

I have the same issue working with Java Grinder also... although I have a "hint" distance in since it's translating from Java byte code.

It might be possible to do this, but it would take some work and would need to be done carefully since the assembler supports multiple platforms.