Fields
A field corresponds to a certain number of bits of a machine
instruction. The first field of an instruction stores the opcode of the
instruction. The remaining fields
include the operands of the instruction. There can also be 0-bit fields, which just
correspond to punctuation in the
assembly language format of the instruction.
Parameters:
- name
The names of the fields have a form that is a little different
than
symbols in the assembly language. A field name can be either any single
non-whitespace character or a mixture of
two or more letters, numbers, and hyphen (-) characters.
- type
The type is either required, optional, or
ignored.
- A required field is one that must appear as an operand in the
instruction. If the field has
positive length, then the assembly code must include an operand for that
field consisting of a literal
or a symbol whose value will fit in the field. If the field has length 0,
then the name of the field
must be included as an operand in the instruction in assembly language
programs and is used just as
punctuation. Therefore, a field of length 0 must have a name that forms a
token in assembly language.
- If a field is optional, then an operand need not be specified for
that field in assembly
language, in which case the field's default value is used for the operand
instead. If the field has
length 0 and is optional, then it may be omitted. In each
machine instruction, at most one
field with length > 0 can be optional.
- An ignored field is one that is never included as an operand in
assembly language. Instead, the
field's default value is always used for the field. Fields of length 0 may
not have this type.
- numBits
The length or number of bits in this field. It must be a
base-10 integer that is 0 or
greater.
- relativity
The relativity of a field is either absolute, pcRelativePreIncr,
or pcRelativePostIncr.
This relativity allows for two pc-relative addressing modes.
- A field with absolute relativity is one whose operand's value is
placed directly in the field
when assembled.
- If a field has pcRelativePreIncr relativity, then the value of the
operand in the assembly
program for the
field is subtracted from the address of the instruction containing
the field. The assembler puts the difference as the actual value
of the operand in the field in the assembled instruction.
- If a field has pcRelativePostIncr relativity, then the value of the
operand in the assembly
program for the field
is subtracted from the address of the instruction after the one
containing the field. The assembler puts the difference as the actual
value
of the operand in the field in the assembled instruction.
- defaultValue
The default value must be a base-10 integer that fits in
the field. It is used as the
operand for fields of type ignored or for fields of type optional
when operands for those fields
are not included in the assembly program.
- signed
If a field is signed, it can legally hold
any value from -2n-1
to 2n-1 where n is the number of bits in the field. If
the field is unsigned,
the values must be in the range 0 to 2n-1.
- values
If a field has absolute relativity and a positive number of bits, then you
can optionally create a set of
named values for the field. If you create such a set, then the names for these
values become the only legal
values for the field. Furthermore, in this case, you must use one of the names of
those values as the operand in
the field in each assembly language program. If you do not specify a set of
values, then any value that fits in
the field is acceptable.
Examples:

Figure 23. The dialog for editing the fields
of machine instructions.
Consider the fields shown in Figure 23 above. Assume that the "reg" field has
a set of three values
associated with it: A=2, B=3, and C=4. Also, assume that the punctuation
characters '[' and ']'
are individual character tokens (see the
discussion of tokens for
information on setting the token usage of punctuation characters). Now consider two
16-bit machine instructions with
names "foo" and "bar" with opcodes 0 and 1 and with the following
respective formats:
op reg reg un7
op delta[reg]
These instructions can be called in assembly language as shown in these examples:
foo B C
bar -2[A]
and will be assembled into the following bits (with spaces inserted to indicate the
separate fields):
00000 011 100 0000101
00001 11111110 010
Note that the delta value of -2 is converted to binary using 8-bit 2's complement
notation.
If the two punctuation characters '[' and ']' are not individual tokens and
instead form parts of
symbols, then you need to separate them with whitespace from neighboring characters in
instruction calls to avoid ambiguity or
incorrect parsing. For example, you would need to write
foo B C
bar -2 [ A ]
Notes:
- Fields of length 0 are just punctuation and their name must appear as the operand
in assembly language. Such
fields must be of type required or optional. All other properties of
such fields are unused.
- To preserve backward compatibility of this version of CPU Sim with previous
versions that used field lengths
only instead of these new fields, CPU Sim looks for fields when loading a machine
previously saved to a file. If
no such fields are included in the file and instead field lengths are included,
then CPU Sim will add new fields
with names "1" through"16" and "-16" through"-1"
to the machine when it
is loaded. In this way, the old field lengths become actual fields instead.