Showing results for 
Show  only  | Search instead for 
Did you mean: 
Not applicable

Opbasm 1.1 release: 6x faster + m4 macro preprocessor

I have released v1.1 of Opbasm the Open Picoblaze assembler. This is a significant improvement over the previous release. Highlights of Opbasm 1.1 include:

  • Addition of a new regex based parser that is 6x faster than the original pyparsing parser used in 1.0 or 25x faster than kcpsm6.exe. The pyparsing parser is still available in case odd corner cases are found in the new parser.
  • Added support for using the m4 preprocessor on Picoblaze source. A built-in package with over 90 useful macros is provided (see below).
  • An output directory can be specified to avoid cluttering the source directory with build artifacts.
  • The soon-to-be-documented "STAR sX, kk" PB6 instruction is supported

m4 support

The m4 preprocessor adds powerful macro facilities for enhanced Picoblaze assembly. m4 is typically already present on most Linux systems. Various implementations can be installed on Windows. Opbasm will automatically run m4 if a source file has the extension ".psm4" or ".m4" or on any file if the --m4 option is used.

Predefined macros are provided with Opbasm covering the following areas:

  • Push and Pop stack operations
  • Bitfield manipulations
  • Shift and rotate by multiple bits
  • Conditional jump and call
  • Conditional if-then-else
  • Repeated string and table operations that work on Picoblaze-3
  • 16-bit arithmetic, logical, and shift operators
  • Flexible 8-bit multiply and divide routines with user specified registers
  • 8-bit constant multiply and divide generators

The following are some of the highlights of the m4 preprocessor. See the detailed m4 documentation for complete coverage of the built-in macros.

m4 includes the ability to evaluate arbitrary integer expressions:

  load s0, evald(4 * 5 + 1) ; Expands to "load s0, 21'd"

The expression evaluator permits the natural use of negative decimal literals:

  load s0, evalh(-20) ; Expands to "load s0, ec"

You can define aliases for registers without altering the original as with NAMEREG.

  define(alt_name, s0)
  load alt_name, 01 ; Expands to "load s0, 01"
  add s0, 01        ; s0 register is still visible

An easy to use stack is now at your disposal:

  namereg sE, SP ; Protect use of sE as the stack pointer
  stackinit(SP, 0x3F)

  push(s0, s1)
  <modify s0 and s1>
  pop(s0, s1)  ; restore them

You can shift registers by multiple bits in one macro call:

  sl0(s0, 4)  ; Multiply by 2**4

Picoblaze-3 doesn't have the ability to handle strings as efficiently as PB6 but it is still necessary to work with them at times. Suppose that you have a subroutine "write_char" that writes characters in s0 out to a peripheral. You can write entire strings with the following:

  callstring(write_char, s0, `my string') ; Note use of m4 quotes `' to enclose the string

This expands to the following:

  load s0, "M"
  call write_char
  load s0, "y"
  call write_char
  load s0, " "
  call write_char
  load s0, "n"
  call write_char
  load s0, "g"
  call write_char

Similarly you can send arbitrary bytes:

  calltable(write_char, s0,  pbhex(DE, AD, BE, EF))

The related macros outputstring(), storestring(), outputtable(), and storetable() are also available.

Consider that you need to do some 16-bit arithmetic. You can define aliases for
pairs of 8-bit registers and then pass them into the 16-bit arithmetic macros:

  reg16(rx, s4, s3) ; Virtual 16-bit register rx is composed of (s4, s3)
  reg16(ry, s6, s5)

  load16(rx, 1000)
  load16(ry, 3000 + 500) ; You can use arbitrary expressions for constants
  add16(rx, ry)          ; rx = rx + ry
  add16(rx, -100)        ; rx = rx + (-100)

This is much less obtuse than manually calculating 16-bit constants and repeatedly implementing the operations in pieces.

Some users may be unable to use Opbasm due to formal release procedures requiring a "golden" assembler. The m4 macro package can still be used with other Picoblaze assemblers by manually running code through m4:

  m4 picoblaze.m4 [input source] > expanded_macros.gen.psm

0 Kudos
0 Replies