Page 1 of 1

beebasm - an assembler with BBC BASIC-like features

Posted: Mon Oct 07, 2013 12:56 pm
by BigEd
See http://www.retrosoftware.co.uk/wiki/index.php/BeebAsm (open source, cross-platform)

This assembler has a number of features inherited from BBC BASIC's built-in assembler, and also has local labels and macros. By using the BASIC-like features you can use loops and conditionals in your source. Output can be to plain binary or can write into a disk image suitable for a Beeb. The FOR loop syntax is a bit odd.

Example:

Code: Select all

.multiply
    \\ multiplies A*X, puts result in product/product+1
    CPX #0:BEQ zero
    DEX:STX product+1
    LSR A:STA product:LDA #0
    FOR n, 0, 7
        BCC skip:ADC product+1:.skip   \\ would break BBC BASIC!
        ROR A:ROR product
    NEXT
    STA product+1:RTS
.zero
    STX product:STX product+1:RTS
Features:
Quote:
Uses standard 6502 syntax
Supports 65C02 instruction set
Denote hex literals with '&' or '$'
Denote binary literals with '%'
Multiple statement lines, statements separated by colons
Define labels with .label, like BBC BASIC
Assign variables with addr=&70, like BBC BASIC
Add bytes, words and strings with EQUB, EQUW, EQUD and EQUS - as an extension to BBC BASIC, these can take a comma-separated list
FOR...NEXT
IF...ELIF...ELSE...ENDIF
Supports all of the BBC BASIC functions and operators in expressions, e.g. SIN, COS, SQR, DIV, MOD, etc etc
Save object code to a disc image or to a standalone file
INCLUDE "file" to include another source file
Ability to set a guard on a memory address so it will warn you if it is assembled over
Use braces { } to enclose blocks of code so that all labels and variables defined within will be local to that block.
INCBIN command to include a binary file in the object code.
SKIPTO <addr> to move the address pointer to the specified address, generating an error if we are already beyond this address.
MAPCHAR command to allow strings to be assembled using non-ASCII codes (this is maybe more useful than it sounds; there's an example in the documentation).
Warns if there is no SAVE command in the source code.

Re: beebasm - an assembler with BBC BASIC-like features

Posted: Mon Oct 07, 2013 1:03 pm
by BitWise
The save command does need a small change as it always sets the high order bytes set to $00 which means it will load in the second processor if one is active. I think they need to add an IOSAVE command which forces $FF into these.

Re: beebasm - an assembler with BBC BASIC-like features

Posted: Mon Oct 07, 2013 2:31 pm
by BigEd
Good point! RichTW is on the forum here.
(To the uninitiated: the BBC OS allows for many and various architectures to be hooked up as a "second processor" which was initially conceived of as the main processor - the BBC Micro was merely the I/O processor. The I/O processor sits at the top of a nominally 32-bit address space for the purpose of file I/O operations, whereas the second processor memory map starts at the bottom. So the top 16 bits of an address ought to be FFFF if referring specifically to the I/O processor, or 0000 if the aim is to load in the main processor. Conveniently, if there's no second processor fitted, the top bytes of addresses are ignored, and the BBC micro itself acts as both main processor and I/O processor.)

Re: beebasm - an assembler with BBC BASIC-like features

Posted: Mon Oct 07, 2013 10:35 pm
by jgharston
BitWise wrote:
The save command does need a small change as it always sets the high order bytes set to $00 which means it will load in the second processor if one is active. I think they need to add an IOSAVE command which forces $FF into these.
Or just allow ORG to take a 32-bit value, which is what I do:

Code: Select all

ORG &FFFF0900
etc.

Re: beebasm - an assembler with BBC BASIC-like features

Posted: Thu Feb 12, 2015 10:36 pm
by richard.broadhurst
I've used it for a couple of complete BBC games and another couple of incomplete ones, I find it works, just the way I want it to :wink:
I just dropped it into my favourite dev environment and perfect combo, my favourite editor and 6502 code :D

Re: beebasm - an assembler with BBC BASIC-like features

Posted: Fri Feb 13, 2015 9:44 pm
by banedon
Feature-wise, this assembler is much like mine (called 6502CA and under development), although the FOR NEXT and IF ELSE ENDIF are not present in mine.
Glad to see that .labels and the ampersand (&) used by someone apart from me ;) :D

Re: beebasm - an assembler with BBC BASIC-like features

Posted: Wed Nov 11, 2015 8:35 am
by richard.broadhurst
One minor missing feature in the released version is global labels, so if you have "local" code, you can't jump into the middle of it without some hackery:

.routine
{
.loop
...
dex
bne loop
.would_like_to_jump_here ; for no apparent reason
dey
bne loop
rts
}

Re: beebasm - an assembler with BBC BASIC-like features

Posted: Wed Nov 11, 2015 9:02 am
by GARTHWILSON
richard.broadhurst, you can put [code] and [/code] around your code to force monospacing and keep the forum software from removing your intentional extra spaces, so you get this:

Code: Select all

.routine
{
.loop
    ...
    dex
    bne loop
.would_like_to_jump_here ; for no apparent reason
    dey
    bne loop
    rts
}