HALICERY

free-time coding, hardware dev, articles

Top
Home 8042 Blogs About
Home IntelEssential ALU Investigations

Last modified: Sat May 30 11:42:28 UTC+0200 2026 © A. Tarpai


ALU Investigations (PRELIMINARY)

The heart of the ALU since the beginning of microprocessors is the adder.

This is an elaborative analysis of how the binary adder works, how it can be used for subtraction, how the SUB instruction and full signed arithmetic capabilities can be built on top of a relatively simple adder circuit – with implementation details about Intel processors.

Part I.

The adder. Additions and subtractions. SUB instruction in hardware. Intel x86 ADD/SUB and ADC/SBB instructions.

Part II.

Signed arithmetic and the adder. Overflow bit (OF) analysis and detection in hardware by the CY XOR CY–1 method. Intel x86 CMP instruction and signed comparison

It is one of those I always wondered.. how these really work in microprocessors and how it was done in the early days of computing.

An Intel-style 8-bit adder with flags:

     •---------•---------•---------•---------•---------•---------•---------•-------<---  A[7..0] in
     | •-------|-•-------|-•-------|-•-------|-•-------|-•-------|-•-------|-•-----<---  B[7..0] in
    _|_|_     _|_|_     _|_|_     _|_|_     _|_|_     _|_|_     _|_|_     _|_|_
   | A B |   | A B |   | A B |   | A B |   | A B |   | A B |   | A B |   | A B |
   |    C|_  |    C|_  |    C|_  |    C|_  |    C|_  |    C|_  |    C|_  |    C|_______CARRY in_______
  _|C'   | \_|C'   | \_|C'   | \_|C'   | \_|C'   | \_|C'   | \_|C'   | \_|C'   |                      |
 | |__Y__|  ||__Y__|   |__Y__|   |__Y__|  ||__Y__|   |__Y__|   |__Y__|   |__Y__|                      |
 |    |     |   |         |         |     |   |         |         |         |                         |
 |    |     |   |         |         |     |   |         |         |         |                         |
 |    •-----|---•---------•---------•-----|---•---------•---o-----•---o-----•--------->  Y[7..0] out  |
 |    |     |                             |                 |         |                               |
 •----|----XOR                            |                _|_       _|_                              |
 |    |     |                             |               |   |     |   |                             |
 |    •-XOR-•                             |               |___|     |___|                             |
 |    |  |  |                             |                 |         |                               |
 |    SF |  OF                            AF                ZF        PF                              |
 |      LESS                                                                                          |
 |                                                                                                    |
 |                                                                                                    |
 |                                                                                                    |
 |                  ____                                                                              |
 |__CARRY out______| CF |_____________________________________________________________________________|
                   |____|

ZF and PF is derived by combinational logic.

By adding two XOR gates to this simple circuit it becomes a fully fledged signed arithmetic device: