Skip to main content

ATmega169 base 8bit Arithmetic and Logic Unit

ALU (Arithmetic and Logic Unit) is a digital system that performs integer arithmetic and logical operations. In this post we introduce ATmega169 base ALU simulation using Proteus. This is 8bit ALU, and functionally it is similar to other entry level ALUs such as Motorola MC14581, 74LS181, etc. This unit can perform 80 arithmetic and logic operations and all these operations are listed in below of this post.

schematic of ATmega169 base 8bit ALU simulation

Firmware of this ALU is developed using AVR-GCC. While at the development we try to isolate firmware with platform as maximum as possible, because of that, this firmware can be modified to run on top of PIC, 8051 or MSP430 MCUs with minor set of changes.


  • A: Input A
  • B: Input B
  • Z: Output
  • EO: Overflow
  • Ei: A = B
  • FF = 0xFF ( = 255)

Instruction

Expression

Comments
00

Z = A

EO = 0
01

Z = B

EO = 0
02

Z = ¬A

EO = 0
03

Z = ¬B

EO = 0
04

Z = A ∧ B

EO = 0
05

Z = ¬ (A ∧ B)

EO = 0
06

Z = (¬A) ∧ B

EO = 0
07

Z = A ∨ B

EO = 0
08

Z = ¬ (A ∨ B)

EO = 0
09

Z = (¬A) ∨ B

EO = 0
0A

Z = A ⊕ B

EO = 0
0B

Z = ¬(A ⊕ B)

EO = 0
0C

Z = (¬A) ⊕ B

EO = 0
0D

Z = 0

EO = 0
0E

Z = A + B

((A + B) > FF) → (EO = 1)
0F

Z = A - B

(B > A) → (EO = 1)
10

Z = A × B

((A × B) > FF) → (EO = 1)
11

Z = A ÷ B

(B > A) → (EO = 1)
12

Z = max{A,B}

EO = 0
13

Z = min{A,B}

EO = 0
14

Z ≈ √A

EO = 0
15

Z = !A

(A > 5) → (EO = 1)
16

Z = AB

(AB > FF) → (EO = 1)
17

Z = A - 1

(A = 0) → (EO = 1)
18

Z = A + 1

(A = FF) → (EO = 1)
19

Z = (A ∧ B) - 1

((A ∧ B) = 0) → (EO = 1)
1A

Z = (¬ (A ∧ B)) - 1

(¬ (A ∧ B) = 0) → (EO = 1)
1B

Z = (A ∧ B) + 1

((A ∧ B) = FF) → (EO = 1)
1C

Z = (¬ (A ∧ B)) + 1

(¬ (A ∧ B) = FF) → (EO = 1)
1D

Z = ((¬A) ∧ B) + 1

(((¬A) ∧ B) = FF) → (EO = 1)
1E

Z = (A ∧ (¬B)) + 1

((A ∧ (¬B)) = FF) → (EO = 1)
1F

Z = ((¬A) ∧ B) - 1

(((¬A) ∧ B) = 0) → (EO = 1)
20

Z = (A ∧ (¬B)) - 1

((A ∧ (¬B)) = 0) → (EO = 1)
21

Z = (A ∨ B) - 1

((A ∨ B) = 0) → (EO = 1)
22

Z = (¬ (A ∨ B)) - 1

(¬ (A ∨ B) = 0) → (EO = 1)
23

Z = (A ∨ B) + 1

((A ∨ B) = FF) → (EO = 1)
24

Z = (¬ (A ∨ B)) + 1

(¬ (A ∨ B) = FF) → (EO = 1)
25

Z = ((¬A) ∨ B) + 1

(((¬A) ∨ B) = FF) → (EO = 1)
26

Z = (A ∨ (¬B)) + 1

((A ∨ (¬B)) = FF) → (EO = 1)
27

Z = ((¬A) ∨ B) - 1

(((¬A) ∨ B) = 0) → (EO = 1)
28

