beebasm - an assembler with BBC BASIC-like features

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

beebasm - an assembler with BBC BASIC-like features

Post 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.
Last edited by BigEd on Mon Oct 07, 2013 1:42 pm, edited 1 time in total.
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

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

Post 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.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

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

Post 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.)
jgharston
Posts: 181
Joined: 22 Feb 2004

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

Post 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.
richard.broadhurst
Posts: 10
Joined: 20 Jan 2013

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

Post 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
User avatar
banedon
Posts: 742
Joined: 08 Sep 2013
Location: A missile silo somewhere under southern England

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

Post 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
richard.broadhurst
Posts: 10
Joined: 20 Jan 2013

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

Post 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
}
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

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

Post 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
}
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Post Reply