Assembly language offers a hands-on approach to understanding how computers perform basic arithmetic at a low level. Subtraction in 8086 assembly follows the same register-first pattern as addition — but with one extra detail worth getting right: operand order. SUB AX, BX computes AX − BX, not BX − AX. Getting that backwards produces a wrong result with no assembler warning. This post walks through a working implementation in three environments: MASM/TASM, emu8086, and NASM.
8086 Assembly Program to Divide Two 16-bit Numbers
Division in 8086 assembly is the most instruction-constrained of the four arithmetic operations. Unlike addition or subtraction, the DIV instruction does not let you choose which registers hold the dividend and quotient — the hardware fixes those roles permanently. Understanding why the registers are wired this way is the key to writing correct division programs and avoiding the dreaded divide overflow exception. This post walks through a working implementation in three assembler environments: MASM/TASM, emu8086, and NASM.
8086 Assembly Program for Addition of Two 8-bit Numbers
Adding two 8-bit numbers is the entry point into 8086 assembly arithmetic — simpler than 16-bit addition in operand size, but identical in structure. You will see the same segment setup, the same register-first constraint, and the same result-storage pattern. This post covers a working implementation in three environments: MASM/TASM (classic DOS toolchain), emu8086 (the Windows emulator used in most college labs), and NASM (modern open-source assembler). All versions are tested and produce verifiable output.
Continue reading 8086 Assembly Program for Addition of Two 8-bit Numbers8086 Assembly Program to Add Two 16-bit Numbers
Adding two 16-bit numbers is one of the first real programs every assembly language student writes — and for good reason. It touches every foundational concept at once: segment registers, data declarations, arithmetic instructions, result storage, and program termination. This post walks through a working implementation in three assembler environments: MASM/TASM (the classic DOS toolchain), emu8086 (the popular Windows emulator used in college labs), and NASM (the modern open-source assembler). All examples are tested and produce verifiable output.
Continue reading 8086 Assembly Program to Add Two 16-bit NumbersInheritance Example in Java
Inheritance is one of the four pillars of Object-Oriented Programming (OOP) in Java. It allows a child class (subclass) to inherit the fields and methods of a parent class (superclass) using the extends keyword. This promotes code reuse, establishes an “is-a” relationship between classes, and forms the foundation for runtime polymorphism. In this post we walk through a practical example of single-level inheritance where a Box class extends a Rectangle class — reusing area logic while adding volume calculation on top of it.
Polymorphism Example in Java
Polymorphism — from the Greek for “many forms” — is one of the four pillars of Object-Oriented Programming in Java. It lets a single method name behave differently depending on the arguments it receives or the object it is called on. Java supports two types: compile-time polymorphism (method overloading, resolved by the compiler) and runtime polymorphism (method overriding, resolved dynamically at run time). In this post we look at hands-on examples of both, starting with the simpler overloading form and then showing how overriding works through inheritance.
Continue reading Polymorphism Example in JavaImplementation of K-Means Algorithm in C++
The K-Means algorithm is one of the most widely used unsupervised machine learning algorithms. It partitions a dataset into K clusters such that each data point belongs to the cluster whose mean (centroid) it is closest to. Unlike KNN, K-Means does not use labelled data — it discovers natural groupings entirely on its own through iteration.
In this post we walk through a well-commented C++ implementation of K-Means that clusters 10 integer values into 2 groups. We cover the algorithm, explain each line of code, trace through the iterative process, and analyse the output in detail.
What is the K-Means Algorithm?
K-Means works by alternating between two steps until the cluster centres stop changing:
- Assignment step: Assign each data point to the cluster whose mean it is closest to.
- Update step: Recalculate the mean of each cluster based on its current members.
The algorithm converges when the means no longer change between iterations — meaning the clusters have stabilised. In this implementation:
- K = 2 (two clusters)
- Distance metric: absolute difference (1D Manhattan distance)
- Dataset: 10 integers entered by the user
- Initial means: provided by the user