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.
- Adds or subtracts two 2-bit numbers (
aandb). - 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.
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.
nasm -f elf64 2adder.asm -o 2adder.o
ld 2adder.o -o 2adder
./2adder- 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
