EnchantedLearning.com is a user-supported site.
As a bonus, site members have access to a banner-ad-free version of the site, with print-friendly pages.
Click here to learn more.
(Already a member? Click here.)
SPARC Assembly-Language Syntax
Assembly language is much more line-oriented than the structured high-level languages you are probably more used to. An assembly-language program is a sequence of individual lines, unlike a high-level language program, which is best thought of in terms of structured statements.
There are four types of assembly language lines: label definition lines, instruction lines, directive lines and blank lines.
- A label definition line contains just a label definition. A label definition is an identifier followed by a colon ":". As usual, an identifier must start with a letter or an underline and must consist entirely of letters, underlines, and digits. You should generally avoid starting labels with an underline character, even though it's legal, unless you're writing system software, since you're liable to run into conflicts with names built in to the system.
A label in assembly language is just the name of an address; it may be the address of an instruction or the address of a piece of data. A label isn't the name of a variable that can change during program execution. You can think of a label as a constant pointer.
Here's an example of a label definition line:
- An instruction line consists of an optional label definition, followed by an operation name, followed by any desired or necessary operands. If there are two or more operands, they are separated by commas; some operations require no operands.
In most cases, the assembler will translate an instruction line into a single machine-language instruction; each SPARC machine-language instruction is one word long. (Some so-called synthetic instructions are actually abbreviations for sequences of instructions, and so the assembler translates these into more than one instruction.)
Here are some examples of instruction lines:
calc: save %sp, -64, %sp
add %i0, %i1, %o0
mov %o0, %i0
- A directive line consists of an optional label definition, followed by a directive name, followed by any desired or necessary directive arguments. Directives can be easily distinguished from instructions, since a directive name always starts with a period ".".
Some directives cause the assembler to produce output that gets placed in the machine-language code; other directives act like declarations in that they merely tell the assembler something about how to assemble the rest of the code.
Here are some typical directive lines:
tablesize: .word 500
daynames: .asciz "SunMonTueWedThuFriSat"
- A blank line consists just of white space (spaces and tabs) and is ignored by the assembler.
In addition, you can place a comment at the end of any line by writing an exclamation mark "!" followed by the comment. Everything from the "!" up to the end of the line is ignored by the assembler. Notice that, since a blank line is a legal assembly language line, you can have a line consisting entirely of a comment and nothing else.
The assembler also recognizes C-style comments bracketed by /* and */. This can be useful for function prologues and the like.
Copyright 1998-1999 Enchanted Learning Software.
Enchanted Learning Search
Search the Enchanted Learning website for: