groepaz wrote: ↑Wed Apr 17, 2024 8:49 am
I would love if someone made a small assembler like ASM502 for the ARM, targeting the pi, android, Arduino, blue pill etc, so you didn't have to run an SDK full of bugs taking a gigabyte or more..
Just build GAS for ARM? For all those modern CPUs it really doesn't make a lot of sense to make a custom assembler - GAS will support them anyway
Fair enough I suppose. I never really got on with GAS on x86, and used NASM instead. The SDK on the blue-pill/arduino is really annoying - the tool for uploading the binaries is just a few K, yet the SDK is enormous, slow and buggy..
As for optimisations, C compiler etc - yes its really the job of the high level language although an assembler could do some of it. It would have to be possible to tell the asm not to optimise in certain places with a macro directive. A high level language is the best place for it because it has far more information - the scope of code and variables, the location of loop end points etc.
Back when writing ASM502 I was looking at Small-C, etc - in the end I started writing my own C compiler (x86, but intending to end up 6502). it is (of course) not complete. If I recall, when experimenting, the Small-C type compilers often seem to convert byte-arithmetic to 16 bits (via virtual ZP registers) for work, converting back to BYTE at the end - which is very inefficient.
Recognising the "static" keyword properly for both vars and subroutines can help - since we would not then need to push everything onto the emulated stack, which is slow on the 6502. I did also think of having one true BYTE register variable available - mapping to X reg. A lot more use of ZP for secondary register vars could help - cc65 didnt seem to use so many as are available if one just uses all of BASIC var space.
I did start thinking in terms of pattern recognition within the intemediate code, so for example
#define VDU 0x1e00 /* C64 0x0400 etc */
void showcharset ()
{
register BYTE x;
x=0;
do {
*(VDU+x) = x;
x++;
} while (x);
}
the compiler could pick out the larger pattern and generate..
VDU = $1e00
showcharset:
ldx # 0
loop01:
txa
sta VDU,x
inx
bne loop01
rts
Of course thinking it and actually doing it are very different things!