Simulation (Stage 3.2) -- Standard Coding Practices

It is useful to establish to establish some standard coding practices to avoid simple errors. That means we can avoid wasting time debugging these simple errors and concentrate on the more "creative" part of our code.

We have already adopted a number of these practices implicitly

Other standard practices that are useful to adopt are

Since I find all these practices cut down on the number of errors that I make, I attempt to follow them. When I don't succeed, my error rate goes up considerably.


Explicit memory size description for instructions

When we allocated space for constants we used the assembler directive DC.W to allocate a 16-bit memory location and place into it (initialize) the value specified in the directive. There are a number of other DC directives available

Except for the DC variant, all the other directives specify the memory word length within the instruction. HVZ used the DC.W syntax to indicate that they wanted a 16-bit space allocated and then initialized for the variables.

Each of the 68K instructions has a similar format to the DC directive. For example, the MOVE instruction can be used as follows

My coding practice is always to explicitly specify the LENGTH of the data being used in the instruction. Thus the HVZ code

	MOVE A, D0
	ADD B, D0
	MOVE D0, C

would become

	MOVE.W A, D0
	ADD.W B, D0
	MOVE.W D0, C

By getting into the habit of thinking about the 16-bit data size associated with the MOVE.W or ADD.W instructions (rather than letting the assembler do the job by translating the MOVE and ADD instructions) I experience less problems when the extension becomes important. For example, when accessing the 32-bit COFFEEPOT device registers during Laboratory 2 it is necessary to use the .L extension or else the device will not operate

Return to the start of this page.


Specifying label definitions using the colon (:)

Consider the following code segment

	section const
AVARIABLE 	DC.W 0x400	; Label definition
	section code
	MOVE.W AVARIABLE, D0	; Label use

The meaning of AVARIABLE in the first line is associated with the definition of a label. In the second line we are using rather than defining AVARIABLE. I have adopted a coding convention that brings out these differences. This coding convention makes use of a colon (:) during label definitions.

	section const
AVARIABLE:	DC.W 0x400	; Label definition
	section code
	MOVE.W AVARIABLE, D0	; Label use

Some assemblers require the presence of the colon, others insist you don't use one. The SDS assembler does not care what approach you use in your source code.



Last modified: July 22, 1996 12:07 PM by M. Smith.
Copyright -- M. R. Smith