Encoder Front Page
SRS Home | Front Page | Monthly Issue | Index
Search WWW Search seattlerobotics.org

An AS11 Primer

Copyright: This document is copyright 1994 by Thomas P. Dickens (thomas.p.dickens@boeing.com), written for the direct use of my students at Henry Cogswell College. It may be distributed freely in verbatim form provided that no fee is collected for its distribution (other than reasonable reproduction costs) and that this copyright notice is included. Enjoy...


The purpose of this document is to provide you with information about the Motorola AS11 assembler, directed for use with the Motorola 68HC11E1 micro controller. It is not intended to teach you assembly programming, but to provide a reference for the AS11 assembler. The information is compiled from the "Motorola Freeware PC-Compatible 8-Bit Cross Assemblers User's Manual", Motorola document number M68FCASS/AD1, first edition, March 1990. I believe that Motorola has discontinued this document and does not currently provide a replacement.


  1. Definitions:
  2. Label Field:
  3. Operation Field:
  4. Operand:
  5. Comment:
  6. Expressions:
  7. Constants:
  8. Directives:
  9. Invoking the Assembler:
  10. More Examples:





Example code: This is a working example. Line numbers (num) from this example are used in the following discussion.


* This code will perform a binary count on Port B (0)
PortB 	EQU $1004 	; (1)
	ORG $B600 	; (2) start of the HC11E1 EEPROM
	clr PortB 	; (3) Clear Port B
Main 	inc PortB 	; (4) Add 1 to Port B
	ldx #$4000 	; (5) so humans can see Port B change
Delay: 	dex 		; (6) x = x - 1
	bne Delay
	bra Main ; (8) Creates an infinite loop


The format of a line:

Each line of the code may include up to 4 fields, separated by whitespace.

Some of the fields may be blank. They are in the following order:

  1. A label or an asterisk (*), starting in column 1.
  2. An operation (instruction mnemonic or assembler directive).
  3. An operand.
  4. A comment.


Label Field:

1.1) An asterisk (*) as the first character in a line indicates the rest of the line is a comment. (Line 0)

1.2) A symbol starting in column 1 indicates a LABEL. (Lines 1,4,6) A label can optionally end with a colon, which is NOT considered as part of the label (Line 6). Labels can only be defined once per file, but can be referenced multiple times. Labels are used for 2 reasons. To identify PC locations (Defined in Lines 4,6, used in lines 7,8) and to define global constants (Defined in Line 1, used in Lines 3-4).

1.3) If column 1 of a line contains a whitespace, then the line is not a comment or a label; the label field is empty. (Lines 2, 3, 5, 7, 8)

2) Operation Field:

2.1) Directive: There are special operation codes called directives which control the assembly process and are not directly translated into machine code. (Line 2) See complete list of directives below in section 7.

2.2) Opcode: The HC11 opcodes which are directly translated into machine code (Lines 3-8). Expressions and constants can be used (see sections 5 & 6). Opcodes are not listed here, see your M68HC11 Reference Manual, Appendix A.

3) Operand: The operand field is dependent on the opcode used and the addressing mode used. The following operand formats are used:

no operand Accumulator and Inherent. (Line 6)
<expression> Direct, Extended, and Relative.(Lines 3, 4, 7, and 8)
#<expression> Immediate. (Line 5)
<expression>,X Index with X register.
<expression>,Y Index with Y register.
<expression> <expression> Bit Set or Clear.
<expression> <expression> <expression> Bit Test and Branch.

NOTE: The last 2 formats DO NOT use commas or the # sign. If used, AS11 may NOT get the correct addressing mode and will NOT issue an error. Watch out for this!!!

4) Comment: The last field on a line can be an optional comment field and is used for human purposes only to aid in documenting the code (I'm sure my students will comment almost every line of code:^) The comment field is separated from the operand field (or from the operation field if no operand is required) by at least 1 whitespace. As common convention is to use a semicolon (;) to visually define the start of the comment field. (Lines 2-6, 8) These can be aligned for better readability.


5) Expressions: An expression is a combination of symbols, constants, algebraic operators, and parentheses, used to specify a value which is to be used as an operand. Operators are like the C language:

+ add - subtract * multiply / divide
% remainder after division & bitwise AND | bitwise OR ^ bitwise XOR

Expressions are evaluated left to right and there is no provision for parenthesized expressions. (?) Arithmetic is carried out in signed two's complement integer precision (16 bits on the IBM-PC).

6) Constants: Constants can be defined in the following number systems:

-none- decimal
$ Hex
% Binary
@ Octal

For example, all of the following generate identical code.

ldaa #68 	; Load the A register with an ASCII 'D'.
ldaa #$44 	; Load the A register with an ASCII 'D'.
ldaa #%01000100 ; Load the A register with an ASCII 'D'.
ldaa #@104 	; Load the A register with an ASCII 'D'.
ldaa #'D 	; Load the A register with an ASCII 'D'.


