In order to make the parsing of SCA as simple as possible we have adopted the fixed field width format. Each line of SCA code not started with a semicolon is divided into four distinct fields, each with its own width, given in number of characters. Fields start on a specified column and may be separated by either tabs or spaces. In this description we assume that a text processor, such as Notepad, is set so that a tab stop equals 8 characters. A full line is 80 columns [0..79]. The Label field starts at column 0 and runs for 15 characters. There must be at least one space separating fields. The Mnemonic field starts on column 16 (2 tabs from left). The Operands field starts at column 32 (4 tabs) and the Comments field starts at column 48 (6 tabs). All labels, operands and comments must be completely contained within these field limitations.
Labels are optional tags that become associated with a specific address when the source code is assembled. If present, a label consists of up to fourteen characters with a terminating colon (15 total). A label must begin with an alpha character but all subsequent characters can be either alpha or numeric (digits). Examples of valid labels would be: FIRST:, B4:, LOOP01:. Invalid labels might be: 1WAY2GO:, AREALLYLONGLABEL:.
There are three labels that are reserved and treated as directives to the assembler. These are MAIN: (main code), DATA:, and SUBRT: (subroutine code). MAIN is to be used as the first label to pass the name of the main program module to the linker/loader. If the first ORG statement is not 0x1000 then the program module is in error and will not assemble.
DATA and SUBRT labels are used either within the same program file as main or as separate assembly module files. The data label can ORG anywhere in memory beyond 0x1000 as can the SUBRT label. A data label must be followed by a sequence of memory allocation directives (below) and followed by an ENDD directive. A subroutine directive must end with an ENDC directive. Failure to provide these terminating directives results in a abort of the assembly process.
Operands are required for all three reserved labels. The operand is a short symbolic name meeting the conventions of label form. These are the symbolic representations of the start of each section identified. The symbol table will contain the name as a label and the address of the org statement immediately below the reserved label instruction. For example
MAIN: MYPROG
ORG 0x1000
results in the symbol MYPROG (not MAIN) in the symbol table with the address 0x1000.
Labels may be written in lowercase, e.g., loop01:, but labels are case insensitive (converted to uppercase in the assembler) so loop: is the same label as LOOP:.
Legal mnemonics include all of the SC instruction set plus the following predefined directives (pseudo-instructions).
DIRECTIVE |
OPERANDS |
EXPLANATION |
ORG |
Address in HEX format, e.g. 0xFFFF |
Sets origination address of program counter. |
END |
None |
Terminates a file listing. No further statements |
ENDD |
None |
Terminates a data section in a file. There may be more statements |
ENDC |
None |
Terminates a code section (either main or subroutine) but not the file. |
EQU |
Number (requires label) |
Sets a label to a constant value. |
DB |
Number (-127 to 127) or character in single quotes, e.g., ‘H’ or string of text in double quotes, e.g., “Hi there”. \t = tab; \n = newline; \0 = terminator |
Sets the value of a byte of memory to number value or ascii value of character (usually takes a label). If a string is given the assembler reserves the number of bytes in the string, setting values of each byte to the corresponding ascii value. |
DW |
Number –215 to 216-1 |
Same but for a full 16 bit word |
RB |
Number |
Reserves number of bytes designated in operand. |
RW |
Number |
Reserves number of words in memory |
Operand(s)
The following register names are reserved: A, R0, B, R1, C, R2, D, R3, E, R4, IX, R5, BP, R6, SP, R7.
Numbers may be specified in decimal, octal, hexadecimal, or binary form. The following formats apply:
1234d or 1234 – decimal (default format)
1234o or 01234 – octal (leading zero)
1234h or 0x1234 – hexadecimal
1111b or 001111 – binary (leading twin zeros – assembler will strip off excess leading digits)
Byte: Unsigned value 0..255
Short: Signed value –127..+127
Character: Any ascii character in single quotes
Integer Signed value –1x215..1x216-1
Long: –1x231..1x232-1 (disregard
this type)
String: any sequence of ascii characters enclosed in double quotes. Strings must fit within the operand field so it may be necessary to break a string across two or more statements, e.g.
DB “Hello Wo”
DB “rld!”.
A comment field must start with a semicolon if a comment is present. Comments must end at column 78 (leaving room for a newline).
Program Coding
A program will have the following basic format:
80 columns 1 2 3 4 5 6 7 0123456789012345678901234567890123456789012345678901234567890123456789012345678 ------------------------------------------------------------------------------- LABEL MNEMONIC OPERANDS COMMENTS ------------------------------------------------------------------------------- ; ; A sample program ; ; this is a comment line ; MAIN: MYPROGRAM ORG 0x1000 ;start assembly 0x1000 START: LD A, FIRSTOP ;getthe first operand LD B, SECNDOP ;get the second operand ADD A, B ;A <- A + B ST A, ANSWR ;store it LAST: HALT ENDC ;end code section ; ; Data area ; DATA: ORG 0x1100 ; put data in new page FIRSTOP: DW 300 ;first operand SECNDOP: DW 100 ;second operand ANSWR: RW 1 ;reserve a single word ENDD ; END
where an original ORG statement is required as the first line of non-comment code. Note that if this is a main module the address of origin must be 0x1000 for the SimpComp.
Labels are completely programmer determined within the restrictions given above.
The spacing of the fields is critical. In the above diagram the fields are separated by enough space and on fixed starting columns to allow easy readability. Follow this convention. You may use either tabs or a string of spaces but make sure the start of each field is in the specified column.