LXP32 coding style guidelines

Introduction

This document provides a few suggestions on coding style for developing software in the LXP32 assembly language. These guidelines were tested in a medium-sized commercial project.

Registers

One distinctive feature of the LXP32 processor is the abundance of registers, which can be used not only for parameter passing or temporary storage, but even for long term storage. An example of register allocation:

To simplify the use of register variables, global or otherwise, it is recommended to declare them as macros:

#define x r1
#define y r2
#define z r3

Macro definitions for global register variables should be placed in a separate include file with the inc extension.

Identifiers

It is useful to adopt a naming convention to distinguish between various types of identifiers:

A simple example that calls a procedure 1000 times:

#define ITERATIONS 1000

#define i r32

	lcs i, ITERATIONS
Loop:
	lcs r0, Do_action_proc
	call r0
	sub i, i, 1
	lcs r0, Loop
	cjpmne r0, i, 0

Modules

It is recommended to put every non-trivial procedure to a separate module (source code file). Besides general code clarity, doing so has other advantages: