Skip to main content

Single-purpose processor for power

Short answer

The algorithm initializes result=1, count=0, and repeatedly multiplies result by base while count<exponent. The FSMD uses wait, init, test, multiply, and output states. Datapath includes registers for base, exponent, count, result, a multiplier, incrementer, comparator, and a mux to load initial 1 or product.

Design a single purpose processor to determine the value of x to the power n (read two integers a and b and calculate a^b, showing all the steps). Start the design from the function computing the desired result, FSMD, datapath and controller.

The processor reads integers a (base) and b (exponent, b >= 0) and computes a^b by repeated multiplication.

Step 1: Function

 Power(a, b):
   result = 1; count = 0
   while (count < b) {
       result = result * a
       count = count + 1
   }
   output result

Step 2: FSMD

StateConditionActions (RTL)Next
S0 (wait)start = 0done = 0S0
S0start = 1load a, b into A, BS1
S1 (init)alwaysR = 1, C = 0S2
S2 (test)C < BnoneS3
S2C >= BnoneS4
S3 (multiply)alwaysR = R * A, C = C + 1S2
S4 (output)alwaysout = R, done = 1S0
 S0 --start=1--> S1 (R=1,C=0) --> S2 (test C<B)
 S2 --C<B-----> S3 (R=R*A, C=C+1) --> S2
 S2 --C>=B----> S4 (out=R, done=1) --> S0

Step 3: Datapath

  a_in -> [A] --------------+
                            v
        +-----+  R*A    +-------+
  R <---| mux |<--------|   *   |<-- R
        |(1/prod)       +-------+
        +-----+
  b_in -> [B] --> [ C < B ] --> lt  (to controller)
                      ^
  C <-- mux(0 / C+1) -+  (incrementer on C)
  R --> out

Components: registers A, B, C, R; multiplier (R x A); incrementer (C + 1); comparator (C < B); mux for R (1 or product) and C (0 or C + 1).

Controller

State register (3 bits) with inputs start and lt (C < B). Outputs: loadA, loadB, R_sel/R_load, C_clr/C_inc, out_en, done. 5-state FSM as in the table.

Trace: a = 2, b = 3: R = 1; C = 0 -> R = 2, C = 1 -> R = 4, C = 2 -> R = 8, C = 3 -> stop, output 8.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Embedded System chapter 2 questions →