Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 1.12 KB

File metadata and controls

35 lines (25 loc) · 1.12 KB

2-bit Full Adder / Subtractor (Chained)

screenshot

This project demonstrates a 2-bit binary adder/subtractor built from first principles—chaining two full adders. It includes implementations in Assembly (x86-64) and JavaScript.

What it does

  • Adds or subtracts two 2-bit numbers (a and b).
  • Uses a control flag sub (1 for subtraction, 0 for addition).
  • Outputs the 2-bit result and the final carry/borrow.
  • Mimics gate‑level logic: XOR for sum, AND/OR for carry, and inversion for subtraction.

Files

  • 2adder.asm – NASM assembly implementation (prints result and carry to stdout).
  • 2adderSubtraction.js – The addition and subtraction version.
  • 2adder.js – The older addition version.
  • index.html – To run the script (maybe pretty later).
  • .gitignore – To ignore other files.

How to run

Assembly

nasm -f elf64 2adder.asm -o 2adder.o
ld 2adder.o -o 2adder
./2adder

JavaScript

  • Download one of the 2 Js files and the index.html
  • Put them in the same folder and open the index.html
  • Open the browser console to see the results