7) Directives: The following directives are used by the AS11 assembler:

7.1) BSZ <expression> ; Block Storage of <expr> Zeros at the current PC.

7.2) <label> EQU <expression> ; Assign a value (other than a PC value) to the label symbol.

7.3) FCB <expr>(,<expr>...) ; Form a table of Constant Bytes.

7.4) FCC <delimiter><string><delimiter>; Form a table of a Constant ASCII Character string.

7.5) FDB <expr>(,<expr>...) ; Form a table of constant Double Bytes.

7.6) FILL <expr1>,<expr2> ; Fill memory with <expr1> from the current PC to PC + <expr2>.

7.7) OPT <option>(,<option>...) ; AS11 output Options:

Option Name Option Description
c Cycle counting in the listing.
cre Print a cross reference table at the end of the listing.
l (Lower case L) Print a listing from this point on.
noc (Default) Disable cycle counting from this point on.
nol (Default) Disable listing from this point on.
s Print a symbol table at the end of the listing.

7.8) ORG <expression> ; Set or change the current PC. If no ORG directive is given, the PC starts at zero.

7.9) PAGE ; Causes a page break in the listing.

7.10) RMB <expression> ; Reserve <expr> Memory Bytes from the current PC. The memory is reserved but is not initialized.

7.11) ZMB <expression> ; Zero <expr> Memory Bytes.

8) Invoking the Assembler:

AS11 file1 (file2 file3...) (- option1 option2...)

Normally assembler files will have an .asm file extension. AS11 does not look for this, it must be expressly provided. For each file, a corresponding file with an .S19 extension will be created.

The options are listed in section 7.7 above. Use a space before the minus sign to separate the options from the last filename. Options used in the code will override any provided options from the command line.

9) More Examples: The following code is taken from various working codes I've recently written. The intent is to provide you some real code. Hopefully any syntax questions you have can be found here. Another good source of syntax examples can be found in the M68HC11 Reference Manual, Appendix B Bootloader Listings, which lists the programs which reside in the boot ROM.


	OPT l,c,cre,s ; turn on a bunch-o-options.
* File: example.asm
* Purpose: To demonstrate various assembler syntaxes.
* Author: Tom Dickens
* Date: 10/5/1994
* Lots and lots of documentation to describe your code, memory layout,
* and anything else you currently know and will want to know later.
* Be very verbose. Believe me, you'll thank yourself in 6 months.
* The example code includes routines to initialize and drive the HC11
* UART for MIDI (musical Instrument Digital Interface) output, and also
* to setup a table for a 16 character LCD. The entire LCD code is too
* long to include in its entirity here.
	ORG $B600 ; Start of the HC11E1 EEPROM


* Define some numeric constants.
NOTE_ON 	EQU $90 ; constant value for a MIDI note on event.
NOTE_OFF 	EQU $80 ; constant value for a MIDI note off event.
LCD_in_RAM 	EQU $20 ; RAM address for dynamic LCD data.
Temp_space 	EQU $00 ; address of a scratch byte.


	ldx 	#$1000 		; initialize X for port references.
	lda 	#$20
	staa 	$2b,X 		; set UART baud rate to 31.25 K Hz for MIDI
	staa 	$2c,X 		; set 8-bit, 1 stop bit, & wakeup idle.
	ldaa 	#%00001000
	staa 	$2d,X 		; enable Rx and Tx, no interrupts.
	bclr 	$28,X $20 	; turn the DWOM off.
	ldaa 	$2f,X 		; read Rx just in case, clear out any garbage.


* Copy the LCD table from ROM to RAM so we can change the fields.
	ldx 	#LCD_Display_1 	; Table From location
	ldy 	#LCD_in_RAM 	; Table To location.
	ldaa 	$00,X
	staa 	$00,Y
	cpx 	#DIS_END+1 	; copy table, including null byte at the end.
	bne 	Copy_More


	ldx #$1000 ; initialize X for port references.
* More code here...


* The note value is passed in the A register
NoteOn: psha 			; remember A
	ldaa 	#NOTE_ON
	bsr 	Midi_Out 	; Send the Byte out
	pula 			; now use A
	bsr 	Midi_Out 	; Send the Byte out
	ldaa 	#127 		; Full MIDI velocity
	bsr 	Midi_Out 	; Send the Byte out


NoteOff: psha 			; remember A
	ldaa 	#NOTE_OFF
	bsr 	Midi_Out 	; Send the Byte out
	pula 			; now use A
	bsr Midi_Out 		; Send the Byte out
	ldaa #0 		; No velocity
	bsr Midi_Out 		; Send the Byte out


* The byte to send is in register A.
	brclr $2e,X $80 * 	; The '*' loops back to this line.
	staa 	$2f,X 		; Send the byte out of the UART


	fcc " Time 00:00:00" ; 
	fcb $00 ; Null terminate the string
	fcb ' ,'T,'i,'m,'e,' ,' ,' ,'0,'0,':,'0,'0,':,'0,'0,0