CSS372

 

SimpComp - Assembly Language Format

 

Fixed Field Format

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 should be separated by spaces.  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.  The Operands field starts at column 24 and the Comments field starts at column 48.  All labels, operands and comments must be completely contained within these field limitations.

Labels

 

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:. 

Labels, as well as all other fields except comments must be written in uppercase.

Mnemonics

 

Legal mnemonics include all of the SC instruction set plus the following predefined directives (pseudo-instructions).

 

DIRECTIVE

OPERANDS

EXPLANATION

ORG

Number

Sets origination address of program counter.

END

None

Terminates program listing.

DB

Number (-128 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 215

Same but for a full 16 bit word

RB

Number

Reserves number of bytes designated in operand. No initialization occurs

RW

Number

Reserves number of words in memory. No initialization occurs.

 

Operand(s) 

 

Reserved names

The following register names are reserved: A, B, C, D, E, X, P, S.  X = IX, P = BP and S = SP registers.

 

Numbers

Numbers may be specified in decimal, octal, hexadecimal, or binary form.  The following formats apply:

1234d or 1234 – decimal

1234o or 01234 – octal

1234h or 0x1234 – hexadecimal

1111b or 001111 – binary

Data Types

Byte: Unsigned value 0..255

Short: Signed value –128..+127

Character: Any ASCII character in single quotes. Escaped characters, e.g., ‘\n’ are interpreted as single bytes.

Integer Signed value –1x215..1x215-1

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., “Hello ” “world!”.

Comments

A comment field must start with a semicolon if a comment is present.  Comments must end at column 78 (leaving room for a newline).

Example Program

example program

Output

Assuming successful assembly, the assembler constructs two files.  These are the assembly listing file and the program load file.  The listing file has a similar format to the source file but contains the addresses and generated code fields appended.  The load file is a text file in hex format that can be loaded by the SimpComp simulator and run.  Examples of these files.

Errors

The assembler reports syntax errors if they occur during the assembly process.

ert.assertTrue(SCFormatUtil.toFourHex(cpu.getRegister()[0]).equals("0001")); // F000 <- 0001