Beebug


Macro Assemblers

Categories: Review: Software

 
Published in Beebug Volume 5 Number 2

The latest software tools for machine code programmers are macro assemblers. Geoff Bains has been taking a look.

Macro Assemblers

Giving the Beeb a built-in assembler was without doubt a masterful move on the part of Acorn. However, this primitive assembler offers only the bare essentials. More comprehensive assembler packages suitable for serious use have now been produced by several other companies. Here we look at two of these.

The major difference with these new assemblers is that they can handle 'macros' - sections of code that can be defined as a macro and called up and inserted into the machine code generated (the 'object code') whenever needed. It is a similar idea to subroutines except that the macro code itself is actually inserted in place of the call.

In addition, these newer assemblers also have the facility to assemble from source code that is far larger than the Beeb's memory. This is especially useful if you are, say, assembling a ROM. What with the bulky mnemonics and extensive comments, the source code for an 8K ROM may take up around 50K. Clearly, this calls for a new assembler.

Macrom

Macrom is a very powerful assembler package combining a text editor, macro assembler, disassembler, and assembler routine library.

The Macrom editor is a fully fledged text editor in its own right, though it is especially configured for writing assembler code. The editor operates in any display mode and is entered with either the command *ED or *ED [filename] to edit a file already saved to disc or tape.

The assembler text is entered as normal into the editor. A string starting with a space is assumed to be an op code. Strings without are taken as labels. As soon as Return is pressed at the end of a line the editor automatically formats the line into its four fields of label, op code, operand and comment.

Needless to say you can use the cursor keys to go back on existing lines and alter them with the utmost ease. The function keys give you a range of facilities that owe more than a little to Wordwise. The editor can be toggled between overwrite and insert modes and a 'move to' command is also provided. Markers can be inserted in the listing and the blocks deleted, moved or copied.

The equivalent of Wordwise's menu page is provided by 'extended' commands entered in the window that springs up at the screen base when fl is pressed. The extended commands will display the assembler listing (as Wordwise's preview), load and save blocks or the whole listing, change display mode, perform a search and replace operation, and assemble the code. The clever part of the Macrom editor is that the assembler is not stored as ASCII text. It is tokenized so that you can cram much more assembler source code into the Beeb's modest memory. Pure ASCII files (from, say, Wordwise) can be loaded into the editor using *EXEC. In addition, a program supplied on the support disc will convert Basic programs containing assembler into Macrom editor files.

Once your assembler program, Or Macro is written, it should be assembled. Macrom's assembler is extremely fast and provides for a number of options that control the assembly. The object code can be directed to a file on disc or tape, or directly into memory. The assembly listing can be printed or not as required and indeed the actual assembly output can be suppressed for a fast run through to detect errors. The assembler can suppress errors, stop at an error and print the offending line, or direct all the errors to a file for inspection after assembly.

There's not a lot more you could ask of an assembler. Macrom not only performs all these tasks but does so efficiently and quickly. The real proof of the pudding, however, has to be the command set allowed by the assembler.

Most of the normal assembler mnemonics and operators are allowed and several special ones as well. Op codes are only accepted in upper case leaving lower case free for use as labels. The extra op codes for the 65C@2 (as used in the B+, Master, and 65C02 second processor) are also accepted but a warning is printed on assembly in case they are not wanted.

For Beeb directives such as EQUB, the assembler not only allows the Basic form but other commonly used mnemonics like DEFB, DB, and DFB as well. Unfortunately Macrom does not allow the operator DIV so if you're used to using this to extract the high byte from a number, you'll have to get accustomed to the expressions '<' and '>' which are used to specify the high and low bytes of a number.

Macrom can support conditional assembly too. The directives IF, ELSE, and ENDIF are used to alter the flow of assembly at assembly time according to factors under your control.

Other pseudo-ops control the assembly. ORG and RUN define the start and execution addresses of the object code and EMBED sets the relocation address for code to be downloaded at run-time. A very useful directive, QUERY, will halt the assembly and allow a value to be entered by the user. The most important pseudo-ops supported by the package, however, are those that instigate macros.

A section of code that is to be a macro is defined within the pseudo-ops MACRO and ENDM. The label on the assembler line containing MACRO is the title of the macro and is used to call the code from the main assembler listing. Alternatively CHAIN "[filename]" will switch the assembler source from the main listing to the specified file on disc, to access other listings and other macros.

