% This file is part of the Stanford GraphBase (c) Stanford University 1993
@i boilerplate.w %<< legal stuff: PLEASE READ IT BEFORE MAKING ANY CHANGES!
@i gb_types.w
\def\title{MULTIPLY}
\prerequisite{GB\_\,GATES}
@* Introduction. This demonstration program uses graphs
constructed by the |prod| procedure in the {\sc GB\_\,GATES} module to produce
an interactive program called \.{multiply}, which multiplies and divides
small numbers the slow way---by simulating the behavior of
a logical circuit, one gate at a time.
The program assumes that \UNIX/ conventions are being used. Some code in
sections listed under `\UNIX/ dependencies' in the index might need to change
if this program is ported to other operating systems.
\def\<#1>{$\langle${\rm#1}$\rangle$}
To run the program under \UNIX/, say `\.{multiply} $m$ $n$ [|seed|]', where
$m$ and $n$ are the sizes of the numbers to be multiplied, in bits,
and where |seed| is given if and only if you want the multiplier
to be a special-purpose circuit for multiplying a given $m$-bit
number by a randomly chosen $n$-bit constant.
The program will prompt you for two numbers (or for just one, if the
random constant option has been selected), and it will use the gate
network to compute their product. Then it will ask for more input, and so on.
@ Here is the general layout of this program, as seen by the \CEE/ compiler:
@^UNIX dependencies@>
@p
#include "gb_graph.h" /* the standard GraphBase data structures */
#include "gb_gates.h" /* routines for gate graphs */
@h@#
@@;
@@;
main(argc,argv)
int argc; /* the number of command-line arguments */
char *argv[]; /* an array of strings containing those arguments */
{
@;
@;
@;
if (seed<0) /* no seed given */
printf("Here I am, ready to multiply %ld-bit numbers by %ld-bit numbers.\n",
m,n);
else {
g=partial_gates(g,m,0L,seed,buffer);
if (g) {
@;
printf("OK, I'm ready to multiply any %ld-bit number by %s.\n",m,y);
}@+else { /* there was enough memory to make the original |g|, but
not enough to reduce it; this probably can't happen,
but who knows? */
printf("Sorry, I couldn't process the graph (trouble code %ld)!\n",
panic_code);
return -9;
}
}
printf("(I'm simulating a logic circuit with %ld gates, depth %ld.)\n",
g->n,depth(g));
while(1) {
@;
@