Microprogramming for n-machine
mpgen translates "mspec.txt" into bits in "mpgm.txt". Each line
of microword contains "bits" or "control signals" and "next
address". This style is called "one address microprogram".
There are other formats such as "two-address microprogram" and
"multi-format microprogram". One-address microprogram is the
simplest one. Each bit in control signals denotes an event or
control in the data path, such as a select signal of a multiplexer or a
load signal for a register. The number of control signals depends
on the design of data path. In our abstraction, an event in data
path is at register transfer level, source register to destination
register, the data can passed through a combination function, denoted s ->f-> d, where s, d are
register and f is a combination function. The next address bits
are the address for the event "goto label", the flow of control in the
microprogram. It can be unconditional, conditional or multi-way
branch depends on the simulator of control unit. The "width" of
next address is ceiling(log_2 number of microword). The
"width" of a microword is the number of control signals pluses the
width of next address.
There are two sections in "mspec.txt": signal definition and
microprogram. The signal definition declares the name of control
signals. The ordering of the signal denotes its bit position,
from 0...n. This section starts with ".s". The microprogram
section starts with ".m" and ends with ".e". Each microprogram line
contains:
[:label] active-event* flow-control*
[/label] ;
where [optional] * repeat 0 or more times, ";" is the end of a
line.
A comment line starts with "..". This is an excerpt from
n-machine microprogram:
.s
xe
de1
sM
snil
. . .
inc
isnil
isatom
pass2
mR
mW
lmar
jmp
jT
jF
.m
.. start of microprogram
..
:begin xe
isnil jT /exit ;
xe
isatom jT /decode ;
.. e1 = tail e
xe inc
lmar ;
mR sM
de1 ;
. . .
.. <exit>
retval = NIL
:exit snil
pass2 sT drv ret ;
.e
All signal names the appear in the microprogram must be already defined
in the signal definition section. All label beginning of a line
are prefix with ":". All other labels are prefix with "/" and
must appear at the beginning in some line otherwise it is an undefined
label which is an error. The name of active event appears in a
microprogram word, all other signals are idle. The active-event
is translate into bit "1" otherwise "0".
The above example is explained as follows:
.s
xe
de1
sM
snil
. . .
The signal definition section declares "xe" to be bit no. 0, "de1" to
be bit no. 1, "sM" to be bit no. 2, "snil" to be bit no. 3. etc.
:begin
xe isnil jT /exit ;
The line labelled "begin" and has two signals active: "xe" and "isnil"
then the flow "jT /exit" denotes jump-if-true to the line labelled
"exit". "xe" and "isnil" are the control signals to the data
path. "jT" is the internal signal modeled the control unit
control flow itself. The line is ended with ";" to signify the
end of this line. If there is no flow of control then the
next-address bits are filled with "0".
How to generate a
microprogram
After a microprogram is written, the file is named "mspec.txt".
mpgen takes "mspec.txt" and outputs "mpgm.txt" and
"mspec.h". In "mpgm.txt", the first line is the number of
microword, the next line and the rest are started with "address" and
the bits. The following is an excerpt of n-machine bits of
microprogram:
166
0
1000000000000000000000000000000000100000000000010010100101
1
1000000000000000000000000000000000010000000000010000001000
2
1000000000000000000000000000001000000000100000000000000000
3
0000000000000001000001000000000000000010000000000000000000
4
0100000000000000000000000000001000000000100000000000000000
. . .
to run mgen:
c:> mgen > mpgm.txt
mgen takes "mspec.txt" implicitly and outputs mpgm.txt on stdout. It
also outputs "mspec.h" with the following convention: all control
signals are prefix with "s_xx" where xx is the name, all labels
are prefix with "a_yy" where yy is the label. Three symbols are
defined : MCWIDTH, MAWIDTH, MLEN denote the width of all control
signals, the width of next address, and the length of
microprogram. These symbols are used in the simulator. The
following is an excerpt from "mspec.h" of n-machine:
#define s_xe 0
#define s_xe1 1
#define s_xe2 2
. . .
#define a_begin 0
. . .
#define a_exit 165
#define MCWIDTH 50
#define MAWIDTH 8
#define MLEN 166
How to recompile nsim
(n-machine simulator)
Generate microprogram (mpgm.txt, mspec.h). Move mspec.h to the
same directory with nsim. Recompile nsim. Move
mpgm.txt to the same directory with "nsim.exe" (the executable of
nsim). nsim starts by reading "mpgm.txt" and executes the
microprogram.
Example session, assume the microprogram is already written in
"mspec.txt"
c:\nut\mpgm> mgen > mpgm.txt
c:\nut\mpgm> move mpgm.txt
..\test
c:\nut\mpgm> move mspec.h
..\nsim
recompile nsim
run the simulator, assume the program to be executed is "quick1.txt"
c:\nut\test> nut < quick1.txt
nut compiler outputs a.obj
c:\nut\test> nsim < a.obj
(fun.2.2
(do (put.1 (new lit.20 ))(call.408 get.1 lit.20 )(call.466 get.1 lit.)(call.354 get.1 lit.0 lit.19
)(call.466 get.1 lit.20 )))
20 19 18 17 16 15 14 13 12 11 10
9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20
clock 54929
10
c:\nut\test>
The first line of output is the listing of machine code of the main
function which is the source :
(def main () (a)
(do
(set a (new 20))
(inita a 20)
(show a 20)
(quicksort a 0 19)
(show a 20)))
The second and third line are the output from the program
quicksort. The fourth line shows the number of clock used in
execution. The last line is the return value from the main
program, the last executed expression (show a 20).
7 December 2004
P. Chongstitvatana