Z = (A ∨ (¬B)) - 1

((A ∨ (¬B)) = 0) → (EO = 1)
29

Z = B - 1

(B = 0) → (EO = 1)
2A

Z = B + 1

(B = FF) → (EO = 1)
2B

Z = (A ⊕ B) - 1

((A ⊕ B) = 0) → (EO = 1)
2C

Z = (¬ (A ⊕ B)) - 1

(¬ (A ⊕ B) = 0) → (EO = 1)
2D

Z = (A ⊕ B) + 1

((A ⊕ B) = FF) → (EO = 1)
2E

Z = (¬ (A ⊕ B)) + 1

(¬ (A ⊕ B) = FF) → (EO = 1)
2F

Z = ((¬A) ⊕ B) + 1

(((¬A) ⊕ B) = FF) → (EO = 1)
30

Z = (A ⊕ (¬B)) + 1

((A ⊕ (¬B)) = FF) → (EO = 1)
31

Z = ((¬A) ⊕ B) - 1

(((¬A) ⊕ B) = 0) → (EO = 1)
32

Z = (A ⊕ (¬B)) - 1

((A ⊕ (¬B)) = 0) → (EO = 1)
33

Z = (A ∨ B) - A

((A ∨ B) = 0) → (EO = 1)
(A > (A ∨ B)) → (EO = 1)
34

Z = (¬ (A ∨ B)) - A

(¬ (A ∨ B) = 0) → (EO = 1)
(A > ¬ (A ∨ B)) → (EO = 1)
35

Z = (A ∨ B) + A

((A ∨ B) = FF) → (EO = 1)
36

Z = (¬ (A ∨ B)) + A

(¬ (A ∨ B) = FF) → (EO = 1)
37

Z = ((¬A) ∨ B) + A

(((¬A) ∨ B) = FF) → (EO = 1)
38

Z = (A ∨ (¬B)) + A

((A ∨ (¬B)) = FF) → (EO = 1)
39

Z = ((¬A) ∨ B) - A

(((¬A) ∨ B) = 0) → (EO = 1)
(A > ((¬A) ∨ B)) → (EO = 1)
3A

Z = (A ∨ (¬B)) - A

((A ∨ (¬B)) = 0) → (EO = 1)
(A > (A ∨ (¬B))) → (EO = 1)
3B

Z = (A ∧ B) - A

((A ∧ B) = 0) → (EO = 1)
(A > (A ∧ B)) → (EO = 1)
3C

Z = (¬ (A ∧ B)) - A

(¬ (A ∧ B) = 0) → (EO = 1)
(A > ¬ (A ∧ B)) → (EO = 1)
3D

Z = (A ∧ B) + A

((A ∧ B) = FF) → (EO = 1)
3E

Z = (¬ (A ∧ B)) + A

(¬ (A ∧ B) = FF) → (EO = 1)
3F

Z = ((¬A) ∧ B) + A

(((¬A) ∧ B) = FF) → (EO = 1)
40

Z = (A ∧ (¬B)) + A

((A ∧ (¬B)) = FF) → (EO = 1)
41

Z = ((¬A) ∧ B) - A

(((¬A) ∧ B) = 0) → (EO = 1)
(A > ((¬A) ∧ B)) → (EO = 1)
42

Z = (A ∧ (¬B)) - A

((A ∧ (¬B)) = 0) → (EO = 1)
(A > (A ∧ (¬B))) → (EO = 1)
43

Z = (A ⊕ B) - A

((A ⊕ B) = 0) → (EO = 1)
(A > (A ⊕ B)) → (EO = 1)
44

Z = (¬ (A ⊕ B)) - A

(¬ (A ⊕ B) = 0) → (EO = 1)
(A > ¬ (A ⊕ B)) → (EO = 1)
45

Z = (A ⊕ B) + A

((A ⊕ B) = FF) → (EO = 1)
46

Z = (¬ (A ⊕ B)) + A

