Skip to main content

Design LCM single-purpose processor

Short answer

Method: maintain X = multiples of a, Y = multiples of b; if X<Y, X = X+a else Y = Y+b until X=Y. Datapath: registers A(a), B(b), X, Y; adders with muxes to load or add; comparator generates eq/lt flags. Controller: FSM with states S0 (wait), S1 (compare), S2 (X add), S3 (Y add), S4 (output).

Design a processor that calculates the LCM of two numbers. Show the design of data path only and construct the diagram of controller.

The design uses the additive LCM method: keep two running multiples, X (of a) and Y (of b), and repeatedly add to the smaller one until they become equal. That common value is the LCM. (Inputs a and b are positive integers.)

Algorithm

 LCM(a, b):
   X = a; Y = b
   while (X != Y):
       if (X < Y) X = X + a
       else       Y = Y + b
   output X

Example a = 4, b = 6: (X, Y) = (4,6) -> (8,6) -> (8,12) -> (12,12). LCM = 12.

FSMD

StateConditionActionsNext
S0 waitstart = 0done = 0S0
S0start = 1A = a, B = b, X = a, Y = bS1
S1 compareX = YnoneS4
S1X < YnoneS2
S1X > YnoneS3
S2alwaysX = X + AS1
S3alwaysY = Y + BS1
S4 outputalwaysout = X, done = 1S0

Datapath (only)

  a -> [A]        [B] <- b
        |  X+A      |  Y+B
        v           v
  +--> [adder]   [adder] <--+
  |       |          |      |
  |   mux(a,X+A)  mux(b,Y+B)
  |       v          v      |
  +----- [X]        [Y] ----+
          |  \      /  |
          |   [comparator]--> eq, lt  (to controller)
          v
        out = X

Components: registers A, B, X, Y (X and Y are 16 bits, since the LCM of two 8-bit numbers can need up to 16 bits), two adders (or one shared adder with a mux), two 2:1 multiplexers (load the input or the add result), one comparator giving eq (X = Y) and lt (X < Y), and an output buffer. Control inputs to the datapath: loadA/B, X_sel, X_ld, Y_sel, Y_ld, out_en.

Controller (FSM)

Inputs: start, eq, lt. Outputs: X_ld, Y_ld, selects, done. Five states, 3-bit state register.

 start, status flags --> +-------------+   +-----------+
 (from datapath)         | Next-state  |-->| State     |
                         | logic       |   | register  |
                         +------^------+   +-----+-----+
                                |   current state |
                                +-----------------+
                                                  v
                                           +-------------+
                                           | Output logic|--> control
                                           +-------------+    signals
StateControl signals asserted
S0none (waiting)
S1none (comparison only)
S2X_sel = add, X_ld = 1
S3Y_sel = add, Y_ld = 1
S4out_en = 1, done = 1

✓ Answer checked by Claude Opus 5.5 (high effort)

All Embedded System chapter 2 questions →