Page 1 of 1

Assembler alternatives

Posted: Sun 08 Apr 2018, 10:08
by guest
Whilst the integral assembler is an important (and unique) feature of BBC BASIC, it has to be admitted that its usefulness in a cross-platform context is limited. Not only might you have to write (and test) four different versions of assembler code - 32-bit and 64-bit x86, 32-bit and 64-bit ARM - the restrictions imposed by Apple on what you are allowed to do in iOS mean the assembler cannot be used at all in that edition!

So when writing code targetted to multiple platforms it is easier and safer to avoid assembly language code altogether. This means finding some alternative, and there are not many options. The most obvious one is to use BASIC code but of course there is likely to be a big performance hit. However CPU speeds have increased enormously in the 37-odd years since BBC BASIC was first devised and things which could only be done in assembly language then can often be done at an acceptable speed in interpreted BASIC now. It is sometimes possible to optimise the BASIC code (perhaps with the help of a profiler) to squeeze a bit more performance, and if you're really lucky you may be able to leverage features such as BBC BASIC's array arithmetic to gain a large benefit.

If BASIC code cannot achieve the required performance, another thing to consider is whether any Operating System functions (callable with SYS) can help. In the various editions of BBCSDL you have access to most of the Simple DirectMedia Layer (SDL) API functions and also to most of the C Run Time (CRT) API functions. For example suppose you need to copy a block of memory from one place to another very quickly; whilst your first thought might be a simple assembly language loop, using SYS "memcpy" may well be an alternative (it might even be faster).

If none of these solutions is suitable, you may have to bite the bullet and write assembler code for all the platforms you want to target (and accept that you cannot support iOS). But in that case I'd be interested to learn what it is you need to do in case I can think of a solution that hasn't occurred to you. In an extreme case I might even be prepared to modify BBC BASIC itself to help solve the problem (I did that to make SORTLIB work in iOS!).


Re: Assembler alternatives

Posted: Sat 14 Apr 2018, 22:07
by alex_farlie
Similar considerations would apply to the BB4WFORTH you wrote. Although Jonesforth seems to have been ported to other architectures.

Re: Assembler alternatives

Posted: Sat 14 Apr 2018, 22:27
by guest
alex_farlie wrote:
Sat 14 Apr 2018, 22:07
Similar considerations would apply to the BB4WFORTH you wrote.
The clue is in the name: BB4WForth! It's necessarily only compatible with 32-bit x86 platforms, and whilst that currently includes Linux and MacOS, soon it will be Windows only (and who knows how long that will last). Effectively BB4WForth has no relevance to BBCSDL.


Re: Assembler alternatives

Posted: Mon 24 Jun 2019, 18:53
by Repton
Complely agree with the OP. Has anone tried running BBC Basic 8bit assembler code?

Re: Assembler alternatives

Posted: Tue 25 Jun 2019, 08:27
Hi Repton,

I'm not quite sure what your point is, so forgive me if this reply misses it!

The assembler needs to match the underlying processor, and since no machines on which you'd want to/be able to run either BB4W or BBC_SDL use the old 8 bit (6502?) processor, it isn't going to work (and the integrated assembler wouldn't know how to handle it, anyway, since it/they are assemblers for more modern processors).

Hope that's helpful (and correct!).