分类:
2009-06-29 21:45:44
This document contains a summary of the differences between Motorola assembly code and GNU assembly code. It's important to note that there are (were) actually several varieties of Motorola HC11 assemblers—we have done our best to handle the most common varieties in this document. However, the GNU assembler accepts a mostly different format than all of the Motorola assemblers. This is a blessing in disguise: the reward for introducing a new format is that assembly for any platform is written in very much the same format when using the GNU assembler. You can use this document to get a feel for the difference between Motorola-style and GNU-style assembly syntax.
Description | Motorola Convention | GNU Convention | Notes | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Whitespace |
Each line of code in a Motorola assembly file is divided into four tab-separated sections: [LABEL] OPERATION [OPERAND [...]] [COMMENT] LABEL is an optional label for the line. It may optionally be followed by a colon (see "Labels and colons.") OPERATION is either an instruction (mnemonic) or a pseudo-op (directive). OPERAND is an operand to an instruction. There may be any number of operands depending on the line's OPERATION. COMMENT is an optional section. By convention, comments begin with a semicolon ;, but it is ignored as part of the comment. If a line begins with *, the entire line is ignored by the assembler (see "Comments"). |
In GNU assembly code, whitespace serves as a separator, but like C or Java, the type and number of whitespace characters (tab or space) is not syntactically significant; whitespace should be used to improve code readability. |
(none) | ||||||||||||||||||||
Comments |
* Data storage declaration ORG $00 i RMB 1 ; variable i j RMB 1 ; variable j k RMB 1 ; variable k |
/* The data storage declaration section */ .sect .data i: .byte # variable i j: .byte # variable j k: .byte # variable j |
The GNU assembler recognizes two varieties of comments:
| ||||||||||||||||||||
Labels and colons |
|
|
In the Motorola assemblers, colons after labels are optional. In code written for the Motorola assembler, the colon seems to be absent more often than it appears. However, colons are required after label names in GNU assembly code. You may find it useful to use a label on a line by itself to increase code clarity. In particular, you might want to begin a large block of code with a label on a line by itself. An example to illustrate colon usage follows: /* Motorola label without colon */ instr1 ldaa #0xff /* Gnu label with colon */ instr2: ldaa #0xff | ||||||||||||||||||||
Specifying numeric bases |
|
|
When specifying an immediate value in assembly, use the prefixes indicated in the tables. Remember: octal values always start with a zero, so if you mean for a decimal value to be decimal, make sure it doesn't start with a zero. | ||||||||||||||||||||
Capitalization |
|
|
The GNU assembler does not actually care what case you use for anything in your assembly programs. The capitalization discussed in the tables to the left is simply the accepted convention. You may use whatever capitalization you want to. However, there are a few caveats:
|
Motorola Directive | GNU Directive | Notes |
---|---|---|
ORG $8000 |
.sect .data and .sect .text |
Instead of using the ORG directive, divide your assembly program into data and text sections. The data section will store global variables and the text section will store your program's code. Constants can go in either the data or text section; local variables should go on the stack. |
PORTD EQU $08 |
.equ PORTD, 0x08 |
Use the .equ directive instead of EQU. The argument to .equ can be a number or a label name; this is similar to a #define statement in C. Imagine that, for this example, wherever the text PORTD occurred in your code, the replacement 0x08 would be substituted instead. |
END |
.end |
The GNU assembler, like all present-day assemblers, is smart enough to figure out where the end of your program is. You don't need to explicitly give an END command. However, if you insist, you can use the .end directive. All instructions after END and .end are ignored by the assembler. |
BUFFER RMB 5 |
.size BUFFER, 5 or BUFFER: .byte .byte .byte .byte .byte |
Use the .size directive to reserve a chunk of memory for later use. The first argument to .size is the name of the label you want to associate with the beginning of the chunk of memory and the second argument is the number of bytes you want to reserve. You can also use the .byte directive to reserve a byte of memory. The advantage to using .byte is that you can initialize the reserved bytes to some value: simply use the value as the argument to the .byte directive. For example, to initialize the first byte of BUFFER to 0: BUFFER: .byte 0x00. |
BUFFER BSZ 5 |
BUFFER: .byte 0x00 .byte 0x00 .byte 0x00 or BUFFER: .byte 0x00, 0x00, 0x00 |
You must use the .byte directive to initialize a byte of memory to some value while reserving it. |
ABC FCB $11, $22, $33 |
ABC: .byte 0x11, 0x22, 0x33 |
Use the .byte directive to reserve and initialize bytes of memory. |
ABC FDB $11,$22,$33 |
ABC: .word 0x11, 0x22, 0x33 |
Use the .word directive to reserve and initialize words of memory. On the HC11, a word is two bytes (16 bits). |
ALPHA FCC "DEF" |
ALPHA: .string "DEF" |
Use the .string directive to reserve memory and initialize it with a string value. This is slightly different than the Motorola assembler's FCC pseudo-op, however: the GNU assembler terminates strings with a null character (0). Therefore, ALPHA: .string "DEF" actually reserves four bytes of memory: three for the characters D, E, and F, and one for the null character. |
SPACE DCB 5,$20 or SPACE RMB 5 FILL $20,5 (depending on the assembler's syntax) |
SPACE: .byte 0x20 .byte 0x20 .byte 0x20 .byte 0x20 .byte 0x20 |
Instead of using the DCB or FILL directive, use the .byte directive with the GNU assembler. |
The GNU assembler can print the full set of instructions it recognizes:
m6811-elf-as --print-opcodes | less
This list follows below:
aba abx aby adca [#] [* ] [ ] [ ,X] [ ,X] adcb [# ] [* ] [ ] [ ,X] [ ,X] adda [# ] [* ] [ ] [ ,X] [ ,X] addb [# ] [* ] [ ] [ ,X] [ ,X] addd [# ] [* ] [ ] [ ,X] [ ,X] anda [# ] [* ] [ ] [ ,X] [ ,X] andb [# ] [* ] [ ] [ ,X] [ ,X] asl [ ] [ ,X] [ ,X] asla aslb asld asr [ ] [ ,X] [ ,X] asra asrb bcc [