Computer Systems

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Computer Systems

Overview of the task The (fictional) DBMP CPU includes 8 general-purpose registers in addition to a
nonaddressable program counter, and executes instructions that are exactly 16 bits wide. Encoding
of its opcodes supports 16 distinct instructions. Your main task is to write an assembler for DBMP
programs, as well as define some features that have not be specified in the description below.
Further details follow the description of the DBMP’s instruction set and assembly code.

The instruction set In the following descriptions:

• reg, dreg and sreg are registers with names z0, z1, z2, … z7. The same register may be used as both
the dreg and sreg in an instruction. The register name must use a lower-case ‘z’.

• addr is a decimal value – such as 91 or 108.

• lab is a lower-case alphabetic symbolic label – such as loop or start – that corresponds to an
instruction address.

• val is a decimal value – such as 91 or 108. The table below describes 12 of the possible 16
instructions in the DBMP instruction set.
DBMP assembly language DBMP programs are written as a sequence of instructions using the
instruction mnemonics shown in the table above. The mnemonics are case-sensitive and only upper-
case letters may be used. Instruction mnemonics are separated from any operands by one or more
spaces and zero or more spaces may precede an instruction mnemonic. A pair of operands is
separated by a single comma. The comma may have zero or more whitespace characters before
and/or after it. Each instruction is written fully on a single line. Blank lines may be used between
instructions.

An instruction mnemonic may optionally be preceded by a single symbol label (details below). A
label must be separated from the mnemonic by one or more spaces. Only one label per instruction is
permitted.

Each translated instruction is stored in a single 16-bit memory location. The first instruction in a
program listing is stored at location 0, the second at location 1, and so on.

Labels may be used to symbolically denote instruction addresses, e.g., as destinations of the GO
instructions. Labels consist entirely of one or more lower-case alphabetic letters ‘a’ through ‘z’.
Forward references to labels are allowed. A symbol table is used by the assembler to associate a
label with the address in which the instruction it labels is stored.

When a program starts running, the initial value of all registers is 0 and the program counter
contains the value 0.

Example program The following simple program illustrates the features of the assembly language
described above.

VALLOAD 10,z0

TOMEM z0,243

loop MEMLOAD 243,z7

DEC z7

GOZ end, z7

TOMEM z7,243

GO loop

end STOP

The program above loads decimal 10 into z0 and then stores that value into memory location 243.
The value at 243 is then loaded into z7. The instruction has the label ‘loop’ associated with it, with
address value 2. The value in register z7 is decremented by 1. If the resulting value in z7 is zero then
the program branches to execute the STOP instruction at label ‘end’ (address 7) and stops. If the
value in z7 is not zero then the next instruction stores the value in z7 into location 243 and then the
program branches back to the MEMLOAD instruction labelled by loop. This process repeats until the
program stops

Assessment activities
a) [15 marks] Design a suitable encoding structure for the DBMP instruction set. For each instruction
listed above, state the value of its opcode and how the available 16 bits would be encoded for it.

b) [5 marks] State how many memory locations may be addressed for your chosen encoding of the
MEMLOAD and TOMEM instructions.

c) [5 marks] State how many instruction addresses may be targeted by the GO, GOZ and GONZ
instructions in your encoding.

d) [5 marks] Define a 13th instruction for the DBMP instruction set, giving details of its encoding,
operation and addressing details if appropriate. Your instruction should be both sufficiently distinct
from those already defined to be worth adding and a realistic instruction for a modest CPU. For
instance, another relational jump would not be sufficient and a trigonometric operation would be
unrealistic. Your instruction should be something that genuinely enhances the existing instruction
set by providing a useful operation that is not already readily available via simple combinations of
the other instructions.

e) [70 marks] Write an assembler in Java for the DBMP instruction set described above. This does
not need to recognise your 13th instruction. The assembler must read its input from standard input
(System.in) and write its output to standard output (System.out). The program takes no command-
line arguments to its main method. For valid DBMP assembly code it must output to System.out a
16-character text representation of the binary version of each instruction, one instruction per line;
for instance:

0111000000101101

1101000000000101

etc.

For invalid DBMP assembly code the assembler must output an error message to System.out and it
may immediately exit. Invalid assembly code would include illegal instruction mnemonics,
instructions with incorrect operands, missing target labels for jumps, etc.

You might also like