REXX Language implementation
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.
rxas commandThe 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 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.
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 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 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.
rxas assemblerrxas 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.
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