Assembler alternatives

Discussions related to using the integrated assembler
Post Reply
guest
Site Admin
Posts: 103
Joined: Mon 02 Apr 2018, 09:12

Assembler alternatives

Post by guest » Sun 08 Apr 2018, 10:08

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!).

Richard.

alex_farlie
Posts: 1
Joined: Tue 03 Apr 2018, 22:44

Re: Assembler alternatives

Post by alex_farlie » Sat 14 Apr 2018, 22:07

Similar considerations would apply to the BB4WFORTH you wrote. Although Jonesforth seems to have been ported to other architectures.

guest
Site Admin
Posts: 103
Joined: Mon 02 Apr 2018, 09:12

Re: Assembler alternatives

Post by guest » Sat 14 Apr 2018, 22:27

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.

Richard.

Post Reply