Parameters can be passed to the macro to affect the exact nature of the code inserted at that point. Labels and values following the call to the macro are substituted in order for @1, @2, etc in the macro code. With the facility for conditional assembly, this provides a very powerful combination. The most complex assembler program can be simply broken down into easily-written chunks.

To take advantage of the macro facility of Macrom, Clares also supplies a library of useful macros on disc. These cover a wide range of subjects from changing mode and printing characters to setting up a ROM header.

The Macrom ROM also includes a disassembler, invoked through *PEEK. It will only operate on code in memory but it does have the useful facility of displaying the full names of all OS calls and vectors.

Macrom is a very powerful package that will appeal to any serious assembler programmer. It has been designed carefully to fit in with existing ideas of the BBC Basic assembler but offers facilities far beyond that. The manual is well written and acts as both a clear, concise reference and a helpful tutorial. Full marks for an excellent product.

6502 Macro Assembler

Star's macro assembler is a different kettle of fish to Clares'. It does not offer the same range of features as Macrom but then it costs a lot less too. Star's assembler comes on a 8K ROM which comprises only an assembler. This ROM has no editor or disassembler, but then these may be found in many other packages.

The Star assembler does not require an editor for writing the source code because every user of this ROM already has one. The Star assembler uses files created with the BBC Basic interoreter. That is not to say that the square brackets, OPT, loop structures, and other paraphernalia required by the Beeb's built-in assembler are necessary. Instead, an assembler listing is created as a series of program lines containing assembler statements.

This means that the source code can be created just as you create a normal Basic program. It can be edited, renumbered, and so on as normal and saved and loaded from disc or cassette in the usual way too. If you have a Basic program editor of some kind then this can be used to supplement BBC Basic's editor to good effect.

However you edit your source code, it is assembled with Star's assembler with the command *ASSEMBLE. This prompts you for the filename of the file containing the program or '*' can be entered instead to assemble the program in memory.

Star's assembler does not assemble at quite the soeed of Macrom but that's not to say that it's in any way slow. The object code generated is placed in an 8K output buffer in memory on its way to a file on disc or cassette. The object code is always saved with the same name - 'FILEa'. If this gets to be too big (more than 8K) a second file - 'FILEb' - is created and so on. Up to around 50K of object code can be generated in this way.

Like Macrom, Star's assembler support all the normal 6502 op codes and has several others with special functions. It can also support the 65C02 extra op codes but only after a #new command in the source code. This is in many ways a safer solution to the problem than that employed by Macrom.

All of the Star assembler's pseudo-ops - to set the start and execution address, switch the printer on and off, and so on - are accessed with these # commands. This makes the assembler mwuch easier for the beginner to come to grips with - the program code itself and the controlling commands are clearly separated.

This assembler can also support conditional assembly with #if, #else, and #endif commands. Rather disappointingly, the functions EQUB, EQUS, and so on are not accessed with these names in Star's assembler. Instead, EQUB is called #byte and EQUW is #word. EQUS is called up rather confusingly with just #. However, a nice extension to this theme is the #include command that will place an entire file of codes into memory at that point in the object code - great for inserting large amounts of data prepared beforehand.

To handle very large source code programs, split over several files, the #merge command will make the assembler treat the files as one. Macros are defined and used in Star's assembler in a very similar way to Macrom. The #macro command starts the definition and END finishes it. The macros can then be called up ('expanded') by name whenever required. Parameters can be passed to the macros too, in a very similar manner to parameter passing to procedures in Basic.

Although the Star package is not as comprehensive as Macrom it still offers a remarkably powerful program for the price. The manual is clear and helpful and has many example listings to show the use of this ROM's numerous facilities. Star's assembler is excellent for anyone just starting on the road to serious assemble work or who does not require the extra facilities of Macrom.

Geoff Bains

Other BBC Model B Game Reviews By Geoff Bains


  • Beebed Front Cover
    Beebed
  • Diagram II Front Cover
    Diagram II
  • Floppy Wise Front Cover
    Floppy Wise
  • TD ROM Front Cover
    TD ROM
  • Clef Computer Music System Front Cover
    Clef Computer Music System
  • Magic Mushrooms Front Cover
    Magic Mushrooms
  • Colourspace Front Cover
    Colourspace
  • Boffin Front Cover
    Boffin
  • Graphics Development System Front Cover
    Graphics Development System
  • Bruce Lee Front Cover
    Bruce Lee