(¬ (A ⊕ B) = FF) → (EO = 1)
47

Z = ((¬A) ⊕ B) + A

(((¬A) ⊕ B) = FF) → (EO = 1)
48

Z = (A ⊕ (¬B)) + A

((A ⊕ (¬B)) = FF) → (EO = 1)
49

Z = ((¬A) ⊕ B) - A

(((¬A) ⊕ B) = 0) → (EO = 1)
(A > ((¬A) ⊕ B)) → (EO = 1)
4A

Z = (A ⊕ (¬B)) - A

((A ⊕ (¬B)) = 0) → (EO = 1)
(A > (A ⊕ (¬B))) → (EO = 1)
4B

Z = flip{A}

EO = 0
4C

Z = flip{B}

EO = 0
4D

Z = random{0..FF}

EO = 0 ; see note in below
4E

Z = Z | random0 = A

EO = EO ; see note in below
4F

Z = Z | random0 = B

EO = EO ; see note in below

Note 1:

In this system random numbers are generated using linear congruential generator algorithm, therefore:

randomn + 1 = (a randomn + C) mod m

If not initialized random0 = 0.

The Proteus simulation and ATmega169 firmware is available to download at google drive. This is an open source software project and all the content are licensed under the terms of MIT license.

Comments

Popular posts from this blog

Building the TD4 4-Bit CPU

The TD4 is a famous 4-bit CPU featured in the book How to Build a CPU by Kaoru Tonami . The book focuses on constructing a functional processor entirely from basic 74-series TTL logic ICs. While the book is unfortunately only available in Japanese, a friend from Japan sent me a copy along with a TD4 PCB. I believe the PCB is based on the open-source design files available on BG5DIW's GitHub repository . "How to Build CPU" book and the PCB. Recently, I finally found the time to build and experiment with it. The project took a few months, as I had to translate the book myself to grasp the core concepts. The overall design is simple and elegant, offering a set of 12 instructions and a 16-byte ROM (implemented via DIP switches) for programming. The board operates on 5V and can be powered via USB. Most components were sourced from local shops, though I had to order a few 74HC-series ICs online. Later, I tested the circuit by replacing some 74HC components with 74LS series...

CD2003 - yet another simple FM radio receiver

In the last few days, we are looking for some simple FM radio receiver to integrate into one of our ongoing projects. For that, we try several FM radio receiver ICs including TDA7000, CD2003/TA2003/TA8164, CXA1019, and KA22429. Out of all those chips we select CD2003 (or TA2003/TA8164) based receiver for our project because of its simplicity and outstanding performance. Except to CD2003, Sony CXA1019 also perform well but we drop it because of its higher component count. We design our receiver based on Toshiba TA2003 datasheet and later we try TA8164 and CD2003 with the same circuit. Either CD2003 or TA8164 can directly replace TA2003 IC, and as per our observations, TA8164 gives excellent results out of those 3 chips. A prototype version of CD2003 FM radio receiver The PCB design and schematic which we used in our prototype project are available to download at google drive (including pin-outs of crystal filters and inductors ). Except for CD2003 IC, this receiver consist...

Arduino superheterodyne receiver

In this project, we extend the shortwave superheterodyne receiver we developed a few years ago . Like the previous design, this receiver operates on the traditional superheterodyne principle.  In this upgrade, we enhanced the local oscillator with Si5351 clock generator module and Arduino control circuit. Compared to the old design, this new receiver uses an improved version of an intermediate frequency amplifier with 3 I.F transformers. In this new design, we divide this receiver into several blocks, which include, mixer with a detector, a local oscillator, and an I.F amplifier. The I.F amplifier builds into one PCB. The filter stage, mixer, and detector stages place in another PCB. Prototype version of 455kHz I.F amplifier. In this prototype build, the Si5351 clock generator drives using an Arduino Uno board. With the given sketch, the user can tune and switch the shortwave meter bands using a rotary encoder. The supplied sketch support clock generation from 5205kHz (tuner f...