CREXX

REXX Language implementation

View the Project on GitHub adesutherland/CREXX

Assembler Programming Guide

This chapter has general information about writing programs in assembly language using the rxas assembler programs. It discusses the assembler file format, linkage conventions, and other useful programming information, including the cRexx level B feature which allows including assembly language statements in Rexx programs.

The rxas command

The assembler is started by invoking the rxas executable and takes options, which are specified before the name of the source file. For the options, see page \pageref{rxas—the-crexx-assembler}. The input file has a fixed filename extension of .rxas, the output file replaces the extension with rxbin. The input is UTF-81 and the output is rxbm bytecode, which is platform independent.

The format of an assembler source file

The format of the source lines follows the general layout of assembly source, without a fixed format - there are no mandatory start columns. As most .rxas files will be generated by the rxc compiler from Rexx source, let’s have a quick look at what it looks like.

```rexx options levelb import rxfnsb

say “hello, rxas!” say “Today is” date()


<!--splice--crexx hellox-->

This is the generated assembler source:

\lstinputlisting[language=rxas,label=fpow_example]{./hellox.rxas}

Because this assembler source is generated by the compiler, it contains more than strictly necessary for a successful assembly; to be precise, support for the sourceline() function, tracing and numeric settings. We see a `main() .locals=7` in line 8. Lines 9-14 set defaults for numeric handling, while line 15 includes the sourceline from the cRexx program. Line 16 has the `say hello, rxas`; `say` is the assembler statement which assembles into an instruction for the runtime to put out this line.

When hand-written, this program would look more like:

```rxas <!--hellox2.rxas-->
main() .locals=7
  say "hello, rxas!"
  load r1,5
  call r6,date(),r1
  sconcat r6,"Today is",r6
  say r6
  ret

date() .expose=rxfnsb.date

We can see that the first component of the lines are the procedure names or the instruction mnemonics ; this program has no labels. After the instructions, their parameters are placed.

Register names

The cRexx Virtual Machine has a virtually unlimited number of registers. Registers are called r1..r*n. A procedure needs to specify the number of local registers it uses.

Labels

Labels are used, as in other assembly languages, as targets for branches and comparisons in the code: The label is a string that is ended by a colon (:’). Its purpose is to be a symbolic location to branch into when decisions are taken. It is recommended that a label starts in the first column of the line.2 Branches need to have a target within a module; they cannot jump into other procedures, this is reserved for the call operation.

Procedure names

Procedure names are identifiers for routines in the program. Procedure main() carries a special role, as that is the one the VM runtime gives control to when a program is started. Procedures return either nothing (.void) or data of a specified type (like .int or .string). Procedures can be called and will return a value of the specified type.

Linkage conventions

Optimizing actions of the rxas assembler

rxas is an optimising assembler3 which can rearrange instructions or eliminate them entirely. This optimisation can be switched off when in doubt. This will cause loss of performance, but will make debugging of the code more straightforward, because there is a more direct correspondence with the sourcelines and the generated assembly code.

Embedded Rexx Assembler

The assembler command enables the inclusion of arbitrary assembler instructions within a Rexx program. The compiler validates the instruction mnemonic and arguments, ensuring that variables are converted into the appropriate register number.

This example uses the linkarg assembler instruction with two variables and an integer constant.

assembler linkarg e,i,5

  1. except for older mainframe operating system versions, where it is EBDCIC. 

  2. it will not hurt, however, if it does not start in column one. It must be the first word of the line, though. 

  3. optimization is default but can be switched off, for example when debugging.