---
title: "Single-purpose processor for power"
subject: "Embedded System"
chapter: 2
key: "semester_6/embedded_system:spp-power"
source: https://www.bctengineer.com/q/semester_6/embedded_system/spp-power
site: BCT Engineering
---

# Single-purpose processor for power

Embedded System · Chapter 2: Hardware Design Issues

- Asked in: 2074 Bhadra, 8 marks; 2078 Baisakh, 8 marks (asked 2 times)
- Video: [Designing Single Purpose Processor To Calculate GCD (HCF).](https://www.youtube.com/watch?v=Wy344fMRnOo) — AFlick
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/embedded_system/spp-power
- Whole chapter: https://www.bctengineer.com/md/semester_6/embedded_system/chapter-2

## Question

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.

## 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.

## Answer

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

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

#### Step 2: FSMD
| State | Condition | Actions (RTL) | Next |
|---|---|---|---|
| S0 (wait) | start = 0 | done = 0 | S0 |
| S0 | start = 1 | load a, b into A, B | S1 |
| S1 (init) | always | R = 1, C = 0 | S2 |
| S2 (test) | C < B | none | S3 |
| S2 | C >= B | none | S4 |
| S3 (multiply) | always | R = R * A, C = C + 1 | S2 |
| S4 (output) | always | out = R, done = 1 | S0 |

```text
 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
```text
  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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How is a^b computed in the design?
   A. Repeated addition of b
   B. Repeated multiplication of result by a, b times
   C. Shifting a by b
   D. Looking up a table
   Answer: B. result starts at 1 and is multiplied by a for count from 0 to b. (Key point: Method)

2. What are the initial values of R and C?
   A. R = a, C = b
   B. R = 0, C = 0
   C. R = 1, C = 0
   D. R = 1, C = 1
   Answer: C. R = 1 is the multiplicative identity; C counts multiplications from 0. (Key point: Initialisation)

3. Which condition goes to the multiply state S3?
   A. C = 0 only
   B. C >= B
   C. start = 0
   D. C < B
   Answer: D. While C < B, multiply and increment; otherwise go to the output state. (Key point: Loop test)

4. Which components does the datapath need?
   A. Registers A, B, C, R, multiplier, incrementer, comparator, muxes
   B. Only an adder
   C. A divider
   D. Only a counter
   Answer: A. Multiplier does R x A, incrementer does C + 1 and comparator does C < B. (Key point: Datapath components)

5. For a = 2, b = 3 the output is:
   A. 6
   B. 8
   C. 9
   D. 4
   Answer: B. R goes 1 -> 2 -> 4 -> 8 after three multiplications, so 2^3 = 8. (Key point: Trace)

## Related in Embedded System

- [Fibonacci single-purpose processor](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Aspp-fibonacci) — Embedded System, chapter 2, asked 2×
- [Factorial single-purpose processor](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Aspp-factorial) — Embedded System, chapter 2
- [Sum of digits processor](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Aspp-sum-of-digits) — Embedded System, chapter 2
- [Largest of four integers processor](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Aspp-largest-of-four) — Embedded System, chapter 2
- [Design LCM single-purpose processor](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Aspp-lcm-datapath-controller) — Embedded System, chapter 2
- [Dual-purpose processor: median and variance](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Adual-purpose-median-variance) — Embedded System, chapter 2

## Related in other subjects

- [Single-phase AC voltage controller with R load](https://www.bctengineer.com/question.md?key=semester_7%2Fpower_electronics%3Aacvc-r-load-rms) — Power Electronics, chapter 6, asked 6×
- [Single short-circuited stub design steps](https://www.bctengineer.com/question.md?key=semester_7%2Frf_and_microwave_engineering%3Asingle-short-circuited-stub-design) — RF and Microwave Engineering, chapter 2
- [Digital PD controller design for plant 1/s²](https://www.bctengineer.com/question.md?key=semester_6%2Fdigital_control_system%3Apd-design-double-integrator) — Digital Control System, chapter 4, asked 2×
